如何在ASP.NET MVC的Action禁用安全? [英] How to disable security for an Action in ASP.NET MVC?
问题描述
我的要求是,只有在登录页面和注册页面应该从匿名用户访问。
我创建使用默认模板VS2008一个新的ASP.NET MVC项目。
My requirement is that only the login page and the Register page should be accessible from anonymous users. I have created a new ASP.NET MVC project using the default template in VS2008.
之后,我已经启用了安全性增加这部分的web配置:
After that I have enabled security adding this section to the web config:
<authorization>
<deny users="?" />
</authorization>
现在的注册行动是无法访问的,因为启用了安全性。我该怎么办,只为行动禁用安全?
Now the Register Action is not accessible anymore because of the security enabled. How I can do to disable security only for that Action?
感谢
推荐答案
您将要使用授权
属性上的控制器动作,以限制在控制器或动作访问级别:
You will want to use the Authorize
attribute on your controller actions to restrict access at the Controller or Action level:
的http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx
这篇关于如何在ASP.NET MVC的Action禁用安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!