PDA

View Full Version : URL Rewriting problem in .NET



sajjadlogic
16 Jun 2006, 08:01 AM
Hello

I am using URL rewriting through a downloaded .NET application. Which uses web.config file for rewriting rules and some other code. The snapshot of web.config is below. I have also checked some other applications which are using the same technique.

WEB.CONFIG FILE
=========================

<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/monitors\.aspx</LookFor>
<SendTo>~/default.aspx?c=2</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/computers\.aspx</LookFor>
<SendTo>~/default.aspx?c=3</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/software-(\d{2})\.aspx</LookFor>
<SendTo>~/default.aspx?c=$1</SendTo>
</RewriterRule>

</Rules>
</RewriterConfig>

<system.web>
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</httpModules>


=====================================================

The problem is, that it is dependent on web.config file which only executes when an ASPX request arrives on server. For example, if I rewrite a *.aspx URL in *.html or in any other file format, the web.config file is not activated by the server and hence I get a 404. For example, I cannot use this kind of rewrite rule in my web.config.


<RewriterRule>
<LookFor>~/software-(\d{2})\.html</LookFor>
<SendTo>~/default.aspx?c=$1</SendTo>
</RewriterRule>



Because server gets a request of *.html file and it doesn't hand over it to .NET engine, so finally web.config is not read for this request.

I want to ask for any other way of URL rewriting in asp.net in which I can use any file extension like *.html, *.php, etc in re-writing rules. Like I can do in Apache mod-rewrite.


Thanks.

DanInManchester
20 Jun 2006, 11:51 AM
I simply don't use any other extension apart from aspx for all my pages. This way the .net application is always in control.

If you are able to configure your IIS setup you can map other file extensions to the same ASP.net application so that when say a jpeg file is requested the .net application will be invoked.

Another approach is to use an ISAPI filter but I'm unsure of how you would tie this into your .net application.