locked
Url rewrite and redirect to subdomain after login RRS feed

  • Question

  • User-1154155734 posted

     

    Hi everybody,

    Current situation:

    I have an asp.net website and its hosted in IIS7, on my developer environment. I have bind the website to some domains for example:

    • www.mywebsite.com
    • mywebsite.com
    • newyork.mywebsite.com
    • paris.mywebsite.com
    • madrid.mywebsite.com

    The word before the domain (subdomain) is very important because I have a method who get some data depending on this word.

    Some examples for the current situation:

    Before logging on
    After logging on
    http://newyork.mywebsite.com/somePage.aspx https://newyork.mywebsite.com/somePage.aspx
    http://paris.mywebsite.com/somePage.aspx https://paris.mywebsite.com/somePage.aspx
    http://madrid.mywebsite.com/somePage.aspx https://madrid.mywebsite.com/somePage.aspx


    New situation:

    Now I would like to change the url after the customer is logged on. When a user is logged on he get for example this url:

    https://customer.mywebsite.com/newyork


    Some examples for the new situation:

    Before logging on
    After logging on
    http://newyork.mywebsite.com/somePage.aspx https://customer.mywebsite.com/newyork/somePage.aspx
    http://paris.mywebsite.com/somePage.aspx https://customer.mywebsite.com/paris/somePage.aspx
    http://madrid.mywebsite.com/somePage.aspx https://customer.mywebsite.com/madrid/somePage.aspx


    Can someone help me in the right way to implement this. I have read and heard about a httpmodule and url rewrite. When I search on google I found the URL rewrite module for IIS7. Is this the best solution to implement this?
    Friday, October 15, 2010 8:44 AM

Answers

  • User-619846739 posted
    In that case it sounds like you need to use a combination of the two. Use a redirect after authentication to go from the original URL to the new desired URL. (i.e. order.mywebsite.com/NewYork. Then use URL Rewrite to have order.mywebsite.com/NewYork really call order.mywebsite.com/default.aspx?dealerName=NewYork. The easiest way to do the URL rewrite portion is to use the "User-friendly URL" wizard. In the wizard paste http://order.mywebsite.com/default.aspx?dealerName=NewYork into the first field and select the example that you want. The one that you're looking for is one of the options. Check the two checkboxes at the bottom too.
    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Tuesday, October 19, 2010 9:05 AM

All replies

  • User-1154155734 posted

     Nobody?

    Monday, October 18, 2010 3:21 AM
  • User-176674611 posted

    Hi,
     
    You cannot achieve this simply by using URL rewrite rules. As far as I know, the URL Rewrite Module runs before any authentication happens in IIS, so we cannot get the customer's login information via server variables in rewrite rule. You can implement an ASP.NET module to achieve this. This article is an example for it:
    Redirect clients in your application with HttpRedirection module
    http://mvolo.com/blogs/serverside/archive/2007/05/24/Redirect-clients-in-your-application-with-HttpRedirection-module.aspx

    Monday, October 18, 2010 5:43 AM
  • User-619846739 posted

    I agree with Lloydz that URL Rewrite isn't the best solution for this since the authorization decision is made after URL Rewrite has redirected the request.

    However, the solution should be pretty easy.  In the ASP.NET code just after they have authenticated, just add a Request.Redirect to the desired URL.  Within ASP.NET you have access to Request.ServerVariables("HTTP_HOST") to get the domain name.  So, you could take the subdomain from HTTP_HOST and redirect to the new customer URL. 

    You can do this with the HttpRedirection module as Lloydz suggested, and you can also consider using Application_AuthorizeRequest from global.asax.  http://www.codetoad.com/asp.net_globalasax.asp.

    Monday, October 18, 2010 11:15 AM
  • User-1154155734 posted

     Hi,

     A redirect is not anough because when I redirect to the second domain the dealerName is moved from subdomain to a path.

    The first url is

    NewYork.mywebsite.com

    After login I redirect to the second url:

    order.mywebsite.com/NewYork

    But I would like to do underwater something like this:

    order.mywebsite.com/default.aspx?dealerName=NewYork

     

    Is it possible to do this with the URL rewrite module with some rule and regular expressions?

     

    Tuesday, October 19, 2010 7:04 AM
  • User-619846739 posted
    In that case it sounds like you need to use a combination of the two. Use a redirect after authentication to go from the original URL to the new desired URL. (i.e. order.mywebsite.com/NewYork. Then use URL Rewrite to have order.mywebsite.com/NewYork really call order.mywebsite.com/default.aspx?dealerName=NewYork. The easiest way to do the URL rewrite portion is to use the "User-friendly URL" wizard. In the wizard paste http://order.mywebsite.com/default.aspx?dealerName=NewYork into the first field and select the example that you want. The one that you're looking for is one of the options. Check the two checkboxes at the bottom too.
    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Tuesday, October 19, 2010 9:05 AM
  • User-1154155734 posted

     I have created a rule with the User-friendly URL wizard. And I pasted the url order.mywebsite.com/default.aspx?dealerName=NewYork. And when I run this url in the browser it worked:

    order.mywebsite.com/NewYork

    But when I click on a link on my website. It goes for example to order.mywebsite.com/pages/categories/categoryList.aspx?id=12. And the dealer name (NewYork) isn't available in the url. The web application needs this company name, otherwise it wil not work. Thats the reason I would like to add in each url the dealer name. Something like underwater:

     order.mywebsite.com/pages/categories/categoryList.aspx?id=12&dealername=NewYork

     And shows the virtual url:

     order.mywebsite.com/NewYork/pages/categories/categoryList.aspx?id=12

     

     

    Tuesday, October 19, 2010 2:27 PM