简体   繁体   中英

Server.MapPath inside Application_End handler in Global.asax

I want to save a file when my application ends.

For that, I need to get the root folder of the application.

The only way I know to do that is using Server.MapPath("~") , but this does not work, even through HttpContext.Current.Server because there is not current context, as far as I understand.

Is there a smart & simple way to get that folder path? Will I have permission problems, trying to create a file in the root folder?

Any alternative ideas how to accomplish this?

您应该使用HttpRuntime.AppDomainAppPath ,它始终有效。

  1. Request.MapPath("")
  2. Request.PhysicalApplicationPath
  3. HttpRuntime.AppDomainAppPath

Edit

It should be HttpRuntime.AppDomainAppPath only as the other two option will be null in Application_End handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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