why Page is not available under Razor
I move aspx views to razor. Some things are not worked (null r开发者_如何学运维eference) :
Page.RouteData.Values["IdeaType"]
Page.User.IsInRole("Admin")
I have to change to:
ViewContext.RequestContext.RouteData.Values["IdeaType"]
ViewContext.RequestContext.HttpContext.User.IsInRole("Admin")
why? need to import something?
Razor's Page
property returns a page state bag that can pass data between layout pages, content pages, and partial views.
WebForm's Page
property returns your Page
instance (it's inherited from the Control
class).
They're not the same.
In general, WebForms properties and Razor properties are rather different.
Note that Razor pages also have a User
property; you can just write User.IsInRole(...)
.
精彩评论