2

I have an ASP.NET Web Forms website that uses .NET 4 routing to handle custom URLs.

Somebody in our organisation decided to advertise a URL with a plus sign in it (eg. www.domain.com/this+that), so now I am stuck with having to modify the system to recognise this URL and route it to the correct page.

It's a .NET 4.0 website running on IIS7.5.

I have researched how to do this already, and the advice has been to add the following to my web.config file, which I have done. But still I get a IIS 404 error message, and it doesn't even go to my custom 404 error page.

<system.webServer>
  <security>
    <requestFiltering allowDoubleEscaping="true">
    </requestFiltering>
  </security>
</system.webServer>

Any idea why this isn't working?

johna
  • 10,540
  • 14
  • 47
  • 72
  • 1
    possible duplicate of [Plus (+) in MVC Argument causes 404 on IIS 7.0](http://stackoverflow.com/questions/3375789/plus-in-mvc-argument-causes-404-on-iis-7-0) – Samiey Mehdi Sep 05 '13 at 01:13
  • Duplicate? Kind of... But answers didn't solve my problem. Also, it's Web Forms not MVC. – johna Sep 05 '13 at 01:40
  • 1
    Is that even a valid URL? If it's not valid, then I suggest you not try to work around standards. – John Saunders Sep 05 '13 at 02:27

1 Answers1

2

I can only speak from personal experience, but try one of these:

MVC:

    [ActionName("this+that")]
    public ActionResult ThisThat()
    {
        return View("ThisThat");
    }

web.config redirect:

<location path="this+that">
<system.webServer>
<httpRedirect enabled="true" destination="www.domain.com/this_that" httpResponseStatus="Permanent" />
</system.webServer>
</location>

Update: Working on my end. Make sure web.config looks like this:

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering allowDoubleEscaping="true" />
        </security>
    </system.webServer>

And Global.asax should look like the following:

    protected void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("Test", "This+That", "~/Test.aspx");

    }
Zerkey
  • 795
  • 1
  • 6
  • 16
  • The web.config change solves my problem. Thanks. However, I would still be interested in finding out why the allowDoubleEscaping didn't help... – johna Sep 05 '13 at 01:39
  • Should also point out that the web.config change in this answer only worked if allowDoubleEscaping is set to true. – johna Sep 05 '13 at 01:45
  • @John Working 100% with "+" signs in the url, see updated answer. You are missing a tag on your web.config if that matters. Can you post your routes if you are still having issues? – Zerkey Sep 05 '13 at 02:08
  • My mistake - I did already have security tag in my web.config - just left it out of my question. But, I hadn't looked at my routes and that turns out to be the problem. In my regex pattern I hadn't included the plus sign. So thanks very much for your help. Not only is my problem solved but you gave another option for how to handle this. – johna Sep 05 '13 at 02:27