Question

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?

Was it helpful?

Solution

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).

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top