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 4 of 4
  1. #1
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts

    serve new home page based on variable or no variable

    OK, i havent worked with asp and cookies together before. I have a new page design and an old one. the html is contained in 2 subs, SUB OLDPAGE and SUB NEWPAGE.

    This is what Im trying to do

    - user goes to www.mysite.com/ and gets OLDPAGE by default


    - user goes to www.mysite.come/?nsmc=new . I want to then set a cookie for 30 days storing the cookie "nsmc" as equaling "new" , then user gets NEWPAGE

    - user goes to www.mysite.com/ ( nsmc cookie shoudl now equal new) and serves NEWPAGE


    - user goes to www.mysite.com/?nsmc=old - then set cookie nsmc to "old and serve OLDPAGE

    on subsequent visits to www.mysite.com user will again get OLDPAGE




    ok, so this is what I have


    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <%
    
    IF Request.Querystring("nsmc") = "new" THEN
    Response.Cookies("nsmc")= "new"
    ELSEIF  Request.Querystring("nsmc") = "old" THEN
    Response.Cookies("nsmc")= "old"
    END IF
    Response.Cookies("nsmc").Expires = Date() + 30
    IF Request.Cookies("nsmc") = "new" THEN
    NEWPAGE
    ELSE
    OLDPAGE
    END IF
    
    SUB NEWPAGE
     %>
    <p> this is my new page design</p>
    
    <% 
    END SUB 
    SUB OLDPAGE
    %>
    
    <p>this is my old page<p>
    
    <% END SUB %>

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    ahh nevermind I figured it out. My code was "working" but to do it the way i want I have to prevent client side page caching so I put this at the top of the pages and it works as i wanted now


    Code:
    <% 
        pStr = "private, no-cache, must-revalidate" 
        Response.ExpiresAbsolute = #2000-01-01# 
        Response.AddHeader "pragma", "no-cache" 
        Response.AddHeader "cache-control", pStr 
    %>

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Ummm...no, I don't think that will work.

    You can't use Request.Cookies to get the cookie you JUST SET using Response.Cookies.

    Request.Cookies *ONLY* shows you the cookies that were present at the time the user's HTTP request was made.

    So if the cookies were set to "old" and the query string said "new", then Request.Cookies would still be "old" and the query string would NOT take effect until the next time the user got to the page.

    Try this:
    Code:
    IF Request.Querystring("nsmc") = "new" THEN
         Response.Cookies("nsmc")= "new"
         Response.Cookies("nsmc").Expires = Date() + 30
         NEWPAGE
    ELSEIF  Request.Querystring("nsmc") = "old" THEN
        Response.Cookies("nsmc")= "old"
        Response.Cookies("nsmc").Expires = Date() + 30
        OLDPAGE
    ELSEIF Request.Cookies("nsmc") = "new" THEN
        NEWPAGE
    ELSE
        OLDPAGE
    END IF
    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:

    DanInMa (10-26-2012)

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Ahh I see. Ill have to give that a shot. I ended up using server.transfer, but I wanted to figure out how to do it the way I wanted to do it

    Ill give is a shot on Monday, no wait Tuesday. ( Monday is Sharepoint 2007 to 2010 migration yikes!)


  •  

    Posting Permissions

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