ASP.NET MVC being hosted at DiscountAsp.Net and using a domain pointer

Go To StackoverFlow.com

1

I host a website on DiscountASP.NET and they have any option of adding a domain pointer for a separate domain using your same hosting account. Thus if the original site is abc.com you can purchase a domain pointer to xyz.com and both initially point to the same root location. Using the root for abc.com is OK, but when xyz.com is the address, I want to reroute to a separate subdirectory that contains the code for xyz.com. Where would I try redirecting xyz.com to reference the subdirectory's code instead of using the root directory? I am thinking that handling it the Global.asax where typically all the routing code resides is too late, since I want each site's Global.asax file to handle their respective sites independently.

A post on the DiscountAsp.Net forum for classic ASP discussed adding code like the following to the default document.

If InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain1.YourHostedDomainName.com") ) > 0 Then Response.Redirect("/subdomain1") ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain2.YourHostedDomainName.com") ) > 0 Then Response.Redirect("/subdomain2") ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("subdomain3.YourHostedDomainName.com") ) > 0 Then Response.Redirect("/subdomain3/home.asp") End If

ASP.NET MVC is my first web project and as far I what I understand all routing flows through RegisterRoutes() and the route collection which is set of in Global.asax. Any ideas?

2009-06-16 19:35
by Rick


1

You need to make the subfolder a separate Application (in DiscountAsp.net's control panel)

Then, try writing an HttpModule that calls Response.Redirect to redirect the browser to the subfolder on the root domain.

If you want to keep your users on the subdomain, I don't think it's possible. I've never used ASP .Net MVC, but I assume that routes are registered per-AppDomain, which means that the folder for each subdomain would have to be its own Application. There is no way (AFAIK) to transfer execution across AppDomains (Server.Transfer won't do it).

If I'm wrong, and it is possible to do it without making seperate Applications, make an HttpModule that calls Server.Transfer on requests from the subdomain (and make sure that links are relative to the folder representing the subdomain; ~ paths won't work).

2009-06-16 21:17
by SLaks
Thanks for the suggestion. I had to go out of town for a few days. I will give it a try next week. Thanks again - Rick 2009-06-18 17:41
Thanks for the advice. I did create a separate application and registered an HttpModule in IIS that handled the redirect. I still was not able to get everything working as two independent sites which I was hoping for, so I ended up just opening a new account for the 2nd site. But I did learn a bit more, so that it always a good thing - Rick 2009-06-23 18:58


0

The route manager in MVC is to map urls to controllers. Controllers are code, and the location does not matter as much. I'm unaware of a way to use the Routing to do redirection which is what you are looking for. DiscountASP.Net should have a way of pointing your new domain to a different folder, I would check your control panel for a way to do this.

If you are on IIS 7, this is likely to use host headers to do the directing for you. In this situation (IIS 7 or not), you should be aware that you will likely be running a website in a website. If your root site is not asp.net, things are probably going to be easier, however, if your root (abc.com) is an asp.net site (sounds like that's not the case from your question, but it's good information, so I'll tell you anyway) the web.configs will be addative.

- root
|
|- xyz.com
 |
 |- web.config (xyz.com)
|
|- web.config (abc.com)

Be aware that abc.com's web.config will be applied first, and then xyz.com, and they can conflict and create annoying issues. But you should check in your control panel first for a way to point your new domain at a different folder. Running multiple websites out of a shared hosting account comes with a potentially large set of headaches, so I wish you good luck.

2009-06-16 19:45
by NerdFury
According to discountasp.net's technical support, "You can use the Root Domain Pointer addon to point additional domains to the root of your hosted account and then programically redirect these domains to a subdirectory. - Rick 2009-06-16 20:05


0

You appear to be trying to run two separate websites, one of them on a subdomain.

I don't use DiscountAsp.Net, but they should allow you to set up a separate web site that serves your subdomain; contact their support.

2009-06-16 20:12
by SLaks
I've contacted their technical support and they indicate that you have to programically redirect these domains to a subdirectory. Their examples show how to redirect using classic ASP.Net and Response.Redirect(). I have also posted in their forum with no answer yet.... - Rick 2009-06-16 20:24
Ads