I am using the below rule in web.config to remove ".aspx" from URL
<rule name="RemoveASPX" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="AddASPX" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
The page methods are working fine earlier but after adding this rule web.config, they stopped working. If i remove this from web.config they start working. Can anyone explain why this is happening. I have googled but not get any clues.
That's because the rule AddASPX
is adding the .aspx
to all the incoming URLs but those that directly refer to a file or directoy, or have a dot.
If your page mehtod urls look like this path\page.aspx\methodname
, they are not modified because there is a .
(dot) in it. But, if your urls look like this: path\page\methodname
, they are rewritten as path\page\methodname.aspx
and that's why them stop working.
You have to determine a pattern that works for this cases, and implement a condition to ignore it. You need to determine how the failing URLs look like. You can use fiddler or the browser console (press F12 to open it) to see the requested URLs.