【发布时间】:2020-11-28 23:57:48
【问题描述】:
我的工作环境是:
- Windows 7 专业版
- Visual Studio 2019、ASP.NET MVC、实体框架
- SQL Server Express
- IIS 7.5 版(本地安装)
当我在 Visual Studio 中调试时,在此路径 ~/Content/Documentacion/log/ 内创建目录/文件没有问题(使用 VS 附带的 IIS Express)。
但是当我发布解决方案并使用 IIS 7.5 运行它时,没有创建目录/文件,我无法理解问题。
这是代码:
public void CreaLogATiempos(DateTime fin, bool sobrescribir = false)
{
try
{
text = "xxxxx= ";
string docPath = "~/Content/Documentacion/log/" ;
var folder = System.Web.HttpContext.Current.Server.MapPath(docPath );
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
FileInfo MyFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(docPath + this.archivo));
if (!MyFile.Exists)
{
StreamWriter crear = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(docPath + this.archivo));
crear.WriteLine(text);
crear.Close();
}
else
{
StreamWriter crear = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(docPath + this.archivo), true);
crear.WriteLine(text);
crear.Close();
}
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
}
也许有人可以看到错误或对问题有所了解?
【问题讨论】:
-
将异常记录到文件中,它可能会有所帮助。但我认为,IIS 进程登录权限存在问题。
-
对我来说似乎是权限问题;当您从 IIS 运行它时,应用程序池用户是否具有创建目录权限?是的。 Backs 所说的 - 一些日志记录会有所帮助。
标签: c# asp.net entity-framework iis-7.5