How to easily redirect if not authenticated in MVC 3?

前端 未结 4 657
夕颜
夕颜 2021-01-01 14:00

I am brand new to ASP.NET, and I\'m trying to find a way to easily redirect an unauthenticated user from any page on the site to the logon page. I would prefer to not put th

4条回答
  •  情书的邮戳
    2021-01-01 14:13

    Mark your controller with [Authorize] attribute http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx

    See your web.config, by default you should have Forms authentication turned on authentication mode="Forms" http://msdn.microsoft.com/en-us/library/eeyk640h.aspx

    Also look at this question ASP.NET MVC Authorization

    In case if you want to have custom Authorize behavior look here Customizing authorization in ASP.NET MVC

提交回复
热议问题