iis 7.5 - Regex URL rewriting for custom login page -


i'm implementing custom login page multitenant portal each client gets different login page styled according stored settings.
achieve using iis 7.5 url rewriting module.
idea capture requests "http://portal.com/client1/" , rewrite them "http://portal.com/login.aspx?client=client1".

what i'm struggling regex expression match url , extract "client1" bit out.

examples:
"http://portal.com/pepsi" = "http://portal.com/login.aspx?client=pepsi"
"http://portal.com/fedex" = "http://portal.com/login.aspx?client=fedex"
"http://portal.com/northwind" = "http://portal.com/login.aspx?client=northwind"
"http://portal.com/microsoft/" = "http://portal.com/login.aspx?client=microsoft"

so match should found if requested url contains single word after first "/" , work whether there trailing "/" or not.

"http://portal.com/clients/home.aspx" ignored rule. "http://portal.com/clients/catalog" ignored rule. "http://portal.com/products.aspx" ignored rule. 

assuming:

  • that parameter name client
  • and don't care after /client1/ can use simple pattern capture portion of url , repeat parameter

here:

<rewrite>     <rules>      <rule name="client1 rewrite">       <match url="^([^/.]*)[/]*$" />       <action type="rewrite" url="login.aspx?client={r:1}"/>     </rule>   </rules> </rewrite> 

fiddle

this works because in of ignore list there slash in "middle", slash optional @ ending of "filter" list. {r:1} contain first slash or end of url if there no slash.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -