0

I have an article based website where users can login, post articles etc.

The url I am using for a registered user looks as follows (only example):

http://example.com/Author/1234/Screenname

Like you can see, I am passing through the ID (1234) and using the users screen name.

The Problem

Passing the ID is 100% fine, but once a user has a special character or anything that is not A-Z, it will return a 404 or a Bad Request page.

Problematic URL

See /Screen.name - I want to replace special characters, coz it will cause a Http error.

http://example.com/Author/1234/Screenname.

I want to use the Intelligencia UrlRewriter in the web.config (or any other global solution, e.g. global.asa) to replace special invalid url characters.

My current web.config rewriter code:

<rewrite url="^~/Author/(.+)/(.+)" to="~/Contributor_Profile.aspx?auID=$1&amp;auN=$2" processing="stop" permanent="true"/>
Marc Uberstein
  • 12,501
  • 3
  • 44
  • 72
  • The problem is you need to URL encode parameters in the query string. I don't know this Intelligencia stuff, but you should try and see how it can do that. – fge Jan 20 '12 at 08:40
  • As per fge's comment, the problem here may be invalid characters in the URL rather than the URL rewriting module (which we use actually). See http://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid for valid and invalid characters in a URL. Which characters are you experiencing problems with? – rrrr-o Jan 20 '12 at 16:42
  • Thanks for the comments. I know the problem is in the url, but it is my clients existing data that can't be changed. That is why I want to replace the characters before loaded in the address bar, to avoid any issues. – Marc Uberstein Jan 21 '12 at 22:46
  • So is the URL served without the rewriter? If so, this may indicate that the rewriter is doing some internal parsing/validation that may be modified. Can you provide an example of a problematic URL, including the characters that are causing it to fail? – rrrr-o Jan 24 '12 at 11:17
  • The friendly url is called directly, then doing the rewrite and tries to load page. See my problematic url in my updated answer. :) thanks. – Marc Uberstein Jan 24 '12 at 11:34
  • I can successfully parse and redirect a URL with a full stop in it following your example, and retrieve that value from the query string on the target page. That is running locally in IIS on Windows 7. One option that we do use (but didn't made any difference in this situation) is to encode the value when you pass it on the query string so use `encode($1)` rather than just `$1` – rrrr-o Feb 02 '12 at 14:50
  • Hi thanks for the reply. See my updated question, the full stop should actually be at the end of the URL. I have added the encode() method around my var $1, still the same issue. Maybe I should just try finding all the places on the website and uri encode the author names?? – Marc Uberstein Feb 02 '12 at 15:23

1 Answers1

0

Try this in your web.config

<httpRuntime relaxedUrlToFileSystemMapping="true" />
rrrr-o
  • 2,447
  • 2
  • 24
  • 52
  • Thanks for this. But I forgot to mention I am using .Net 3.5 – Marc Uberstein Feb 03 '12 at 05:22
  • From what I [read](http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/5206beca-071f-485d-a2bd-657d635239c9/) the problem seems to be down to a problem with the Uri class. You could upgrade to .NET 4.0 and implement the above option, or there looks to be a [workaround](http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/5206beca-071f-485d-a2bd-657d635239c9/) that I haven't tried. – rrrr-o Feb 03 '12 at 09:15
  • Thanks for all the help. I will accept your answer, coz i'll have to convert to 4.0. and/or check the workaround. Cheers buddy – Marc Uberstein Feb 03 '12 at 11:43