在我的ASP.Net网站中,我有以下代码,我可以在整个网站上使用。
如何在ASP.Net MVC2中执行相同的操作?什么是MVC中的basepage相当于
public class BasePage : Page
{
public BasePage()
{
this.PreInit += new EventHandler(BasePage_PreInit);
}
/// <summary>Every page executes this function before anything else.</summary>
protected void BasePage_PreInit(object sender, EventArgs e)
{
// Apply Theme to page
Page.Theme = "Default";
}
public bool IsSiteAdmin(string userName)
{
if (System.Web.Security.Roles.IsUserInRole(userName, "SiteAdmin1"))
return true;
return false;
}
}
使用OnActionExecuting滤波器的替代方法是使主题属性延迟加载,使得其自身初始化(可能是从会话,或路由数据,或其他)在第一次使用。我发现这种方法更容易理解,因为从属性定义中可以清楚地看到值来自何处,并且在测试过程中像使用过滤器一样容易地截取值。 –