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

后端 未结 3 997
予麋鹿
予麋鹿 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:24

    The reason that the domain is in the request is...that's what's being asked for. For example these are a few stackexchange sites from http://www.stackexchangesites.com/:

    • http://community.ecoanswers.com
    • http://www.appqanda.com
    • http://www.irosetta.com/

    If you ping them, you'll see they all point to the same IP/Web Server and be served by the same app (or multiple apps in this case, but the example holds if it was one big one)...but the application doesn't know which one until a host header comes in with the request asking the server for that site. Each request may be to a different domain...so the application doesn't know it.

    If however it doesn't change, you could store it as an appSetting in the web.config.

提交回复
热议问题