asp.net我可以强制每个页面从基本页继承?还应该有的这个逻辑是我的母版页? [英] asp.net Can I force every page to inherit from a base page? Also should some of this logic be in my master page?
问题描述
我有了一个基本页面的Web应用程序。
I have a web app that has a base page.
每个页面需要从这个基地页继承,因为它包含的属性,他们都需要以及处理与登录权限。
Each page needs to inherit from this base page as it contains properties they all need as well as dealing with the login rights.
我的基本页面有一些属性,例如:IsRole1,IsRole2,currentUserID,Role1Allowed,Role2Allowed
My base page has some properties, eg: IsRole1, IsRole2, currentUserID, Role1Allowed, Role2Allowed.
在我设置的属性每个页面的initRole1Allowed和Role2Allowed
On the init of each page I set the properties "Role1Allowed" and "Role2Allowed"
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Role1Allowed = True
Role2Allowed= False
End Sub
本的BasePage那么如果用户需要重定向决定。
The basepage then decides if the user needs redirecting.
样品code所以不正是将是,错误给出了想法
'Sample code so not exactly what is going to be, bug gives the idea
Protected Overridable Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Role1Allowed And Not Role1 Then
'Redirect somewhere
End If
End Sub
如果他们需要什么在它的页面必须超越这个页面加载,但要确保他们首先调用基页面加载。
The page then must override this pageload if they need anything else in it, but making sure they call the base pageload first.
Protected Overrides Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MyBase.Page_Load(sender, e)
If Not IsPostBack Then
BindGrid()
End If
End Sub
的其它性质(IsRole1,IsRole,currentUserID)也由页面访问,以便可以决定,如果某些事情需要基于用户做着
The other properties (IsRole1, IsRole, currentUserID) are also accessible by the page so it can be decided if certain things need doing based on the user.
(我希望这是有道理的)
(I hope this makes sense)
好了,所以我有2个问题
Ok so I have 2 questions
- 如果这个功能是在基本页面或应该以某种方式在主,如果是这样我将如何获得所有属性,如果它是什么?
- 由于有多人在做这个项目,创造了一些被遗忘覆盖,当它从该的BasePage继承,或调用基页面加载页面。
有没有什么办法来强迫他们这样做吗?
感谢您的帮助。
BEX
推荐答案
在阅读完之后,我发现这一点:的链接到网络配置的变化
应该是完美的你。
After reading this, i found this: link to web config changes Should be perfect for ya.
这篇关于asp.net我可以强制每个页面从基本页继承?还应该有的这个逻辑是我的母版页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!