我有一个 MVC3 应用程序应用程序。 我想记录各种内容, 比如当提交表格时, 为了避免必须写到数据库, 我想在 xml 文件中记录细节 。
问题是,我应该使用什么文件夹,我所看到的一些例子暗示了 App_Data 文件夹。 对于最不重要的问题,什么是标准或建议什么?
所以我用这个:
// Create a new XmlSerializer instance with the type of the test class
var serializerObj = new XmlSerializer(typeof(CourseApplicationVM));
// Create a new file stream to write the serialized object to a file
var filename = string.Format("{0}-{1}-{2}{3}", "CourseApp",
viewModel.Course.Code + viewModel.Applicant.Name, DateTime.Now.Ticks, ".xml");
var filepath = Path.Combine(Server.MapPath("~/App_Data/Log"), filename);
TextWriter writeFileStream = new StreamWriter(filepath);
serializerObj.Serialize(writeFileStream, viewModel);
// Cleanup
writeFileStream.Close();
它在当地工作良好, 但当发布到服务器时不会发生。 在查看文件夹结构时, 它并不出乎意料, 因为它在发布时甚至没有 App_ Data 文件夹。 导致错误 :
Could not find a part of the path C:inetpubwwwrootMyApplicationApp_DataLogCourseApp-0385JoeBloggs-634734549879496695.xml .
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path C:inetpubwwwrootMyApplicationApp_DataLogCourseApp-0385JoeBloggs-634734549879496695.xml .
为什么没有那个文件夹呢?保存这些事物的通常地点是什么?
Thanks, David