By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

rewriting URL

P: n/a
Hiya!!

I am trying to do something really simple here..

I have a link, clicking on which leads to a page say MyPage.aspx.
There's a query string also passed to it. Hence its :

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

Now, I dont want this to be displayed to the user. I want something
like:
http://machineName/projName/MyPage,
on anything, but NOT the querystring.

I tried the below code :

1)
In global.asax.vb :

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim strCurrentPath As String
Dim strCustomPath As String

strCurrentPath = Request.Path
strCurrentPath = strCurrentPath.ToLower()
If (strCurrentPath.IndexOf("/MyPage.aspx") -1) Then

strCustomPath = "http://machineName/projName/MyPage"

Context.RewritePath(strCustomPath)
End If

The above code gives an error : Invalid file name for monitoring..

2)
In page_load of mypage.aspx
Context.RewritePath(strCustomPath)

Still the same error :-(

Any pointers ?

Thanks!!

Nov 16 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
ASP.Net 2.0 has this built right in. What you'll want is the urlmapping
section of the config file (if I remember correctly). There's also a really
nice utility at http://www.urlrewriting.net that can do more extensive
mapping with regular expressions.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hiya!!

I am trying to do something really simple here..

I have a link, clicking on which leads to a page say MyPage.aspx.
There's a query string also passed to it. Hence its :

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

Now, I dont want this to be displayed to the user. I want something
like:
http://machineName/projName/MyPage,
on anything, but NOT the querystring.

I tried the below code :

1)
In global.asax.vb :

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim strCurrentPath As String
Dim strCustomPath As String

strCurrentPath = Request.Path
strCurrentPath = strCurrentPath.ToLower()
If (strCurrentPath.IndexOf("/MyPage.aspx") -1) Then

strCustomPath = "http://machineName/projName/MyPage"

Context.RewritePath(strCustomPath)
End If

The above code gives an error : Invalid file name for monitoring..

2)
In page_load of mypage.aspx
Context.RewritePath(strCustomPath)

Still the same error :-(

Any pointers ?

Thanks!!

Nov 16 '06 #2

P: n/a
I don't think this is what she is asking, although urlmapping would
work for say, http://machineName/projName/MyPage.aspx (if you want
asp.net to handle files with no extension, this is a webserver setting
that has to handle the request first), you could map:
http://machineName/projName/MyPage.aspx

to

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

you could not say, have MyPage.aspx also map to:

http://machineName/projName/MyPage.aspx?myQueryStr=1234

so the issue is moot.

Basically you could

a) have a different url mapping for every possible querystring
possibility (eg. MyPageAbcd.aspx -MyPage.aspx?myQueryStr=abcd)

b) create a httphandler that takes advantage of Request.RewritePath()
that allows you to parse a request and rewrite the url to the correct
querystring (eg. http://machineName/projName/MyPage/abcd.aspx) and then
map that in your handler to ->
http://machineName/projName/MyPage.aspx?myQueryStr=abcd by parsing
http://machineName/projName/<aspxpage>/<querystringvalue>.aspx. This
option is really limitless, as long as you know how to parse the
incoming url.

c) your third option isn't as flexible, but requires no url rewriting,
and that is to post all of your data instead of passing in querystring

~kcf
Mark Fitzpatrick wrote:
ASP.Net 2.0 has this built right in. What you'll want is the urlmapping
section of the config file (if I remember correctly). There's also a really
nice utility at http://www.urlrewriting.net that can do more extensive
mapping with regular expressions.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hiya!!

I am trying to do something really simple here..

I have a link, clicking on which leads to a page say MyPage.aspx.
There's a query string also passed to it. Hence its :

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

Now, I dont want this to be displayed to the user. I want something
like:
http://machineName/projName/MyPage,
on anything, but NOT the querystring.

I tried the below code :

1)
In global.asax.vb :

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim strCurrentPath As String
Dim strCustomPath As String

strCurrentPath = Request.Path
strCurrentPath = strCurrentPath.ToLower()
If (strCurrentPath.IndexOf("/MyPage.aspx") -1) Then

strCustomPath = "http://machineName/projName/MyPage"

Context.RewritePath(strCustomPath)
End If

The above code gives an error : Invalid file name for monitoring..

2)
In page_load of mypage.aspx
Context.RewritePath(strCustomPath)

Still the same error :-(

Any pointers ?

Thanks!!
Nov 17 '06 #3

P: n/a
Hmmm.... doesnt seem to be as simple as I thought it would be.

As kferron said, I'll focus on : httphandler -rewrite path ->
parsing..

Meanwhile, if anybody has a link which shows how to do this, or a code
snippet, that would be great!!

Thanks for the help!!
kferron wrote:
I don't think this is what she is asking, although urlmapping would
work for say, http://machineName/projName/MyPage.aspx (if you want
asp.net to handle files with no extension, this is a webserver setting
that has to handle the request first), you could map:
http://machineName/projName/MyPage.aspx

to

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

you could not say, have MyPage.aspx also map to:

http://machineName/projName/MyPage.aspx?myQueryStr=1234

so the issue is moot.

Basically you could

a) have a different url mapping for every possible querystring
possibility (eg. MyPageAbcd.aspx -MyPage.aspx?myQueryStr=abcd)

b) create a httphandler that takes advantage of Request.RewritePath()
that allows you to parse a request and rewrite the url to the correct
querystring (eg. http://machineName/projName/MyPage/abcd.aspx) and then
map that in your handler to ->
http://machineName/projName/MyPage.aspx?myQueryStr=abcd by parsing
http://machineName/projName/<aspxpage>/<querystringvalue>.aspx. This
option is really limitless, as long as you know how to parse the
incoming url.

c) your third option isn't as flexible, but requires no url rewriting,
and that is to post all of your data instead of passing in querystring

~kcf
Mark Fitzpatrick wrote:
ASP.Net 2.0 has this built right in. What you'll want is the urlmapping
section of the config file (if I remember correctly). There's also a really
nice utility at http://www.urlrewriting.net that can do more extensive
mapping with regular expressions.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hiya!!
>
I am trying to do something really simple here..
>
I have a link, clicking on which leads to a page say MyPage.aspx.
There's a query string also passed to it. Hence its :
>
http://machineName/projName/MyPage.aspx?myQueryStr=abcd
>
Now, I dont want this to be displayed to the user. I want something
like:
http://machineName/projName/MyPage,
on anything, but NOT the querystring.
>
I tried the below code :
>
1)
In global.asax.vb :
>
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim strCurrentPath As String
Dim strCustomPath As String
>
strCurrentPath = Request.Path
strCurrentPath = strCurrentPath.ToLower()
If (strCurrentPath.IndexOf("/MyPage.aspx") -1) Then
>
strCustomPath = "http://machineName/projName/MyPage"
>
Context.RewritePath(strCustomPath)
End If
>
The above code gives an error : Invalid file name for monitoring..
>
2)
In page_load of mypage.aspx
Context.RewritePath(strCustomPath)
>
Still the same error :-(
>
Any pointers ?
>
Thanks!!
>
Nov 17 '06 #4

P: n/a

this is a pretty cool approach in my opinion Christina

http://www.codeproject.com/aspnet/urlrewriter.asp

Christina wrote:
Hmmm.... doesnt seem to be as simple as I thought it would be.

As kferron said, I'll focus on : httphandler -rewrite path ->
parsing..

Meanwhile, if anybody has a link which shows how to do this, or a code
snippet, that would be great!!

Thanks for the help!!
kferron wrote:
I don't think this is what she is asking, although urlmapping would
work for say, http://machineName/projName/MyPage.aspx (if you want
asp.net to handle files with no extension, this is a webserver setting
that has to handle the request first), you could map:
http://machineName/projName/MyPage.aspx

to

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

you could not say, have MyPage.aspx also map to:

http://machineName/projName/MyPage.aspx?myQueryStr=1234

so the issue is moot.

Basically you could

a) have a different url mapping for every possible querystring
possibility (eg. MyPageAbcd.aspx -MyPage.aspx?myQueryStr=abcd)

b) create a httphandler that takes advantage of Request.RewritePath()
that allows you to parse a request and rewrite the url to the correct
querystring (eg. http://machineName/projName/MyPage/abcd.aspx) and then
map that in your handler to ->
http://machineName/projName/MyPage.aspx?myQueryStr=abcd by parsing
http://machineName/projName/<aspxpage>/<querystringvalue>.aspx. This
option is really limitless, as long as you know how to parse the
incoming url.

c) your third option isn't as flexible, but requires no url rewriting,
and that is to post all of your data instead of passing in querystring

~kcf
Mark Fitzpatrick wrote:
ASP.Net 2.0 has this built right in. What you'll want is the urlmapping
section of the config file (if I remember correctly). There's also a really
nice utility at http://www.urlrewriting.net that can do more extensive
mapping with regular expressions.
>
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
>
"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hiya!!

I am trying to do something really simple here..

I have a link, clicking on which leads to a page say MyPage.aspx.
There's a query string also passed to it. Hence its :

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

Now, I dont want this to be displayed to the user. I want something
like:
http://machineName/projName/MyPage,
on anything, but NOT the querystring.

I tried the below code :

1)
In global.asax.vb :

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim strCurrentPath As String
Dim strCustomPath As String

strCurrentPath = Request.Path
strCurrentPath = strCurrentPath.ToLower()
If (strCurrentPath.IndexOf("/MyPage.aspx") -1) Then

strCustomPath = "http://machineName/projName/MyPage"

Context.RewritePath(strCustomPath)
End If

The above code gives an error : Invalid file name for monitoring..

2)
In page_load of mypage.aspx
Context.RewritePath(strCustomPath)

Still the same error :-(

Any pointers ?

Thanks!!
Nov 17 '06 #5

P: n/a
Thanks !!
I will implement it and let you know how'd it go..
kferron wrote:
this is a pretty cool approach in my opinion Christina

http://www.codeproject.com/aspnet/urlrewriter.asp

Christina wrote:
Hmmm.... doesnt seem to be as simple as I thought it would be.

As kferron said, I'll focus on : httphandler -rewrite path ->
parsing..

Meanwhile, if anybody has a link which shows how to do this, or a code
snippet, that would be great!!

Thanks for the help!!
kferron wrote:
I don't think this is what she is asking, although urlmapping would
work for say, http://machineName/projName/MyPage.aspx (if you want
asp.net to handle files with no extension, this is a webserver setting
that has to handle the request first), you could map:
>
>
http://machineName/projName/MyPage.aspx
>
to
>
http://machineName/projName/MyPage.aspx?myQueryStr=abcd
>
you could not say, have MyPage.aspx also map to:
>
http://machineName/projName/MyPage.aspx?myQueryStr=1234
>
so the issue is moot.
>
Basically you could
>
a) have a different url mapping for every possible querystring
possibility (eg. MyPageAbcd.aspx -MyPage.aspx?myQueryStr=abcd)
>
b) create a httphandler that takes advantage of Request.RewritePath()
that allows you to parse a request and rewrite the url to the correct
querystring (eg. http://machineName/projName/MyPage/abcd.aspx) and then
map that in your handler to ->
http://machineName/projName/MyPage.aspx?myQueryStr=abcd by parsing
http://machineName/projName/<aspxpage>/<querystringvalue>.aspx. This
option is really limitless, as long as you know how to parse the
incoming url.
>
c) your third option isn't as flexible, but requires no url rewriting,
and that is to post all of your data instead of passing in querystring
>
>
>
~kcf
>
>
Mark Fitzpatrick wrote:
ASP.Net 2.0 has this built right in. What you'll want is the urlmapping
section of the config file (if I remember correctly). There's also a really
nice utility at http://www.urlrewriting.net that can do more extensive
mapping with regular expressions.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hiya!!
>
I am trying to do something really simple here..
>
I have a link, clicking on which leads to a page say MyPage.aspx.
There's a query string also passed to it. Hence its :
>
http://machineName/projName/MyPage.aspx?myQueryStr=abcd
>
Now, I dont want this to be displayed to the user. I want something
like:
http://machineName/projName/MyPage,
on anything, but NOT the querystring.
>
I tried the below code :
>
1)
In global.asax.vb :
>
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim strCurrentPath As String
Dim strCustomPath As String
>
strCurrentPath = Request.Path
strCurrentPath = strCurrentPath.ToLower()
If (strCurrentPath.IndexOf("/MyPage.aspx") -1) Then
>
strCustomPath = "http://machineName/projName/MyPage"
>
Context.RewritePath(strCustomPath)
End If
>
The above code gives an error : Invalid file name for monitoring..
>
2)
In page_load of mypage.aspx
Context.RewritePath(strCustomPath)
>
Still the same error :-(
>
Any pointers ?
>
Thanks!!
>
Nov 17 '06 #6

P: n/a
Hey, I would like to consider the third approach also:
post all of your data instead of passing in querystring

Can I get a pointer to that too..

Thanx!!
kferron wrote:
this is a pretty cool approach in my opinion Christina

http://www.codeproject.com/aspnet/urlrewriter.asp

Christina wrote:
Hmmm.... doesnt seem to be as simple as I thought it would be.

As kferron said, I'll focus on : httphandler -rewrite path ->
parsing..

Meanwhile, if anybody has a link which shows how to do this, or a code
snippet, that would be great!!

Thanks for the help!!
kferron wrote:
I don't think this is what she is asking, although urlmapping would
work for say, http://machineName/projName/MyPage.aspx (if you want
asp.net to handle files with no extension, this is a webserver setting
that has to handle the request first), you could map:
>
>
http://machineName/projName/MyPage.aspx
>
to
>
http://machineName/projName/MyPage.aspx?myQueryStr=abcd
>
you could not say, have MyPage.aspx also map to:
>
http://machineName/projName/MyPage.aspx?myQueryStr=1234
>
so the issue is moot.
>
Basically you could
>
a) have a different url mapping for every possible querystring
possibility (eg. MyPageAbcd.aspx -MyPage.aspx?myQueryStr=abcd)
>
b) create a httphandler that takes advantage of Request.RewritePath()
that allows you to parse a request and rewrite the url to the correct
querystring (eg. http://machineName/projName/MyPage/abcd.aspx) and then
map that in your handler to ->
http://machineName/projName/MyPage.aspx?myQueryStr=abcd by parsing
http://machineName/projName/<aspxpage>/<querystringvalue>.aspx. This
option is really limitless, as long as you know how to parse the
incoming url.
>
c) your third option isn't as flexible, but requires no url rewriting,
and that is to post all of your data instead of passing in querystring
>
>
>
~kcf
>
>
Mark Fitzpatrick wrote:
ASP.Net 2.0 has this built right in. What you'll want is the urlmapping
section of the config file (if I remember correctly). There's also a really
nice utility at http://www.urlrewriting.net that can do more extensive
mapping with regular expressions.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hiya!!
>
I am trying to do something really simple here..
>
I have a link, clicking on which leads to a page say MyPage.aspx.
There's a query string also passed to it. Hence its :
>
http://machineName/projName/MyPage.aspx?myQueryStr=abcd
>
Now, I dont want this to be displayed to the user. I want something
like:
http://machineName/projName/MyPage,
on anything, but NOT the querystring.
>
I tried the below code :
>
1)
In global.asax.vb :
>
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim strCurrentPath As String
Dim strCustomPath As String
>
strCurrentPath = Request.Path
strCurrentPath = strCurrentPath.ToLower()
If (strCurrentPath.IndexOf("/MyPage.aspx") -1) Then
>
strCustomPath = "http://machineName/projName/MyPage"
>
Context.RewritePath(strCustomPath)
End If
>
The above code gives an error : Invalid file name for monitoring..
>
2)
In page_load of mypage.aspx
Context.RewritePath(strCustomPath)
>
Still the same error :-(
>
Any pointers ?
>
Thanks!!
>
Nov 17 '06 #7

P: n/a
I tried to used HTTPModule:

In the Application_BeginRequest, after checkin the URL, ie if its
/myFolder/URL.aspx, then i am using
HttpContext.Current.RewritePath("/myFolder/newURL.aspx") to rewrite the
URL.

Now, this is the result:
I type http://MachineName/myFolder/URL.apx,
it displays the page - newURL.aspx (but in the addressbar, its
http://MachineName/myFolder/URL.apx).

I wanted it to be other way round, ie
I type http://MachineName/myFolder/URL.apx,
it displays the page - URL.aspx (but changes the url in the addressbar
to - http://MachineName/myFolder/newURL.apx).

The reason is, my orignal link has a querystring attached to it. Now I
dont want the user to see the query string. So I want the page to be
displayed as it would have (with the querystring), but want to display
the URL without the querystring. I wanted to rewrite just my Url (in
the addressbar) to the same url(but without query string).

Any idea ??

Thanks!!

Christina wrote:
Hey, I would like to consider the third approach also:
post all of your data instead of passing in querystring

Can I get a pointer to that too..

Thanx!!
kferron wrote:
this is a pretty cool approach in my opinion Christina

http://www.codeproject.com/aspnet/urlrewriter.asp

Christina wrote:
Hmmm.... doesnt seem to be as simple as I thought it would be.
>
As kferron said, I'll focus on : httphandler -rewrite path ->
parsing..
>
Meanwhile, if anybody has a link which shows how to do this, or a code
snippet, that would be great!!
>
Thanks for the help!!
>
>
kferron wrote:
I don't think this is what she is asking, although urlmapping would
work for say, http://machineName/projName/MyPage.aspx (if you want
asp.net to handle files with no extension, this is a webserver setting
that has to handle the request first), you could map:


http://machineName/projName/MyPage.aspx

to

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

you could not say, have MyPage.aspx also map to:

http://machineName/projName/MyPage.aspx?myQueryStr=1234

so the issue is moot.

Basically you could

a) have a different url mapping for every possible querystring
possibility (eg. MyPageAbcd.aspx -MyPage.aspx?myQueryStr=abcd)

b) create a httphandler that takes advantage of Request.RewritePath()
that allows you to parse a request and rewrite the url to the correct
querystring (eg. http://machineName/projName/MyPage/abcd.aspx) and then
map that in your handler to ->
http://machineName/projName/MyPage.aspx?myQueryStr=abcd by parsing
http://machineName/projName/<aspxpage>/<querystringvalue>.aspx. This
option is really limitless, as long as you know how to parse the
incoming url.

c) your third option isn't as flexible, but requires no url rewriting,
and that is to post all of your data instead of passing in querystring



~kcf


Mark Fitzpatrick wrote:
ASP.Net 2.0 has this built right in. What you'll want is the urlmapping
section of the config file (if I remember correctly). There's also a really
nice utility at http://www.urlrewriting.net that can do more extensive
mapping with regular expressions.
>
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
>
"Christina" <ch*********@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hiya!!

I am trying to do something really simple here..

I have a link, clicking on which leads to a page say MyPage.aspx.
There's a query string also passed to it. Hence its :

http://machineName/projName/MyPage.aspx?myQueryStr=abcd

Now, I dont want this to be displayed to the user. I want something
like:
http://machineName/projName/MyPage,
on anything, but NOT the querystring.

I tried the below code :

1)
In global.asax.vb :

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim strCurrentPath As String
Dim strCustomPath As String

strCurrentPath = Request.Path
strCurrentPath = strCurrentPath.ToLower()
If (strCurrentPath.IndexOf("/MyPage.aspx") -1) Then

strCustomPath = "http://machineName/projName/MyPage"

Context.RewritePath(strCustomPath)
End If

The above code gives an error : Invalid file name for monitoring..

2)
In page_load of mypage.aspx
Context.RewritePath(strCustomPath)

Still the same error :-(

Any pointers ?

Thanks!!
Nov 18 '06 #8

P: n/a
Hello Christina
In the Application_BeginRequest, after checkin the URL, ie if its
/myFolder/URL.aspx, then i am using
HttpContext.Current.RewritePath("/myFolder/newURL.aspx") to rewrite the
URL.

Now, this is the result:
I type http://MachineName/myFolder/URL.apx,
it displays the page - newURL.aspx (but in the addressbar, its
http://MachineName/myFolder/URL.apx).

I wanted it to be other way round, ie
I type http://MachineName/myFolder/URL.apx,
it displays the page - URL.aspx (but changes the url in the addressbar
to - http://MachineName/myFolder/newURL.apx).

The reason is, my orignal link has a querystring attached to it. Now I
dont want the user to see the query string. So I want the page to be
displayed as it would have (with the querystring), but want to display
the URL without the querystring. I wanted to rewrite just my Url (in
the addressbar) to the same url(but without query string).

Any idea ??
put the Query data in you session an make a redirect to the URL you
want and then pick up the Query from your Session.
Regards

Holger
Nov 19 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.