Asp.net mvc 2 ASP.NET MVC身份验证表单
我需要拒绝所有访问任何控制器,如果他们不登录。 我不希望对每个条目执行此操作:Asp.net mvc 2 ASP.NET MVC身份验证表单,asp.net-mvc-2,authentication,Asp.net Mvc 2,Authentication,我需要拒绝所有访问任何控制器,如果他们不登录。 我不希望对每个条目执行此操作: [Authorize] public ActionResult AnyMethod() { ... } 我尝试过类似的方法,但这被拒绝访问所有内容(css、js等等) 在Web.config中,我只有以下代码: <authentication mode="Forms"> <forms loginUrl="Account/Login"></forms> </auth
[Authorize]
public ActionResult AnyMethod() {
...
}
我尝试过类似的方法,但这被拒绝访问所有内容(css、js等等)
在Web.config中,我只有以下代码:
<authentication mode="Forms">
<forms loginUrl="Account/Login"></forms>
</authentication>
谢谢您可以将Authorize属性放在控制器上——它可以应用于方法和类。这将为您节省大量工作,并且仍然允许您的用户访问静态内容(不受web.config保护)
您可以将Authorize属性放在控制器上——它可以应用于方法和类。这将为您节省大量工作,并且仍然允许您的用户访问静态内容(不受web.config保护)
<authentication mode="Forms">
<forms loginUrl="Account/Login"></forms>
</authentication>
[Authorize]
public class AdminController : Controller
{
...
public ActionResult SetPassword( UserPasswordModel model )
{
...
}
...
}