Adam Pedley Adam Pedley - 1 year ago 62
ASP.NET (C#) Question

UrlRewriter.NET with .NET 4.0 not working

I have a web project that had UrlRewriter.NET installed and working fine on .NET 3.5 locally.

I then upgraded it to .NET 4.0 and this continued to work on my local PC in Visual Studio 2010.

When I moved this .NET 4.0 project to my server the url rewriting stopped working.

Here is my web.config (condensed for readability here)

<?xml version="1.0"?>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>


<rewrite url="~/Neat-Url" to="~/Ugly-Url.aspx?id=1"/>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule"/>

When put on the server it just returns a 404.

Interesting discovery. If I create a directory called /Neat-Url, the url rewriting starts working again and redirects to /Ugly-Url.aspx?id=1

Note: Yes I realize that .NET 4.0 has it's own url rewriting and I also have existing code that works with UrlRewriter.

So am I doomed because it is a server configuration issue or is there a way I can work around it?

[UPDATE]: Ok so I have determined something else. The url rewriter won't work unless the file or directory actually exists.

For example. If I want to redirect /Directory1 to /Directory1.aspx, /Directory1 must exist, then it all works fine.

If I want to redirect /File1.aspx to /File2.aspx this also works but File1.aspx must exist on the file system.

Otherwise I continue to get a 404. This seems solvable via .NET and has something to do with the web.config as calling upon File1.aspx gets passed to the runtime and gets an 404. Calling a directory just gets a web host 404.

[UPDATE 2]: I removed the


section from my web config, then added

<identity impersonate="false"/>

Then also changed validateIntegratedModeConfiguration="true". Still the same problem but at least is validates in Integrated Mode now.

[UPDATE 3]: I am now trying ManagedFusion yet still running into errors, but it seems more like a configuration error on my part rather than server support. I raised another question ManagedFusion Url Rewriting not working.

Hopefully that will solve my problems.

Answer Source

change rewrite module to Url Rewrite Module. I had same problem with Godaddy, so changing is solved my problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download