Asp.net web api 尝试写入文件时拒绝访问

Asp.net web api 尝试写入文件时拒绝访问,asp.net-web-api,Asp.net Web Api,嗨,我正试图写一个文件,但当我运行程序时,它说访问被拒绝,我已经尝试过检查安全属性并以管理员身份打开VS,但不起作用。这是构建文件的功能 public void fazfich() { string createText = "\"" + this.Companhia + "\",\"" + this.NrFuncionario + "\",\"" + this.Nome1 + "\",\"" + this.Nome2 + "\",\"" + this.DtNascimento + "\

嗨,我正试图写一个文件,但当我运行程序时,它说访问被拒绝,我已经尝试过检查安全属性并以管理员身份打开VS,但不起作用。这是构建文件的功能

public void fazfich() {
    string createText = "\"" + this.Companhia + "\",\"" + this.NrFuncionario + "\",\"" + this.Nome1 + "\",\"" + this.Nome2 + "\",\"" + this.DtNascimento + "\",\"" + this.Sexo +
        "\",\"" + this.PIN + "\",\"" + this.EMAIL + "\",\"" + this.TpColaborador + "\",\"" + this.CodLingua + "\",\"" + this.CodLingualSO + "\",\"" + this.CodCentroCst +
        "\",\"" + this.CodEscala + "\",\"" + this.CodSector + "\",\"" + this.CodCentroTrb + "\",\"" + this.CodDirecao + "\",\"" + this.CodCategoria + "\",\"" + this.CodCompnhiaExt +
        "\",\"" + this.DsCompanhiaExt + "\",\"" + this.Telefone + "\",\"" + this.InfAutomaticas + "\",\"" + this.HorasExtra + "\",\"" + this.TpControlo +
        "\",\"" + this.CodGrpControlo + "\",\"" + this.NrFuncionarioAlt + "\",\"" + this.TpHorario + "\",\"" + this.TolAtrasoDia + "\",\"" + this.TolAtrasoPrd +
        "\",\"" + this.TolSaidaDia + "\",\"" + this.TolSaidaPrd + "\",\"" + this.SaldoDia + "\",\"" + this.SaldoPrd + "\",\"" + this.TemSaldo + "\",\"" + this.Sistema +
        "\",\"" + this.Saldo + "\",\"" + this.TemCredito + "\",\"" + this.PrecoRefeicao + "\",\"" + this.Subsidio + "\",\"" + this.NrRefeircoes + "\",\"" + this.TpPaga +
        "\",\"" + this.CodPaga + "\",\"" + this.Info + "\",\"" + this.Obs + "\",\"" + this.DtAdmissao + "\",\"" + this.DtDemissao + "\",\"" + this.SisLogico + "\",\"" +
        this.Cartao + "\",\"" + this.DtValidadeIni + "\",\"" + this.DtValidadeFim + "\",\"" + this.Versao + "\",\"" + this.NomeCartao + "\",\"" + this.CodGrpPermissao +
        "\",\"" + this.CodPerfil + "\",\"" + this.PINCARTAO + "\",\"" + this.Status + "\",\"" + this.Info1 + "\",\"" + this.Info2 + "\",\"" + this.Info3 + "\",\"" +
        this.Info4 + "\",\"" + this.Info5 + "\",\"" + this.Info6 + "\",\"" + this.Info7 + "\",\"" + this.Info8 + "\",\"" + this.Info9 + "\",\"" + this.Info10 + "\",\"" +
        this.Msg1 + "\",\"" + this.Msg2 + "\",\"" + this.Provisorio + "\",\"" + this.IDAplicaçã o + "\",\"" + this.AgrpSalarios + "\",\"" + this.Visitante + "\",\"" +
        this.Empresa + "\"\r\n";
    File.WriteAllText(@"C:\Users\ec2ac9097\Documents\estagio\WebApplicationAPI", createText);
}

该程序是一个Web API

该API将在某个特定用户下运行,您可以在IIS设置下进行检查。该特定用户无权在用户文件夹中创建某些内容,例如您试图写入文件的位置

您可以通过尝试在IIS具有完全访问权限的其他地方(如inetpub或您的临时文件夹)写入来验证这一点


绝对不要用IIS Express测试,从一开始就在IIS中设置它。最后,如果要在磁盘上创建文件,您必须设置具有特定权限的特定用户。

格式化修复+删除不相关的标记