views:

2030

answers:

9

Hi,

I'm using ASP .NET MVC Beta and I get the HTTP 404 (The resource cannot be found) error when I use this url which has a "dot" at the end:

http://localhost:81/Title/Edit/Code1.

If I remove the dot at the end or the dot is somewhere in the middle I don't get the error.

I tried to debug but it I get the error from "System.Web.CachedPathData.GetConfigPathData(String configPath)" before ProcessRequest in MvcHandler.

Is "dot" not allowed at the end of a url? Or is there a way to fix the route definition to handle this url?

Thanks in advance

+1  A: 

I can't even imagine a situation in which you would even want this, but I'm pretty sure that's not supported by any web server or web framework. Why do you want to do something so non-standard?

John Sheehan
@John-Sheehan Here's another example http://www.wikipedia.org/wiki/Washington,_D.C.
Micah
Good example. Wikipedia's URLs are incredibly infuriating to work with, so if you can avoid it, I would.
John Sheehan
Now possible with .net 4 - see my answer below
thekaido
A: 

For an example: I have a table named Detail1 [Id(integer), Code(string), Description(string)] which has FK relationship with Master1 through it's Id column. Whenever I select a record of Master1, I also select it's Detail1 record to get it's Code field. In order to not to make this join everytime (since usually there isn't only one detail, there are more than one) I choose not to use Id column and I make Code PK of Detail1.

But when I get rid of Id and use Code as PK then my routes also start to work with Code field, like: Detail1\Edit\Code1

This Code can have anything in it or at the end, including DOT. There are cases where I can prohibit a DOT at the end but sometimes it's really meaningfull.

And I'have also seen this post that routes can be very flexible, so I didn't think mine is so weird.

So that's why I do something so non-standard. Any suggestions?

And also why it's so weird to have a DOT at the end of a url?

ipek
why is it so weird? please find and post a dot-terminated URL from the web
annakata
@annakata http://www.last.fm/music/M.I.A.
Jeff Putz
+2  A: 

Perhaps http://localhost:81/Title/Edit/Code1%2E would work.

I escaped the period with a hex ascii code.

recursive
Doesn't work. Most browsers change %2E back to . before sending the request since it's an unreserved character.
Dan Fitch
A: 

Why can't you have a dot-terminated URI?

Because a URI is a resource request and a historical imperitive exists on all relevant operating systems that the dot character is the extension separator. The last dot is treated as denoting a file extension, hence dot-terminating will make no sense.

Also worth reading:

annakata
RFC3986 says nothing about this. See section 3.3, where it explicitly says that "... a path segment is considered opaque by the generic syntax."
Dan Fitch
A: 

Thanks for the explanation.

ipek
A: 

here's an example where it works: http://www.last.fm/music/M.I.A. Sorry, can't actually offer any help on it, actually stuck on this problem myself...

A: 

I would also be interested in this. And yes - also stumble upon last.fm where it works (e.g. R.E.M.) but found no hints for asp.net how to do it there.

Anyone solved that problem?

+1  A: 

I went into IIS and put the 404 error page to route to my custom Error Controller, with the plan of using the ReferrerURL parameter to get the URL that generated the error, sanitise the URL by removing the period (.) and then re-route it appropriately to the proper controller.

This does not work though, since when the 404 is generated, the header information has a null ReferrerURL, in fact, I went through all the Request parameters and there is nothing that can indicate what URL generated the 404 error, only that the error was generated.

Anyone had better luck on this?

Nissan
+5  A: 

If you are using .NET 4.0, you can set this flag in the system.web section of your web.config and it will be allowed:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

I've tested it and it works. Haack has an explanation of it.

thekaido