Click here to Skip to main content
15,897,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

I have used the urlrewriter.net to rewrite a URL, so a URL like this :

Projects.aspx/ProjectId=4 became: Project/trains-4.aspx.

But my problem is that i need to get the title from the url which is "trains" here.
So iam using : Request.PathInfo, but it is not working.So is there any way to get the "trains" from the url .

Note: the request.querystring gets the initial url which is:"Projects.aspx/ProjectId=4"

Thanks in advance.
Posted

I haven't used urlrewriter.net but URL rewriting works by specifying a rewrite rule in server configurations i.e. if you are using IIS7 then URL Rewrite tool is used for the purpose and only server has access to the rule. So I would imagine no matter what you do in C#, you would only ever get the long/original URL and not the rewritten one. The rewrite URL is just a regular expression which replaces old URL with the new one at the server level, so your C# code doesn't quite get to read the new URL as the server just internally re-directs you to the new URL. You can may be try specifying a reverse write rule or just send the new URL as a GET parameter with the original URL (not sure how exactly, but a rough idea).

See if this does anything to help you : URL Rewriting in ASP.NET[^]

EDIT: something more for you : URL Rewriting with ASP.NET[^]

Turns out, if you have a finite number of URLs to rewrite then you can define them in the web.config and then u can read in your C# code using the ConfigurationManager class. Hack around with it.

Cheers...
 
Share this answer
 
v3
You are using some terminology that is confusing me, but I suggest comparing the values in Request.Url and Request.RawUrl. Perhaps one of those has the value you are looking for.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900