Can Poyrazoğlu Can Poyrazoğlu - 8 months ago 37
ASP.NET (C#) Question

How to remap all the request to a specific domain to subdirectory in ASP.NET

I am using ASP.NET 4.0 (integrated pipeline) with multiple domains in one hosting account. I have my primary domain set up but I want to separate the domains clearly using folder hiearchy. (I have root FTP access, can map all the domains but the master domain to subfolders) I need to map my master domain to a folder too. I'm sure ASP.NET does provide such functionality, probably in web.config settings, but I don't know how to do it. All my searches have led to PHP/Apache settings but I couldn't find one about ASP.NET remapping seamlessly.

For example, I've got these sites in my FTP root:




I need to put to my root / a web.config that needs to map all requests to to /sites/ folder, including all the subdomains too, seamlessly.


I think that the correct solution is that every request by IIS go direct to the correct site, and not on the root as you say.

How ever a way that I can think to make what you ask is to use on Global.asax the Application_BeginRequest to RewritePath to the final destination and still have the link without the /site/ path.

protected void Application_BeginRequest(Object sender, EventArgs e)
       RewritePath("/sites/" + HttpContext.Current.Request.Path, false);