简体   繁体   中英

IIS cannot write file if called from remote, only from the server

I am running a web api on a IIS on Windows Server 2012 R2.

The application has a controller, that on a get request will write to a file on a network share.

If I access the site from a browser on the server it works fine, however if I access the site from my own computer, I get an exception saying that I do not have permission to write to the file.

Users are authenticated against the networks AD, and I am using the same user on both my computer and on the server.

It seems that IIS is handling the request as an other user if I call it from the server, but I have not been able to figure out how I can change this so I can write the file from another host as well.

The code that is giving the exception is using a StreamWriter

using (var writer = new StreamWriter(_filePathName))
{
    writer.WriteLine(GetSetting("PROTECTED_KMDHeader"));
    writer.Close();
}

You need to enable impersonation. See this link https://technet.microsoft.com/en-au/library/cc730708(v=ws.10).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM