how i can track the domain where my application goes hosted in ASP.NET MVC 3?
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
}
精彩评论