rewriting URL

Discussion in 'ASP .Net' started by Christina, Nov 16, 2006.

  1. Christina

    Christina Guest

    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!!
    Christina, Nov 16, 2006
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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!!
    >
    Mark Fitzpatrick, Nov 16, 2006
    #2
    1. Advertising

  3. Christina

    kferron Guest

    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" <> wrote in message
    > news:...
    > > 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!!
    > >
    kferron, Nov 17, 2006
    #3
  4. Christina

    Christina Guest

    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" <> wrote in message
    > > news:...
    > > > 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!!
    > > >
    Christina, Nov 17, 2006
    #4
  5. Christina

    kferron Guest

    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" <> wrote in message
    > > > news:...
    > > > > 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!!
    > > > >
    kferron, Nov 17, 2006
    #5
  6. Christina

    Christina Guest

    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" <> wrote in message
    > > > > news:...
    > > > > > 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!!
    > > > > >
    Christina, Nov 17, 2006
    #6
  7. Christina

    Christina Guest

    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" <> wrote in message
    > > > > news:...
    > > > > > 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!!
    > > > > >
    Christina, Nov 17, 2006
    #7
  8. Christina

    Christina Guest

    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" <> wrote in message
    > > > > > news:...
    > > > > > > 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!!
    > > > > > >
    Christina, Nov 18, 2006
    #8
  9. 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
    Holger Boskugel, Nov 19, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Juha Borenius

    URL rewriting

    Juha Borenius, Aug 14, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    462
    Colin Young
    Aug 15, 2003
  2. Thedotnetteer
    Replies:
    2
    Views:
    779
    Thedotnetteer
    Nov 27, 2003
  3. sandeep pandit via .NET 247
    Replies:
    0
    Views:
    898
    sandeep pandit via .NET 247
    Apr 28, 2004
  4. Gaurav  Agarwal
    Replies:
    2
    Views:
    717
    Gaurav Agarwal
    Jan 31, 2005
  5. =?Utf-8?B?cmFwaWRkYXRh?=

    url rewriting with no extension in url

    =?Utf-8?B?cmFwaWRkYXRh?=, Nov 1, 2006, in forum: ASP .Net
    Replies:
    8
    Views:
    399
    Flinky Wisty Pomm
    Nov 2, 2006
Loading...

Share This Page