使用ASP.NET MVC框架的ActionFilterAttribute属性设计FORM验证

文/Bolik  出处/博客园

如何使用ASP.NET MVC Framework Preview 2 中ActionFilterAttribute属性设计Form用户验证

首先采用BaseController继承Controller以改写保护方法RedirectToAction为公有方法(用以在ActionFilterAttribute属性中使用),本例中扩展了两个属性RequireLoginAttribute 、 RequireRoleAttribute;在RequireLoginAttribute属性过滤中重定向为登录的用户到登录窗户、在 RequireRoleAttribute属性过滤中将非该用户角色的操作显示访问拒绝信息,具体代码如下: 

基础请看 David Hayden [MVP C#] 的 actionfilterattribute-in-asp-net-mvc-framework

This code is my extended ActionFilterAttribute as RequireLoginAttribute and RequireRoleAttribute for form authentication, I just write the BaseController to public the Controller's RedirectToAction function for use it in extended ActionFilterAttribute.

Just for fun with coding!

Code


使用代码如下:

Code




 感谢原创者的辛勤劳动,希望对您有所帮助,转载请注明原出处。
 您可能对 [Asp.Net] 的这些文章也感兴趣:

asp.net中将Excel文件(.xls)绑定到DataGrid
ASP.NET编程中的十大技巧(上)
用Asp.net实现基于XML的留言簿之二
url传递中文的解决方案总结
ASP.NET XMLWeb服务客户端创建Web服务
防止页面被多次提交
分页控件 for vs2003、SQL Server
在Asp.Net中使用SmtpMail发送邮件的方法
ASP.NET中字符串中提取图片的url,并自动下载到本地
ASPX转HTML