내 ASP.Net 웹 사이트에는 사이트 전체를 사용할 수있는 다음 코드가 있습니다.
ASP.Net MVC2에서 어떻게 동일한 작업을 수행합니까?MVC의 기본 페이지는 무엇입니까
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 필터를 사용하는 대신, 테마 속성 지연 로딩하는 것이다. 이 접근법은 값이 나오는 속성 정의에서 매우 분명하기 때문에 이해하기 쉽습니다. 또한 필터와 마찬가지로 테스트 중에 값을 스텁링하는 것만 큼 쉽습니다. –