Using Url.RouteUrl to redirect to C # url,%, etc.

In a web application I'm working on, we would like to be able to show resource information along a given path. The path is completely virtual, it only exists in the application & mdash, so we really have no problem setting up virtual user paths, which are the "weird" standard filesystem standards.

Problem: we have a route that reads something similar to

/Files/{*path}

      

and we are trying to redirect with

Url.RouteUrl("File", new { path = somePath })

      

This usually works, but fails if somePath contains and / or #, among others. On those occasions I suck. I cannot UrlEncode(somePath)

at this point because RouteUrl does its own url encoding, but I cannot leave them as-is because otherwise they are not handled properly (octothorp does not go to the routing data and the ampersand is confusing to IIS) ... Is there any common sense around this? Or do I just need to implement my own routes using string interpolation?

+2


source to share


2 answers


I've been playing around with your example and I can't find any problems using RouteUrl with the special characters described above, at least not in my test environments. The RouteUrl method encodes the correct urls and the controller gets the value in decoded form without any problem or deformation.

I've tested this in IIS 7 as well as VS 2008 development web server.



Can you provide a more complete sample code?

0


source


The best answer I've found so far, although it only works on IIS7, is this: http://dirk.net/2008/06/09/ampersand-the-request-url-in-iis7/ edit the registry and change the default behavior of IIS7. This is unacceptable to us since we are creating an application that will be installed on end-user computers and, anyway, even if we did not, it would be the fact that IIS6 and IIS5 do not respond to this sequence. Any ideas for earlier versions of IIS or ways to override this behavior programmatically in IIS7 would be great.



0


source







All Articles