I am looking for a way to rewrite the url in case the application path in the url has a different casing. Since the application path can vary for different deployments, I need to access it dynamically. Is there any way of doing it?
Background:
I am setting path of cookies to the application path. Since cookie path is case sensitive, I need to rewrite urls in case they are wrongly cased. I would also like to have alternate ways that do not need the use of the url rewrite module.
Example
Let's assume that for one deployment, the alias for the application is "ApplicationA" (for another deployment, the alias may be "ApplicationB").
http://<host>:<port>/<applicationA or Applicationa or APPLicationA etc.>/<rest of the url>
Redirect to
http://<host>:<port>/ApplicationA/<rest of the url>
Just a thought, if one would consider abandoning the camel case notation (ApplicationA) in favor of forced for example lowercase* (applicationa), you could use the ToLower keyword as below.
<system.webServer>
<rewrite>
<rules>
<rule name="force lowercase" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="[A-Z]" ignoreCase="false" />
</conditions>
<action type="Redirect" url="{ToLower:{URL}}" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>
*If you are committed to your original camelCase notation in the url then I would defer to Uriil's approach above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With