Jump to content

ASP.NET Security - IsAuthenticated

Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...