[英]AppDomain.CurrentDomain.BaseDirectory path issue when running MVC project
This code creates a log file in App_Data folder. 此代码在App_Data文件夹中创建一个日志文件。 If file doesn't exist it's created. 如果文件不存在,则创建它。 It works when the MVC page is published on my IIS. 当MVC页面发布在我的IIS上时,它可以工作。
var filename = AppDomain.CurrentDomain.BaseDirectory +
"App_Data//" +
label +
DateTime.Now.ToString() +
".txt";
var sw = new System.IO.StreamWriter(filename, true);
However when i run the project local, i get : 但是,当我在本地运行项目时,我得到:
NotSupportedException. NotSupportedException异常。 the StreamWriter says that my path is not supported. StreamWriter说我的路径不受支持。 This is the path im getting: 这是即时通讯的路径:
"C:\\Projects\\x- chefsportalen 2.0\\Chefsportalen\\App_Data//Paragå manuell2015-05-18 11:00:18.txt" “ C:\\ Projects \\ x-chefsportalen 2.0 \\ Chefsportalen \\ App_Data //Paragåmanuell2015-05-18 11:00:18.txt”
The App_Data folder exist and the path is correct, why am i getting this error? App_Data文件夹存在且路径正确,为什么会出现此错误?
Filenames are not allowed to contain the ":" character. 文件名不允许包含“:”字符。
Use an explicit format string to specify a format that doesn't contain ":", eg 使用显式格式字符串来指定不包含“:”的格式,例如
DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture)
I'm not sure why it's working when you publish to IIS - maybe because IIS is using a culture that doesn't have ":" as time separator. 我不确定为什么当您发布到IIS时它会起作用-可能是因为IIS使用的文化不是以“:”作为时间分隔符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.