PageService - Web Forms Page Object Compatibility
The PageService provides page-level services that mimic ASP.NET Web Forms Page object functionality, enabling programmatic access to page properties like Title, MetaDescription, and MetaKeywords.
Current Page Properties
Title: PageService Sample - BlazorWebFormsComponents
Meta Description: Demonstrates the PageService utility for setting page title and meta tags programmatically in Blazor, similar to ASP.NET Web Forms Page object.
Meta Keywords: blazor, webforms, page service, meta tags, seo, migration
Web Forms Comparison
ASP.NET Web Forms
// In code-behind (.aspx.cs)
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = "My Dynamic Title";
Page.MetaDescription = "Page description for SEO";
Page.MetaKeywords = "blazor, webforms, migration";
}
protected void UpdateButton_Click(object sender, EventArgs e)
{
Page.Title = txtNewTitle.Text;
Page.MetaDescription = txtDescription.Text;
Page.MetaKeywords = txtKeywords.Text;
}Blazor with PageService
@page "/MyPage"
@inject IPageService Page
<BlazorWebFormsComponents.Page />
@code {
protected override void OnInitialized()
{
Page.Title = "My Dynamic Title";
Page.MetaDescription = "Page description for SEO";
Page.MetaKeywords = "blazor, webforms, migration";
}
private void UpdatePageProperties()
{
Page.Title = NewTitle;
Page.MetaDescription = NewMetaDescription;
Page.MetaKeywords = NewMetaKeywords;
}
}Key Features
- Programmatic Title Setting: Set page title dynamically via code, just like
Page.Titlein Web Forms - Meta Tags Support: Set meta description and keywords for SEO, equivalent to
Page.MetaDescriptionandPage.MetaKeywords - Dependency Injection: Available through DI as
IPageService - Event-Based Updates: The
Pagecomponent automatically updates page metadata when properties change - Scoped Service: One instance per request/render cycle, just like Web Forms
Pageobject
Usage Instructions
1. Register the Service (Already done in this sample)
// In Program.cs
builder.Services.AddBlazorWebFormsComponents();
2. Add the Page Component to Your Layout or Page
@inject IPageService Page
<BlazorWebFormsComponents.Page />
3. Set Page Properties Programmatically
@code {
protected override void OnInitialized()
{
Page.Title = "My Page Title";
Page.MetaDescription = "Description for search engines";
Page.MetaKeywords = "keyword1, keyword2, keyword3";
}
private void SomeEventHandler()
{
Page.Title = "Updated Title";
Page.MetaDescription = "Updated description";
}
}
SEO Benefits
The MetaDescription and MetaKeywords properties help improve your site's search engine optimization:
- Meta Description: Appears in search results and social media previews (recommended 150-160 characters)
- Meta Keywords: Helps categorize page content (use relevant, comma-separated keywords)
- Dynamic Updates: Set metadata based on page content, user context, or database values