【发布时间】:2020-05-14 05:46:05
【问题描述】:
当我在调试模式下运行它时,我可以成功地将日志文件写入服务器路径,但是如果我将其发布到本地 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");
});
调试模式和发布模式的访问权限有区别吗?任何建议/cmets TIA。
【问题讨论】:
-
当你调试它时,它会在哪一行中断?
-
可能是权限问题。您可以尝试将
IIS_USER的读/写权限添加到//serverPath/Test/Log/文件夹。调试模式使用的是内置用户,但 IIS 使用的是 IIS_USER。
标签: c# asp.net-mvc iis