[英]File.GetAttributes(unc) generating “Network path not found” error
[英]Error Generating log file to server network path
当我在调试模式下运行它时,我可以成功地将日志文件写入服务器路径,但是如果我将其发布到本地 iis,我不知道为什么在 web 控制台上会出现 500 内部服务器错误。
这是我的后端代码:
public static void VerifyDir(string path)
{
try
{
DirectoryInfo dir = new DirectoryInfo(path);
if (!dir.Exists)
{
dir.Create();
}
}
catch { }
}
public IActionResult storeLogs(string execTime)
{
string query = "Test Query statement"
string path = "//serverPath/Test/Log/";
VerifyDir(path);
string fileName = "Track" + "_Logs.txt";
System.IO.StreamWriter file = new System.IO.StreamWriter(path + fileName, true);
file.WriteLine(DateTime.Now.ToString() + ": \n" + query + "\n" + execTime + "\n") ;
file.Close();
return Ok("ok");
}
这是来自 UI 的 ajax 调用:
$.post("/Home/storeLogs", { execTime: 'test123'})
.done(function () {
console.log("success writing the log");
});
如果调试模式或已发布,访问是否有区别? 任何建议/意见 TIA。
我认为这只是因为 IIS 应用程序池标识没有访问//serverPath 的权限。 当您在 Visual Studio 中调试它时,应用程序在 IIS express 中运行,其身份是您当前的系统登录用户。 它可能是域用户。
但是,当您将其发布到本地 IIS 时。 您的应用程序池将尝试通过应用程序池身份访问 //serverPath。 默认情况下,应用程序池无权访问您的服务器路径,并且连接被隔离。
因此,请尝试将应用程序池身份替换为有权访问您的//serverpath 的域帐户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.