kevin.upshaw Posted April 29, 2012 Share Posted April 29, 2012 Hi. Wonder if anyone can help. I am trying to build a website where users can log in to their account, and then place an order for an item, edit their details etc. However, am using the following code upon loading the myAccount.cshtml page: if (WebSecurity.IsAuthenticated == false) { Response.Redirect("~/"); } So that if the user is not logged in it directs them to the home page to then login. However I am finding that even when the user has logged in, as soon as they come away from the My Account area - it logs them out and they then have to log back in. How could I make this so it persistently keeps the user logged in until they manually log out with the button I have created. Thanks. Kevin Link to comment Share on other sites More sharing options...
justsomeguy Posted April 30, 2012 Share Posted April 30, 2012 How do they get logged out? Are the two areas on different subdomains or something like that? Link to comment Share on other sites More sharing options...
kevin.upshaw Posted April 30, 2012 Author Share Posted April 30, 2012 Forgive me, am new to ASP.NET, am doing a web design module in my degree and am trying to build a website from scratch for my assignment. I had (perhaps foolishly) included the code: <a href="@{WebSecurity.Logout();}"> In a breadcrumb style bar to which (in my thinking) the user could then click the link which would log them out, however - from what you just said I have realised that every time the page is rendered the user will then be logged out - I was staring at the screen far to long yesterday. What would you suggest the best way to allow someone to logout? Thanks. Kevin Link to comment Share on other sites More sharing options...
justsomeguy Posted April 30, 2012 Share Posted April 30, 2012 Write a link to logout.aspx or something like that, and have that file use the WebSecurity.Logout method. Link to comment Share on other sites More sharing options...
kevin.upshaw Posted May 3, 2012 Author Share Posted May 3, 2012 That's brilliant, worked a treat. Cheers. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now