Forum Moderators: open
Working in ASP.NET 2.0 VB, I need to check for the existence of a cookie on entering a page and if it exists, immediately redirect to another page. This is a validation portal and further down on the page, I am also checking for the value of the cookie (in the page behind code) to see if it has been set, and if not, then setting it(this part is working). In other words, the first time a user hits this page, he has has to check a box before being directed to his destination page. On subsequent visits during the same browser session, the user is sent directly to the destination page.
How can I check for this cookie without loading the page? Do I put a script in the <head> of the page? And what would the code look like. I need some guidance here. Thanks.
protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.Cookies["cookiename"] != null && this.Request.Cookies["cookiename"].Value == "Expectedvalue")
{
this.Response.Redirect("URL TO REDIREC TO");
}
}
[edited by: Ocean10000 at 2:55 am (utc) on Aug. 8, 2008]
Partial Class _Default
Inherits System.Web.UI.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim pass As String
pass = Request.QueryString("new")
If ((Not (Me.Request.Cookies("visited")) Is Nothing) _
AndAlso (Me.Request.Cookies("visited").Value = "true")) Then
Me.Response.Redirect(pass)
End If
End SubProtected Sub SubmitFirstDemo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click
Dim pass As String
pass = Request.QueryString("new")
If (pass = "") Then
Response.Redirect("http://www.rssd.com")
End If
If Page.IsValid() Then
Response.Cookies("visited").Value = "true"
Response.Cookies("visited").Expires = DateTime.MinValue
Response.Redirect(pass)
End If
End SubProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Partial Class _Default
Inherits System.Web.UI.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.Load
Dim pass As String
pass = Request.QueryString("new")
If ((Not (Me.Request.Cookies("visited")) Is Nothing) _
AndAlso (Me.Request.Cookies("visited").Value = "true")) Then
Me.Response.Redirect(pass)
End If
End SubProtected Sub SubmitFirstDemo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click
Dim pass As String
pass = Request.QueryString("new")
If (pass = "") Then
Response.Redirect("http://www.rssd.com")
End If
If Page.IsValid() Then
Response.Cookies("visited").Value = "true"
Response.Cookies("visited").Expires = DateTime.MinValue
Response.Redirect(pass)
End If
End Sub
End Class
Partial Class _Default
Inherits System.Web.UI.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim pass As String
pass = Request.QueryString("new")
If (pass = "") Then
Response.Redirect("http://www.home_page.com")
End If
If ((Not (Me.Request.Cookies("visited")) Is Nothing) _
AndAlso (Me.Request.Cookies("visited").Value = "true")) Then
Me.Response.Redirect(pass)
End If
End SubProtected Sub SubmitFirstDemo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit.Click
Dim pass As String
pass = Request.QueryString("new")
If (pass = "") Then
Response.Redirect("http://www.home_page.com")
End If
If Page.IsValid() Then
Response.Cookies("visited").Value = "true"
Response.Cookies("visited").Expires = DateTime.MinValue
Response.Redirect(pass)
End If
End Sub
End Class
Now to check it on the live server....
Now the next question is how do I integrate the development web.config file with the live one. I think I had better start a new thread. Thanks to all who helped.