简体   繁体   English

运行MVC项目时AppDomain.CurrentDomain.BaseDirectory路径问题

[英]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.

相关问题 AppDomain.CurrentDomain.BaseDirectory运行测试后会发生变化吗? - AppDomain.CurrentDomain.BaseDirectory changes after running test? C#Uri AppDomain.CurrentDomain.BaseDirectory相对路径 - C# Uri AppDomain.CurrentDomain.BaseDirectory relative path AppDomain.CurrentDomain.BaseDirectory 更改为错误的目录 - AppDomain.CurrentDomain.BaseDirectory changes to wrong directory 如何模拟AppDomain.CurrentDomain.BaseDirectory - How to mock AppDomain.CurrentDomain.BaseDirectory 如何通过在 c# 中使用 AppDomain.CurrentDomain.BaseDirectory 在文件夹路径中上一步 - How to go one step above in a folder path by using AppDomain.CurrentDomain.BaseDirectory in c# 在本地调试Azure函数为AppDomain.CurrentDomain.BaseDirectory提供了一条有趣的路径 - Debugging Azure function locally gives a funny path to AppDomain.CurrentDomain.BaseDirectory 编写 windows 窗体应用程序时 Application.StartupPath 和 AppDomain.CurrentDomain.BaseDirectory 之间的首选项 - Preference between Application.StartupPath and AppDomain.CurrentDomain.BaseDirectory when writing a windows forms application AppDomain.CurrentDomain.BaseDirectory会根据应用程序的目标平台进行更改 - AppDomain.CurrentDomain.BaseDirectory changes according to the app's target platform 为什么 AppDomain.CurrentDomain.BaseDirectory 在控制台应用程序中定位 bin catelog? - Why is AppDomain.CurrentDomain.BaseDirectory targeting bin catelog in console application? 我应该使用 AppDomain.CurrentDomain.BaseDirectory 还是 System.Environment.CurrentDirectory? - Should I use AppDomain.CurrentDomain.BaseDirectory or System.Environment.CurrentDirectory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM