How do I get the host domain name in ASP .NET without using HttpContext.Current.Request?

后端 未结 3 941
予麋鹿
予麋鹿 2021-01-18 10:56

I\'ve got an ASP .Net application running on IIS7. I\'m using the current url that the site is running under to set some static properties on a class in my application. To d

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 11:29

    Use this instead:

    HttpRuntime.AppDomainAppVirtualPath
    

    Or if you want the physical path:

    HttpRuntime.AppDomainAppPath
    

    For further reading:

    http://weblogs.asp.net/reganschroder/archive/2008/07/25/iis7-integrated-mode-request-is-not-available-in-this-context-exception-in-application-start.aspx

提交回复
热议问题