c# - Cookies dont work when page gets reloaded asp.net -


When my login button is clicked, it should create this cookie

  Secure zero Page_load (item sender, event events e) {if (! Ipostback) {HTTP cookie tester = new HTTP cookie ("User Inc."); Testcookie.Expires = DateTime.Now.AddDays (1); Response.Cookies.Add (testCookie); }} Safe Wide Navigation MenuUyUtemClick (Object Sender, MenuEventErgus E) {} Protected Zero Logon 1_AntinateTicket (Object Sender, OrientateEvent Events E) {} Safe Wide Log Inview 1_View Changed (Object Sender, EventAGRS E) {} Safe Wide BTNLog InCall (Object Sender, EventAgps E) {ifEmailEmailText == "example@hotmail.com" and & Textbox1.Text == "qwerty1") {HTTP cookie cookie = request. Cookies ["User Information"]; Cookie ["username"] = UserEmail.Text; Cookie ["boolean check"] = "true"; Response.Cookies.Add (cookie); Response.Redirect (Request.RawUrl); } else {ErrorMessage.Visible = true; ErrorEmail.Visible = true; Error password. Visible = true; }}}   

}

Then the above cookie must be used to set the master page of the site.

  Public Partial Class _Default: System.Web.UI.Page {Boolean Found = False; Secure Zero Page_load (Object Sender, EventErgus E) {} SafeWind Page_ PreInit (Object Sender, EventEurge E) {String Sign InIncanc = "Fotal"; HttpCookie Cookie = Request Cookies ["userInfo"]; If (cookie! = Null) {sign inchurch = cookie ["boolean check"]; } Try {if (signed check! = "True") it. Page. Masters page file = "~ / Site.Master"; And these.page.masterpagefile = "~ / logged in. Master"; } Catch (Exception Pre) {}}}}   

This code works to switch to another master page, but when the page is repaired, even so That back in itself, it first switches back to the master page. How to change that when you are logged in, you always display the second master page.

Add days or end of cookies

  http cookies my cookie = New HTTP cookie ("User Settings"); myCookie ["font"] = "aerial"; myCookie ["color"] = "blue"; MyCookie.Expires = DateTime.Now.AddDays (1d); Response.Cookies.Add (myCookie);   

Give it a try and see that it works for you.

URL for your reference

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -