tags:

views:

1038

answers:

3

I currently have 2 domain names that I want to setup different websites for. I am currently looking at using some free hosting that works well for my current needs but doesn't give me any way to point "mydomain.com" to the actual site. Instead I have to give users a longer, harder to remember url.

My proposed solution is to point my domains to my home ip and host a small ASP.NET app 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 url was requested in order to know where to redirect the page to?

+1  A: 

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 set up two sites with different binding host names and have each redirect as you like.

Cristian Libardo
A: 

Also looks like you could merge with this question, you are both trying to solve the same thing.

cfeduke
+1  A: 

Here is one way to do it (as recommended by 1and1.com if you host multiple domains). Put this at the root of your web space. All of your websites will point to this root. The script below will forward the requests to the proper subfolder. It's kind of a hack, but if you don't have complete control over the 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
%>
Jim