IIS URL Rewrite Rules for Subdomain Routing in ASP.NET MVC 5 -


i have web application written in asp.net mvc 5 contains information users. create profile page each of users accessible subdomain of web site (e.g. user1.example.com, user2.example.com, ...).

i want these subdomains accessible on http, while rest of application must require https used.

i run web application on iis figured best if used url rewrite rules rewrite user1.example.com example.com/profile/index?name=user1, web application wouldn't have know subdomains being used. came these rewrite rules:

<rewrite>   <rules>     <clear />     <rule name="rewrite user subdomains query string" stopprocessing="true">       <match url="^(.+)" />       <conditions>         <add input="{http_host}" negate="true" pattern="^www\.example\.com$" />         <add input="{http_host}" pattern="^([^.]+)\.example\.com$" />       </conditions>       <action type="rewrite" url="/profile/index?name={c:1}" />     </rule>     <rule name="redirect https without www" stopprocessing="true">       <match url="(.*)" />       <conditions trackallcaptures="false">         <add input="{http_host}" pattern="^www\.example\.com$" />         <add input="{http_host}" pattern="^example\.com$" />       </conditions>       <action type="redirect" url="https://example.com/{r:1}" redirecttype="permanent" />     </rule>   </rules> </rewrite> 

this code unfortunately not rewrite user1.example.com example.com/profile/index?name=user1 , forces https on user1.example.com.

would please explain me why , how fixed?

i ended using code:

<rewrite>   <rules>     <clear />     <rule name="rewrite url tenant subdomain" stopprocessing="true">       <match url="^$" /> <!-- resources user1.example.com/content/css wouldn't affested rewrite -->       <conditions>         <add input="{http_host}" negate="true" pattern="^www\.example\.com$" />         <add input="{http_host}" pattern="^([^.]+)\.example\.com$" />       </conditions>       <action type="rewrite" url="profile/index?subdomain={c:1}" />     </rule>     <rule name="redirect www.example.com" stopprocessing="true">       <match url="(.*)"/>       <conditions>         <add input="{http_host}" pattern="^example\.com$"/>       </conditions>       <action type="redirect" url="https://www.example.com/{r:1}" redirecttype="permanent" />     </rule>     <rule name="redirect https" stopprocessing="true">       <match url="(.*)" />       <conditions>         <add input="{https}" pattern="^off$" />       </conditions>       <action type="redirect" url="https://www.example.com/{r:1}" redirecttype="permanent" />     </rule>   </rules> </rewrite> 

what had me confused fact, url helpers in index template started throw system.web.httpexception: cannot use leading .. exit above top directory. since it's page need have tenant specific, gave up, hardcoded links , started working fine.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -