可能重复:
Is it possible to create a Logon System with ASP.NET MVC but not use the MembershipProvider?
我正在为我的MVC应用程序创建自定义身份验证模型,但我不确定在哪里实现我的自定义IPrincipal和IIdentity类。我不想在每个请求的Global.asax中执行此操作,因为并非站点中的所有页面都需要身份验证。所以我的问题在哪里?我是否应该在自定义操作过滤器中执行此操作以执行需要用户登录的操作?
我不希望使用会员提供商或表单身份验证,这需要完全自定义和分离。
答案 0 :(得分:0)
您是否考虑为控制器创建单独的基类?
您可以覆盖OnActionExecuting事件以检查用户是否经过身份验证......例如:
Public Class AuthenticatedPageController
Inherits Controller
Protected Overrides Sub OnActionExecuting(ByVal filterContext As ActionExecutingContext)
// Code to check user is authenticated - if not chuck them to the log in page...
End Sub
End Class
然后,用户需要进行身份验证的页面的任何控制器都继承自此类而不是标准控制器类。