1

How can I allow multiple periods in a URL?

Sample URL:

http://mylocalhost:6968/MyHome/Edit/ABCD.Applications.ClinicalData%257cCache_Timeout

I have tried:

Various Url Encoding:

       @{
            //string encodedItem = Url.Encode(item.Key);
            //string encodedItem = HttpUtility.UrlEncode(item.Key);                
            string encodedItem = Server.UrlEncode(item.Key);
        }

Adding a route handler:

<add name="UrlRoutingHandler" type="System.Web.Routing.UrlRoutingHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" path="Remote.mvc/*" verb="GET"/>

Modifying the web.config system.web

<httpRuntime relaxedUrlToFileSystemMapping="true" />

None of these things corrected the example URL.

Relevant code

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Key)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Value)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.IsActive)
        </td>
        <td>
            @{
                //string encodedItem = Url.Encode(item.Key);
                //string encodedItem = HttpUtility.UrlEncode(item.Key);                
                string encodedItem = Server.UrlEncode(item.Key);                
            }
            @Html.ActionLink("Edit", "Edit", new {  id = encodedItem }) |
            @Html.ActionLink("Details", "Details", new {  id = encodedItem }) |
            @Html.ActionLink("Delete", "Delete", new {  id = encodedItem })
        </td>
    </tr>
}

I'm clicking the Edit link.

I also tried

@Html.ActionLink("Edit", "Edit", new { id = item.Key })

which had the html output of:

a href=/MyHome/Edit/ABCD.Applications.ClinicalData%7CCache_Timeout

Click this link results in Error:

HTTP Error 404.0

I set a breakpoint in Controller.Edit. The breakpoint is never hit. Anytime I have a url of the form:

http://mylocalhost:6968/MyHome/Edit/ABCD.X

Where X is anything after a . then this error occurs. If I remove X, the breakpoint is hit.

Community
  • 1
  • 1
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
  • Which Url.encode is that? Is it HttpUtility.UrlEncode or HttpServerUtility.UrlEncode ? HttpUtility.UrlEncode seems to handle punctuation in query parameters / path portion of url. Check out the documentation/Remarks section here: http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx – Steven Magana-Zook Mar 05 '13 at 21:39
  • @StevenMagana-Zook - Question updated. – P.Brian.Mackey Mar 05 '13 at 21:48
  • How are you using the URL that it is getting messed up? What if you instead built up the final url using the Uri class? For example: Uri uri = new Uri("http://mylocalhost:6968/MyHome/Edit/ABCD.Applications.ClinicalData%257cCache_Timeout"); – Steven Magana-Zook Mar 05 '13 at 22:16
  • @StevenMagana-Zook - `item.key` comes from the `Model` which comes from a value in the DB. I'll insert the relevant code as well. – P.Brian.Mackey Mar 05 '13 at 22:20
  • Have you tried `@Html.ActionLink("Edit", "Edit", new { id = item.Key })`? If yes, what was the rendered `href` attribute and what was the result when you clicked on this anchor (did you get an error, if yes please specify what error did you get)? – Darin Dimitrov Mar 05 '13 at 22:25
  • @StevenMagana-Zook Try what Darin suggests, it might be that MVC4 already encodes/decodes this on your behalf. – EtherDragon Mar 05 '13 at 22:50
  • @DarinDimitrov - Question updated. – P.Brian.Mackey Mar 06 '13 at 00:22

1 Answers1

0

HTTP GET proved impossible. I decided to redesign the solution. Now I perform an HTTP POST in order to avoid passing data via the URL.

Ideally, my URL's would be hackable. But its an internal app and its what the customer wants so...hey kid, be careful broken glass

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348