0

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: /sites/abc.com

/sites/anothersite

/sites/xyz.com

/sites/mymastersite.com

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

Adam
  • 16,089
  • 6
  • 66
  • 109
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

1 Answers1

1

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)
{   
    if(HttpContext.Current.Request.Host.EndsWith("xyz.com"))
       RewritePath("/sites/xyz.com" + HttpContext.Current.Request.Path, false);  
}
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • i considered Global.asax too, but wouldn't settings something in web.config be more flexible and clean? i managed to add some rules for some domains after searching for a few hours, but i am hard-writing it for every domain and need a flexible/automatic solution to be able to handle newer subdomains in the future. – Can Poyrazoğlu Jul 15 '12 at 20:49
  • @canpoyrazoğlu More Clean than this ? - the web.config is just an xml file, again a code like this do the job. – Aristos Jul 15 '12 at 21:08
  • @canpoyrazoğlu I like to tell you that this in general is not the right approach, and you going to face other issue (except if yous sites are very simple with no other RewritePath and complicate calls. The iis must separate your web sites. – Aristos Jul 15 '12 at 21:10