简体   繁体   English

在ASP.NET应用程序中重写URL

[英]URL rewrite in ASP.NET application

How do I redirect url based on register client in c# .net or asp.net 4.0. 如何在c#.net或asp.net 4.0中基于注册客户端重定向url。 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. 例如,如果客户注册为“ client1”,而我们的网站是www.mycompany.com,则客户收益的每一页都应获得www.client1.mycompany.com。

More detailed example: 更详细的例子:

For example another client created is Client2. 例如,创建的另一个客户端是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. 我已经在网上搜索并找到了静态页面,或者在应用程序启动期间使用了Gloabal.asax,但是在用户登录后却找不到任何东西。

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: 假设您具有url设置,以便所有子域(* .url.com)都可以将任何用户发送到您的服务器,并且您具有IIS设置来处理它们在同一站点中的所有用户(即,不需要主机头,只需IP)使用以下方法之一:

  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. 由于.Net不在乎该URL,因此服务器知道如何呈现它,因此它应该就这么简单。 This assumes all your navigation uses relative paths and you must enable cookie sharing for that domain. 假设所有导航都使用相对路径,并且必须为该域启用Cookie共享。 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. 如果登录的cookie是在1.url.com上给出的,并且您将其发送到2.url.com,则这是必需的。您可以在同一域中共享cookie,需要一些工作,但是可以完成。
  2. Create a generic login page that does a web service request back to the server to see if the user can login. 创建一个通用的登录页面,该页面将向服务器发出Web服务请求以查看用户是否可以登录。 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). 如果他(她)可以使它发送回命令给浏览器,请输入正确的URL,告诉客户端浏览器直接将其发布到该站点的登录页面(发送用户名,密码)。 This will login them into their site and assign the cookies correctly all from one simple login page. 这将使它们登录到其站点,并从一个简单的登录页面正确分配所有cookie。 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. 出于安全原因,我建议在ssl的帖子中完成此操作。

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. 我使用了一个名为UrlRewritingNet的项目-它很旧,但是源可用,因此您可以将其重新编译为4.0。

Link is at http://urlrewriting.net/149/en/home.html 链接位于http://urlrewriting.net/149/en/home.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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