問題描述
子網站的 URL 重寫? (URL Rewriting for a Subsite?)
So this is what I'm trying to achieve...
I have a site with the URL with the following format:
somedb.mysite.com
somedb can be many different DBs. The problem is, different DBs require different versions of the site. These different versions are setup as subsites of the parent site.
For example somedb.mysite.com/1.0 and somedb2.mysite.com/2.0
Currently I'm using Response.Redirect() in the parent site to redirect to the proper version. What I'm HOPING to do is to HIDE the version number so that all DBs appear to be using the same site, and so the URL appears the same if a DB is updated to a newer version.
I've been messing around with using RewritePath and Server.Transfer with not a lot of success... The main problem (from what I can gather) is that Rewrite and Transfer only work within the same site, but the individual versions are technically different subsites sites.
Does anybody have any ideas how I may be able to achieve what I'm trying to do?
參考解法
方法 1:
I would suggest you write your own handler to intercept incoming request for you subdomains
To achieve this you can implement the IHttpHandler and process the url redirection logic in t he ProcessRequest method
Here is a very good example http://www.codeproject.com/Articles/30907/The-Two-Interceptors-HttpModule-and-HttpHandlers
(by user1556027、HatSoft)