tags:

views:

641

answers:

7

I'm trying to make semantic urls for search pages, but if someone use a search finished in dot, the .net engine return a 404.

The request don't even get to the routing engine, so i think its something related to security or something like that.

For example, the stackoverflow routes also don't work in these case: http://stackoverflow.com/questions/tagged/etc.

A: 

How about modify the 404 to resend the url without the .?

Stefan
the curious thing is that the standart 404 handler doesn't work, look the diferences at http://stackoverflow.com/asdfadhttp://stackoverflow.com/questions/tagged/etc.
Jokin
A: 

Looks like IIS might not know how to handle a request with an empty extension.

Right click on the website and choose "Properties". Click "Configuration..." on the "Home Directory" tab. Look at the "Application Extensions" and try adding an empty or wildcard extension.

Robert Wagner
I don't think so, it also happen in the visual studio web server, where all the extensions are managed by the .net handler. in my case the url is like http://search.com/search/search-term-with-dot./location.aspx
Jokin
Hmm if you get the error in VS as well are you sure you don't have an ignore route that is getting hit?
Graphain
while debugging it, the request doesn't hit the breakpoint in the routin engine. if you see the links that i posted in the comment to stefan, the treatment of both request is very diferent, one is handled by the 404 registered handler, and the another one by the default one.
Jokin
A: 

In windows, file names cannot end with a '.' I think all problems stem from there, ie IIS doesn't know what to do with it, so it never gets as far as the ASP.NET error handler and gets handles by the default IIS 404 page.

Most search engines (well Google anyway) exclude punctuation from queries, and I think yours should too.

EDIT: It falls over because it has no file type, even the Microsoft site falls over look http://www.microsoft.com/en/us/fallover. but you can modify the default error files (live somewhere like C:\WINDOWS\help\iisHelp\common) or change it completely.

Check this one out: Configuring Custom Error Messages (IIS 6.0)

DrG
Surely, file names can end with '.' in Windows.
Terminus
It's not hard to find out
DrG
Not true, and the routing system in ASP.NET has nothing to do with file names.
Jeff Putz
A: 

You shouldn't be putting exact user searches in the query string like that... you should UrlEncode them. That will solve the problem.

Timothy Khouri
the dot is a valid character in the url, so if I urlencode something with a dot it will remain the same.
Jokin
True... %2E would work though.
Timothy Khouri
would not, take a look athttp://stackoverflow.com/questions/294495/semantic-urls-with-dots-in-net%2E
Jokin
+2  A: 

Everything after the '.' is the file extension. If that extension isn't mapped to ASP.NET, it won't get handed off to the ASP.NET handler. IIS looks for a static file instead. Hence the 404. If it doesn't add anything (and hard to see how it would), I suggest stripping it out.

dpurrington
But it also happens in the visual studio web server, where all the request are mapped to asp.net. It must be a previous handler or a security mesure. Even the static file requests pass through my handlers. But if the request has a "./" in any position it's a no no
Jokin
I don't think you can make any reasonable inferences from how the development server behaves. For all we know, it knows about this problem with IIS and is doing its best to behave the same way. In the end, it doesn't matter, because you're going to deploy with IIS, not Cassini.
dpurrington
A: 

When the trailing period is not significant (as it is in the case of http://stackoverflow.com/questions/tagged/etc.) you can use IIS's URL Rewrite module to strip the trailing periods.

Pattern: ^(.*[^.])(\.+)$
Rewrite URL: {R:1}

This isn't going to help when throwing away the period is not an option, or there are periods at the end of intermediate path segments, but for the very real use case of dealing with periods being tacked on to URLs by auto-linking algorithms it can help.

Aaron Maenpaa
+1  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