简体   繁体   中英

URL rewrite in ASP.NET application

How do I redirect url based on register client in c# .net or asp.net 4.0. For example if client registers as "client1" and our website is www.mycompany.com for every page client proceeds should get www.client1.mycompany.com.

More detailed example:

For example another client created is Client2. The pages i have created in general is like

 "www.mycompany.com/product.aspx" 
 "www.mycompany.com/categories.aspx" should be shown as
 "www.client2.mycompany.com/product.aspx" and
 "www.client2.mycompany.com/categories.aspx" respectively

I have searched on web and found for static pages or using Gloabal.asax during startup of application but haven't found any thing after user logged in.

I have done something similar before in a few sites and there are a couple methods you could use. Assuming that you have a url setup so that all subdomains ( *.url.com) will send any user to your server and you have IIS setup to handle them all (ie no host header required, just IP) in the same site you can use one of the following methods:

  1. After login simply send the user to that url. Since .Net won't care the url the server knows how to render it, then it should be that simple. This assumes all your navigation uses relative paths and you must enable cookie sharing for that domain. This is required if the cookie for login was give on 1.url.com and you send them to 2.url.com You can share cookies in the same domain, requires a little work, but can be done.
  2. Create a generic login page that does a web service request back to the server to see if the user can login. If he or she can have it send back to the browser a command, along with the correct url, that tell the clients browser to post directly to that sites login page (send username, password). This will login them into their site and assign the cookies correctly all from one simple login page. You could even make an external login page that only exists for this purpose. In the end all the generic page did was see if they could login and the sent their credentials to the correct page that did the login. I recommend this be done in a post with ssl for security reasons.

I hope that makes since.

There's a project called UrlRewritingNet which I use - it's pretty old but the source is available so you could recompile it for 4.0.

Link is at http://urlrewriting.net/149/en/home.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM