开发者

how i can track the domain where my application goes hosted in ASP.NET MVC 3?

开发者 https://www.devze.com 2023-02-24 12:36 出处:网络
i have a application who have hosted on currently on server testing. how i can check the domain where he goes hosted in the code ?

i have a application who have hosted on currently on server testing. how i can check the domain where he goes hosted in the code ?

example开发者_运维知识库.

testing.mydomain.com/

domain.com

how i can check that application goes hosted on subdomain or domain. i just want to know where he goes hosted.


you can use HttpContext.Current.Request.Url.AbsoluteUri, that will return the complete path, from which you can compare it.

Although it will fail, if user requested through IP. so the best option is in your hosted code, add a setting named BaseURL (in web.config), and set it appropriately.


You can take advantage of Host property.

if (Request.Url.Host.ToLower().Equals("testing.mydomain.com"))
{
    // sub domain
}
else if (Request.Url.Host.ToLower().Equals("domain.com"))
{
    // domain
}
0

精彩评论

暂无评论...
验证码 换一张
取 消