I move aspx views to razor. Some things are not worked (null reference) :
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
Pageproperty returns a page state bag that can pass data between layout pages, content pages, and partial views.WebForm’s
Pageproperty returns yourPageinstance (it’s inherited from theControlclass).They’re not the same.
In general, WebForms properties and Razor properties are rather different.
Note that Razor pages also have a
Userproperty; you can just writeUser.IsInRole(...).