"Resource could not be found." error when there is a dot at the end of the URL

I am using ASP.NET MVC beta and I get HTTP 404 error (resource not found) when I use this url that has a “dot” at the end:

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

If I delete a point at the end or the point is somewhere in the middle, I do not get an error.

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

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




As an example: I have a table called Detail1 [Id (integer), Code (string), Description (string)], which has an FK relationship with Master1 through the Id column. Whenever I select the Master1 entry, I also select the Detail1 entry to get the Code field. In order not to make this connection every time (since there is usually not only one part, there are more than one), I prefer not to use the And column, and I do the PK Detail1 code.

But when I get rid of Id and use Code as PK, then my routes also start working with the Code field, for example: Detail1 \ Edit \ Code1

This code may have anything in it or at the end, including DOT. There are times when I can disable the DOT at the end, but sometimes it really makes sense.

And I also saw this post that routes can be very flexible, so I didn’t think mine was so weird.

So why am I doing something so non-standard. Any suggestions?

And why is it so weird to have a DOT at the end of the url?

+49
asp.net-mvc routing routes
Jan 09 '09 at 22:21
source share
6 answers

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 resolved:

<httpRuntime relaxedUrlToFileSystemMapping="true" /> 

I tested it and it works. Haack has an explanation.

+48
Aug 22 '10 at 17:37
source share

This can be solved in several ways in each version of ASP.NET from version 1.0 and higher. I know this two years after the creation of this thread, but, in any case, here:

Cause

Creating a custom error handler or setting up a custom page in IIS for 404 redirects will not work. The reason is because ASP.NET considers this URL to be dangerous. Internally, in System.Web.Util.FileUtil ASP.NET calls the private method IsSuspiciousPhysicalPath , which attempts to map the path to the (virtual, but legal) file name.

When the received legalized path is not equal to the original path, processing stops, and ASP.NET code returns 404 (it does not request IIS or web.config for user 404, it returns one of them that makes it so difficult to do something with this).

Windows Explorer works the same. Try creating a file name ending in one or more points, i.e. test.txt. . You will see that the resulting name is text.txt .

Solution for final URL in point in ASP.NET

The solution is simple (as soon as you know it, it always is). Before sending this 404 message, he will select Application_PreSendRequestHeaders , a simple event that you can register in Global.asax.cs (or the VB equivalent). The following code will return plain text to the browser, but redirection or any other valid answer is also possible.

 protected void Application_PreSendRequestHeaders(object sender, EventArgs e) { HttpResponse response = this.Context.Response; HttpRequest request = this.Context.Request; if (request.RawUrl.EndsWith(".")) { response.ClearContent(); response.StatusCode = 200; response.StatusDescription = "OK"; response.SuppressContent = false; response.ContentType = "text/plain"; response.Write("You have dot at the end of the url, this is allowed, but not by ASP.NET, but I caught you!"); response.End(); } } 

Note: this code also works when "aspx" is not part of the url. Ie, http://example.com/app/somepath . will cause this event. Also note that some paths will not work anyway (ending with a few dots, with a hash tag or, for example, <-sign, causes a 400-Bad Request). Again, it works to complete a quote, space + slash, or multiple dots separated by spaces.

+16
Mar 11 2018-11-11T00:
source share

Well, in .NET 4.5 I fixed this problem by adding "/" to the end of the url.

So, in your case it will be "http: // localhost: 81 / Title / Edit / Code1. /". This was the only thing I did, I did not need to add httpRuntime settings.

+6
Nov 15 '12 at 12:18
source share

add this to handlers

  <add name="ExtensionlessUrlHandler-Integrated-4.0-ForApi" path="api/*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers> 
0
Dec 15 '16 at 13:19
source share

Maybe http://localhost:81/Title/Edit/Code1%2E will work.

I escaped the period with the hex code ascii.

-one
Jan 10 '09 at 15:48
source share

Why don't you have dotted URIs?

Since the URI is a resource request and a historical imperative exists in all relevant operating systems, the extension character is the dot symbol. The last point is considered to mean the file extension, so the termination point does not make sense.

Also worth reading:

-3
Jan 10 '09 at 17:04
source share



All Articles