Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic urls with dots in .net

Tags:

.net

iis

routing

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: https://stackoverflow.com/questions/tagged/etc.

like image 657
Jokin Avatar asked Nov 16 '08 22:11

Jokin


People also ask

Can I use dot in URL?

You cannot have dots in the end of an URL - no matter if it's a blog post or a forum post, like this one.

Why do we use dot in URL?

Adding the dot to the end of the domain name makes it an absolute fully-qualified domain name instead of just a regular fully-qualified domain name, and most browsers treat absolute domain names as being a different domain from the equivalent regular domain name (I'm not sure why they do this though).


3 Answers

If you are using .NET 4.0 and IIS 7+, 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.

like image 156
bkaid Avatar answered Sep 30 '22 03:09

bkaid


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.

like image 29
dpurrington Avatar answered Sep 30 '22 05:09

dpurrington


When the trailing period is not significant (as it is in the case of https://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.

like image 1
Aaron Maenpaa Avatar answered Sep 30 '22 04:09

Aaron Maenpaa