Get Query string with After Rewrite ulr?

85 views
Skip to first unread message

WK Steven Nguyen

unread,
Jul 20, 2013, 1:13:51 AM7/20/13
to urlrewr...@googlegroups.com
Hi all,

I have a real url like this: www.mydomain.com/Media/Album.aspx?aid=1
After Ulr Rewrite like this: www.mydomain.com/Album/id=1

When i access it ok. But I want to get Ulr Query String with C# code: string X = Request.Url.ToString();
then varible X have value: www.mydomain.com/Album/id=1?aid=1

Why? Why it have "aid=1" ?

If I user "Request.RawUrl.ToString()" it get "/Album/id=1" but not have the domain name.

I want get exactly the url is " www.mydomain.com/Album/id=1" to varible X.

Help me, thanks.

Goldie

unread,
Jul 20, 2013, 9:22:23 AM7/20/13
to urlrewr...@googlegroups.com
its your rewrite that is the problem.

try rewriting it so that the ID value is a page to itself.  like www.mydomain.com/Album/1 and the rewrite is to www.mydomain.com/Media/Album.aspx?aid=1

then you can pull from the QueryString property of Request instead of trying parse it out of the URL.

WK Steven Nguyen

unread,
Jul 20, 2013, 10:37:10 PM7/20/13
to urlrewr...@googlegroups.com
Hi Goldie,

It no problem. If i use www.mydomain.com/Album/1 to rewite to www.mydomain.com/Media/Album.aspx?aid=1 , then i get query string ulr by Request.Url.ToString() method, it will return me: www.mydomain.com/Album/1?aid=1

Note: id=1 it is normal string in rewrite config (you can write any word, but not "?"), it's not asp.net parameter, because not after the "?"

Thanks your idea but it not fix my problem.

Goldie

unread,
Jul 21, 2013, 9:53:48 AM7/21/13
to urlrewr...@googlegroups.com
The Rewriter takes the Human readable form "http://www.domain.com/Album/1" and transforms it to actual Web Server parsed form "http://www.domain.com/Album.aspx?id=1".  Once it is in the true form (Web Server), any of the Request properties, that relate to URL/URI will be useable.
Reply all
Reply to author
Forward
0 new messages