简体   繁体   English

如何在Application_Start期间获取Web目录?

[英]How do I get the Web Directory during Application_Start?

I am trying to read a file during Application_Start from my web application. 我试图从我的Web应用程序中的Application_Start期间读取文件。

However at the Application_Start I am unable to get the file published to the Web Directory. 但是在Application_Start中,我无法将文件发布到Web目录。

protected void Application_Start(object sender, EventArgs e)
{
    using (StreamReader reader = File.OpenText("settings.json"))
    {

    }
}

The file was added to the web project, and set to Copy to Output Folder. 该文件已添加到Web项目中,并设置为“复制到输出文件夹”。

http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath(v=vs.110).aspx

Using the MapPath method returns the actual file-system path to the root of your site. 使用MapPath方法返回站点根目录的实际文件系统路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM