Redirecting Multiple IIS Domains

Currently, I have 2 domain names for which I want to set up different sites. I am currently considering using a free hosting service that works well for my current needs, but does not give me any way to point "mydomain.com" to the actual site. Instead, I should give users a longer and more difficult to remember URL.

My suggested solution is to point my domains to my home ip and host a small ASP.NET application through IIS consisting of a redirect page that simply redirects to the appropriate site. Is there a way in ASP.NET to recognize which domain was requested to find out where to redirect the page?

+3
source share
2 answers

Here is one way to do this (as recommended by 1and1.com if you host multiple domains). Put this at the root of your web space. All your websites will point to this root. The script below forwards the requests to the appropriate subfolder. This is a kind of hack, but if you do not have full control over IIS settings, this will work.

Name this file default.asp:

<%EnableSessionState=False

host = Request.ServerVariables("HTTP_HOST")

if host = "website1.com" or host = "www.website1.com" then
response.redirect("http://website1.com/website1/default.aspx")

elseif host = "website2.com" or host = "www.website2.com" then
response.redirect("http://website2.com/website2/default.aspx")

else
response.redirect("http://website1.com/")

end if
%>
+2
source

From asp.net code, you can access the host from the request object:

if(Request.Url.Authority == "www.site1.com")
    Response.Redirect(...);

If you have access to the IIS server, you can also configure two sites with different host names and redirect them as you wish.

+1
source

Source: https://habr.com/ru/post/1699323/


All Articles