Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-26-2012, 05:04 PM   PM User | #1
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
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 %>
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 10-26-2012, 05:39 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
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 
%>
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 10-26-2012, 08:26 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
DanInMa (10-26-2012)
Old 10-26-2012, 11:53 PM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
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!)
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:45 AM.


Advertisement
Log in to turn off these ads.