自定义 AuthorizeAttribute +自定义 SiteMapProvider 相关吗?
我有一个用于控制器类的自定义 SiteMapProvider
(从数据库填充)和一个自定义 AuthorizeAttribute
(根据 Role_Page 数据库验证当前用户角色+请求的页面)。
我必须实现函数 SiteMapProvider.IsAccessibleToUser(context, node)
。我还必须实现AuthorizeAttribute.AuthorizeCore(context)。
这两个函数有什么关系?没有某种方法可以“归因”SiteMapProvider吗?
一些代码:
编辑:这可能是一个解决方案(在< code>AuthorizeCore())? context
但是是 HttpContextBase
和 IsAccessibleToUser() 只接受
HttpContext
作为参数。
If Not SiteMap.Provider.IsAccessibleToUser(context, SiteMap.CurrentNode) Then
当前代码:
Public Class CustomValidateAuthorization : Inherits AuthorizeAttribute
Public Sub New()
End Sub
Protected Overrides Function AuthorizeCore(ByVal httpContext As System.Web.HttpContextBase) As Boolean
If Not Global.Page.IsAccessibleToUser(httpContext.User) Then
//Exception or redirect (in exception)?
// or return false?
End If
Return True
End Function
End Class
Public Class CustomSiteMapProvider : Inherits StaticSiteMapProvider
Public Overrides Function IsAccessibleToUser(ByVal context As System.Web.HttpContext, ByVal node As System.Web.SiteMapNode) As Boolean
Dim p As New BLL.Page
p.LoadFromSiteMapNode(node)
Return p.IsAccessibleToUser(context.User)
End Function
End Class
I have a custom SiteMapProvider
(populated from database) and a custom AuthorizeAttribute
(validates current users roles + requested page against Role_Page database) for controller classes.
I have to implement the function SiteMapProvider.IsAccessibleToUser(context, node)
. I also have to implement AuthorizeAttribute.AuthorizeCore(context)
.
How are these two functions related? Isn't there some way to 'attribute' the SiteMapProvider?
Some code:
edit: Might this be a solution (inside AuthorizeCore()
)? context
however is HttpContextBase
, and IsAccessibleToUser()
only takes HttpContext
as parameter.
If Not SiteMap.Provider.IsAccessibleToUser(context, SiteMap.CurrentNode) Then
current code:
Public Class CustomValidateAuthorization : Inherits AuthorizeAttribute
Public Sub New()
End Sub
Protected Overrides Function AuthorizeCore(ByVal httpContext As System.Web.HttpContextBase) As Boolean
If Not Global.Page.IsAccessibleToUser(httpContext.User) Then
//Exception or redirect (in exception)?
// or return false?
End If
Return True
End Function
End Class
Public Class CustomSiteMapProvider : Inherits StaticSiteMapProvider
Public Overrides Function IsAccessibleToUser(ByVal context As System.Web.HttpContext, ByVal node As System.Web.SiteMapNode) As Boolean
Dim p As New BLL.Page
p.LoadFromSiteMapNode(node)
Return p.IsAccessibleToUser(context.User)
End Function
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我目前使用默认的 sitemapprovider 两次。
I currently use the default sitemapprovider twice.