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

梦想与她 提交于 2019-12-12 01:38:35

问题


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.


回答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);  
}


来源:https://stackoverflow.com/questions/11491454/how-to-remap-all-the-request-to-a-specific-domain-to-subdirectory-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!