Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Logout on refresh (asp.net)

Hey guys,

New coder here. Been away from it for a few months and even then had minimal experience with asp.net/c#. I'm helping my local gaming community by fixing some of their functionality issues on their website. I've been doing a lot of research and ran lots of tests on the code that I had changed but I just want to scream. So, I came here because I'm confident this problem is not nearly what I'm making it out to be.

Problem: When a person is paying cash the day of the event and has to create a username, the admin has to refresh the table in order for the name to populate in the table so we can select "cash paid". When it gets refreshed, the admin is logged out and has to log back in then the table is also updated so we can select "cash paid".

Code
protected void CheckoutButton_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            Session.Abandon();

            //Clear Authentication Cookie.
            HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
            cookie1.Expires = DateTime.Now.AddYears(-1);
            Response.Cookies.Add(cookie1);

            // clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
            HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
            cookie2.Expires = DateTime.Now.AddYears(-1);
            Response.Cookies.Add(cookie2);
            Response.Redirect("~/Checkin.aspx");
            //FormsAuthentication.RedirectToLoginPage();
        }

I feel the authentication cookie should not be cleared but the session one should be. Any advice is much appreciated. Apologies if this is indeed a super easy fix.
(Jan 14, 2017 08:03 PM)Aseeraa Wrote:  When it gets refreshed, the admin is logged out and has to log back in then the table is also updated so we can select "cash paid".

You should just check the session see if the cookie is matching (admin account check or however it is you are/want to dp it) not removing any cookie, thats not practical at all to log out for refreshing data.

You just check if its a legit user/admin thats logged in, refresh the data on the page => done. Idk if i am misunderstanding something here or not 😧

Hope it helps.

🤝


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by iconv32Jul 10, 2022 12:18 PM 0 214 Jul 10, 2022 12:18 PM
Last Post: iconv32
[C#] by Jake JohnsonDec 10, 2020 09:25 AM 3 304 Dec 10, 2020 09:25 AM
Last Post: Xamarin
[C#] by Jake JohnsonOct 28, 2020 10:15 AM 1 192 Oct 28, 2020 10:15 AM
Last Post: itcorp