|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help Translating Classic ASP Script to ASP.NET
I'm having problems moving a classic ASP script to ASP.NET. Essentially it checks for a cookie and if it doesn't exist it popups a javascript newsletter signup window and then writes the cookie and sets and expiration 90 days away. Any suggestions on how to translate this from classic ASP to ASP.Net. I attempted it but kept getting errors. Also, what's the best place to put a script like this in a User Control across my pages? <br><div class="msgQuoteWrap"><div class="msgCode"><br><% If Request.Cookies("HWNewsletter") <> "True" Then %> <br><br>Javascript popup window code goes here<br><br><% <br>Response.Cookies("HWNewsletter") = "True" <br>Response.Cookies("HWNewsletter").Expires = Date + 90 <br>end if <br>%></div></div>
|
|
#2
|
|||
|
|||
|
I would probably create a function that returns a boolean value to let you know if you should print out your javascript or not. This is from memory, so you might need to play with it a bit...<div class="msgQuoteWrap"><div class="msgCode"><br>Public Function CheckCookieExist() as Boolean<br> Dim hasCookie as Boolean = False<br> Dim cookieVal as HttpCookie<br> cookieVal = Httpcontext.Current.Request.Cookies("HWNewsletter")<br> If Not cookieVal Is Nothing Then<br> '-- cookie exists...<br> hasCookie = True<br> Else<br> '-- no cookie exists, so set and return false to show popup<br> hasCookie = False<br> Dim sCookie as New HttpCookie("HWNewsletter")<br> sCookie.Values.Add("HWNewsletter", "1")<br> sCookie.Expires = DateAdd(DateInterval.Day, 90, DateTime.Now)<br> HttpContext.Current.Response.AppendCookie(sCookie) <br> End If<br> Return hasCookie<br>End Function<br></div></div><p> </p><p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>
|
|
#3
|
|||
|
|||
|
Thanks, I'll give this a try!
|
|
#4
|
|||
|
|||
|
Is it possible to do output caching but also check for cookies on a page? When output caching is enabled, the cookie check script will only run when the page has expired. Am I understanding that right?
|
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > Help Translating Classic ASP Script to ASP.NET |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|