urlrewriter.net / c# / I just don't get it
I want to implement url-rewrite into an webapplication with the urlrewriter.net module.
This is my scenario now (numbers are fictional): Browse.aspx?cid=9&countryid=85 (cid stands for category id)
Now I want something like 开发者_如何学运维this categoryname/countryname.html
So i figured this might work but it doesn't. Its my first time using this i must be missing something.
<rewrite url="~/(.+)/(.+).html" to="~/Browse.aspx?cid=$1&countryid=$2" />
Maybe I need to use the title instead of the id on $1 and $2 but then it would be a lot harder to query things i suppose? And it means alot of rebuilding in the application
Can someone please help me get my head together for this?
Kind regards and thank you for reading, Mark
It looks like your example would rewrite ~/9/85.html
into Browse.aspx?cid=9&countryid=85
I suspect you're looking for something more friendly.
To solve this, give some thought to how you will be generating the *.html URLs in your pages. You could embed the category and country names there, and then just ignore them when you do the URL rewriting.
You're going to have to lookup the id's on your page with the way that you're doing it right now. Meaning /mycategory/us.html is going to turn into browse.aspx?cid=mycategory&countryid=us
There are two solutions.
1) Pass in the country and category NAMES and do a look up in your DB in browse.aspx
2) Add the id's to the url. Something like http://www.mysite.com/1/2/mycategory/us.html. The web.config setting would be:
<rewrite url="~/(\d+)/(\d+)/(.+)/(.+).html" to="~/Browse.aspx?cid=$1&countryid=$2" />
Hope that helps.
Probably, a request just can't reach urlrewriter.net module because IIS treats it as the request to certain file, not to ASP.NET. You may find helpful the following article: http://www.codeproject.com/KB/aspnet/iis-aspnet-url-rewriting.aspx
Guess you probably solved or gave up on this a long while ago but for anyone visiting that is meeting a similar problem the solution is to create a custom transform.
You extract the friendly text value using a regex like you would normally and then pass that text to the transform which looks up the value in the database and returns an ID code.
I have gone into this in detail in my article over at:
- http://runtingsproper.blogspot.com/2009/11/advanced-url-rewriting-for-rest-of-us.html
精彩评论