Let's say for example that my site is www.mysite.com
.
I have create a sub domain here, let's say sub.mysite.com
, and deployed an asp.net webform application in here. Everything works fine when I browse to http://sub.mysite.com
A friend of mine, who owns another website, let's say www.hissite.com
, has created a DNS entry for the subdomain sub.hissite.com
and setup the IP address of my web site. He want to redirect the subdomain of his web site to the subdomain of my website.
Unfortunately my provider told me that this kind of configuration works only for 2nd level domains and that I should create a piece of code, in my www.mysite.com
web application, to check if the request is relative to the site sub.hissite.com
, and do a redirect in that case to my sub.mysite.com
.
How do I check if the request is for sub.hissite.com
in my webform application?
What happens to the URL in the client browser?
Thanks for help
EDIT 1:
Actually I have configured an alias for my website but I get the following error when navigating to sub.hissite.com
:
Application Request Routing Error
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed. The domain may not be inserted correctly on Rewrite Maps.
EDIT 2:
Following the answer of OnoSendai I have implemented an MVC ActionFilter
public class MyRedirectFilter : ActionFilterAttribute
{
public override void OnActionExecuting( ActionExecutingContext filterContext ) {
string newUri = "http://sub.mysite.com";
HttpRequestBase request = filterContext.HttpContext.Request;
string referer = request.ServerVariables["HTTP_HOST"];
if ( referer != null && referer.Contains( "hissite" ) ) {
filterContext.HttpContext.Response.Redirect( newUri, true );
}
}
}
And now the application works nice. However the address in the browser address bar change from www.hissite.com
to sub.mysite.com
. Is there any way to make it not change?
Thanks