在AspNetCore.Mvc.Razor命名空間中的RazorPage繼承RazorPageBase,並定義的屬性為:
- HttpContext Context 表示當前請求執行的HttpContext
RazorPageBase定義為抽象類,並繼承了接口:IRazorPage
IRazorPage接口定義屬性如下:
- ViewContent ViewContent 獲取或設置渲染視圖的視圖上下文
- IHtmlContent BodyContent 獲取或設置正文內容
- bool IsLayoutBeingRendered 獲取或設置一個標志,該標志確定是否呈現此頁面的布局
- string Path 獲取應用程序頁面的相對路徑
- string Layout 獲取或設置布局頁面的路徑
- IDictionary<string, RenderAsyncDelegate> PreviousSectionWriters 獲取或設置此頁面可以呈現的部分
- IDictionary<string, RenderAsyncDelegate> SectionWriters 獲取此頁面定義的部分
定義的方法 如下:
- Task ExecuteAsync(); 渲染頁面並將輸出寫入Writer
- void EnsureRenderedBodyOrSections(); 驗證是否渲染了PreviousSectionWriters中定義的所有節,或者如果未定義節則渲染了正文
RazorPageBase中除了繼承IRazorPage中的屬性,還有定義的屬性如下:
- DiagnosticSource DiagnosticSource 獲取或設置用於檢測頁面執行情況的DiagnosticSource實例
- HtmlEncoder HtmlEncoder 獲取此RazorPage處理非IHtmlContent C#表達式時要使用的HtmlEncoder
- virtual TextWriter Output 獲取頁面正在將輸出寫入的TextWriter
- ITempDataDictionary TempData 從ViewContext獲取ITempDataDictionary
- virtual ClaimsPrincipal User 獲取當前登錄用戶的ClaimsPrincipal
- object ViewBag 獲取動態視圖數據字典
可以在Razor頁面中可以直接使用的上述定義的屬性,其中RazorPage中的屬性Context為ViewContent中的HttpContext
因此在Razor頁面中要獲取一些信息時,可以直接使用上述屬性進行處理。