An issue has been frustrating me today in setting up a URL Rewrite in an old .Net Webforms website (EDIT: It is a Web Site project, not a Web Application project, if that is making a difference). The site I'm working on is linked to a lot, all linking to "webroot.com/default.aspx" rather than just "webroot.com". We're wanting to set up (SOMEWHERE, at this point I don't care if it's in global.asax as a redirect or web.config) a URL rewrite to go from /default.aspx to /.
I've tried setting up in code through global.asax:
if (Request.Url.PathAndQuery.ToLower().Contains("/default.aspx"))
Response.RedirectPermanent("/" + Request.Url.Query, true);
This leads to a redirect loop, which I understand totally understand why, was a dumb idea to try it. No other directories has a default.aspx, so I'm not worried about catching others at the moment.
I've tried setting up a URL Rewrite through web.config in the system.webServer node, seen here:
<rewrite>
<rules>
<rule name="RemoveDefaultAspxFromRoot" stopProcessing="true">
<match url="default.aspx" ignoreCase="true" />
<action type="Rewrite" url="/" appendQueryString="true" />
</rule>
</rules>
</rewrite>
This leads to the same issue, which puzzles me as I didn't think a rewrite would perform a redirect, but apparently it does?
I've tried adding in the following in the rule as a voodoo blog-post idea:
<conditions logicalGrouping="MatchAll">
<add input="{REMOTE_PORT}" pattern=".*" />
</conditions>
No dice; still getting stuck in a redirect loop.
I even went through installing the URL Rewrite module manually to IIS and setting up the rule through there via the gui, which can be seen here:
http://i.imgur.com/ovYpfhM.png
I'm still getting a redirect issue.
Can anyone see anything that I'm missing, or have other suggestions? It's strange that this issue seems to be resolved for other people by using the Rewrite action, but that it's not working for me.
I've tried these solutions on IIS7 by publishing locally and setting it up through IIS, and IIS Express through VS2013. Our production servers use IIS7.