Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Internet Explorer Remove querystring from a url on page reload

    Hi all,

    How can I remove querystring from url on page reload?

    Example -
    Code:
    http://www.myURL.com/test.asp?Form=Show&Name=Mike
    The idea is to shop users sharing the URL -
    http://www.myURL.com/test.asp?Form=Show&Name=Mike

    Any help welcomed

    Thanks
    Kind regards,
    Mike Hughes

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    If the user hits the F5 reload button, you can't.

    If you provide the user with a "RELOAD" button you easily can.

    This isn't really an ASP question, as the RELOAD happens client side.

    Hmmm... You *could*, as the first action on the page, do something like this:
    Code:
    <%
    If Trim(Request.QueryString) <> "" Then
        ' optionally save the values from the querystring
        Session("Form") = Request("Form")
        Session("Name") = Request("Form")
        Response.Redirect "test.asp" ' and reload the page without querystring
    End If
    
    ... rest of page ...
    %>
    Now if the user hits F5 reload, the only URL that *can* reload is just the bare "test.asp".

    Will that work for you?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Thanks, it works just a little to good!

    To explain a little more

    I have simple form thats post to save.asp, the form info is saved to a DB. I pick up the values "Download" and "Name" from this page and use the follow codiing to show on the page.

    Code:
    <% If Request.QueryString("PPG_Pack") ="Download" then  %>
        <p>Hi <%=Request.QueryString("Name")%>, thank you for your registration.</p> 
    
    	<p>>> <a href="WORD/2012PPG_AppFrom.doc" target="_new">Please click to download</a></p>
    	<% Else
    What i am trying to do is stop user sharing the URL without registration first.

    Your code, stripts out the query string before I can show the code above.
    Kind regards,
    Mike Hughes

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    ??? So just use <form action="save.asp" method="post">

    And then use Request.Form("...") (or just Request("...") alone) in place of Request.QueryString.

    Now there never will be anything visible in the URL to be shared/copied.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Anyway, if you used the code I showed you:
    Code:
    f Trim(Request.QueryString) <> "" Then
        ' optionally save the values from the querystring
        Session("Form") = Request("Form")
        Session("Name") = Request("Form")
        Session("PPG_Pack") = Request("PPG_Pack")
        Response.Redirect "test.asp" ' and reload the page without querystring
    End If
    
    If Session("PPG_Pack") ="Download" then  
    %>
        <p>Hi <%=Session("Name")%>, thank you for your registration.</p> 
        <p>>> <a href="WORD/2012PPG_AppFrom.doc" target="_new">Please click to download</a></p>
    <% Else
        ...
    See? Once you have stripped the querystring, you use the session values instead.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Or you could do:
    Code:
    <%
    ' save all querystring values as session values
    For Each name In Request.QueryString
        Session(name) = Request.QueryString(name)
    Next
    If Session("PPG_Pack") ="Download" Then
        Response.Redirect "downloadPage.asp"
    Else
       ...
    And the new page, "downloadPage.asp" (or whatever name you use) just does
    Code:
    <%
    ' if a user tries to just use the URL without going through login, don't allow it
    If Session("PPG_Pack") <> "Download" Then Response.Redirect "login.asp"
    %>
    <html><body>
        <p>Hi <%=Session("Name")%>, thank you for your registration.</p> 
        <p>>> <a href="WORD/2012PPG_AppFrom.doc" target="_new">Please click to download</a></p>
    </body></html>
    Or or or ... too many choices, really.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    hughesmi (03-24-2012)

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    UK
    Posts
    302
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Thanks for your direction and help, the last one is a goer!

    Mike
    Kind regards,
    Mike Hughes


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •