Cookies & Redirection

J

Jason Williard

I am trying to implement several website translations. In doing so, a cookie
is set so upon return to the site, they are automatically redirected. If the
language is set to something other than "en" the page should redirect to
/lang/LANGUAGE.

To set the language, there is a drop-down menu, or the user can append
?lang=LANGUAGE to the end of the URL.

Below is the code that I have so far.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++
<script runat="server">
Dim page_path As String

sub Page_Load(Sender as Object, e as EventArgs)

Dim lang As String
Dim setlang As String

if ( Request.Querystring("lang") <> "" )
setlang = Request.Querystring("lang")
end if

if ( Request.Querystring("lang") <> "" )
lang = Request.Querystring("lang")
else if ( Response.Cookies("lang").Value <> "" )
lang = Response.Cookies("lang").Value
end if

Response.Write("Hello")
'Response.Write(lang)
Response.Write(Response.Cookies("lang").Value)


if ( setlang <> "" )
Response.Cookies("lang").Value = lang
Response.Cookies("lang").Expires = DateTime.Now.AddMonths(24)
end if

if ( lang <> "" AND lang <> "en" )
Response.Redirect("/lang/" & lang & Request.ServerVariables("URL"))
end if

end sub
</script>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

What works:
- When the user selects the language, it redirects them to the correct page
and sets the cookie.


The problems thus far:
- When the user returns to the main page, the cookie is deleted and they are
not redirected.


Any assistance would be appreciated.

Thank You,
Jason Williard
 
G

Guest

i think you forget to add cookie

HttpCookie cookie = null;
cookie = HttpContext.Current.Request.Cookies["aaa"];
make the cookie settings and afrer this register the cookie
HttpContext.Current.Response.Cookies.Add(cookie);

Hope Helps
Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top