PageBase.cs 981 B

12345678910111213141516171819202122232425262728293031
  1. using AspNetCoreDefaultHost.Configs;
  2. using AspNetCoreSsrTemplateEngine.DataBoundContext;
  3. using Microsoft.AspNetCore.Http;
  4. using System.Threading.Tasks;
  5. namespace AspNetCoreDefaultHost.Pages.Basic
  6. {
  7. public abstract class PageBase : ComponentBase, IPage
  8. {
  9. protected virtual IReadonlyDataBindContext PageDataBindContext { get; set; } = HostConfig.RootDataBindContext;
  10. protected virtual ComponentBase MasterPage { get; set; }
  11. public virtual async Task ProcessRequestAsync(HttpContext context)
  12. {
  13. context.Response.ContentType = "text/html";
  14. PreRender();
  15. if (null != MasterPage) await MasterPage.RenderAsync(PageDataBindContext, context.Response.Body);
  16. else await RenderAsync(PageDataBindContext, context.Response.Body);
  17. PostRender();
  18. }
  19. protected virtual void PreRender()
  20. {
  21. }
  22. protected virtual void PostRender()
  23. {
  24. }
  25. }
  26. }