Unable to logout from ASP.NET MVC application using FormsAuthentication.SignOut()

前端 未结 4 1477
心在旅途
心在旅途 2021-01-14 02:56

I am trying to implement Logout Functionality in ASP.NET MVC.

I use Forms Authentication for my project.

This is my Logout code:

FormsAuthen         


        
4条回答
  •  离开以前
    2021-01-14 03:32

    To correctly answer your question, I'd have to know how do you secure your "secure" pages.
    I suspect that you're doing something wrong there.

    A simple call to FormsAuthentication.SignOut() should be enough, as it clears the authentication cookie, thus making the other method calls you make there redundant.

    With ASP.NET MVC, you have to use the AuthorizeAttribute on an action method to disallow non-authenticated visitors to use it. (Meaning: the old way you did it with Web Forms by specifying location tags in Web.config no longer works with MVC.)

    For example, here is a small code snippet from my ForumController class:

    public class ForumController : Controller
    {
        ...
    
        [Authorize]
        public ActionResult CreateReply(int topicId)
        {
            ...
        }
    
        ...
    }
    

提交回复
热议问题