sebnilsson - AspNetSeo.CoreMvc 0.8.0-CI00016

Helpers for handling the SEO-data for ASP.NET Core MVC web-applications

PM> Install-Package AspNetSeo.CoreMvc -Version 0.8.0-CI00016 -Source https://www.myget.org/F/sebnilsson/api/v3/index.json

Copy to clipboard

> nuget.exe install AspNetSeo.CoreMvc -Version 0.8.0-CI00016 -Source https://www.myget.org/F/sebnilsson/api/v3/index.json

Copy to clipboard

> dotnet add package AspNetSeo.CoreMvc --version 0.8.0-CI00016 --source https://www.myget.org/F/sebnilsson/api/v3/index.json

Copy to clipboard
<PackageReference Include="AspNetSeo.CoreMvc" Version="0.8.0-CI00016" />
Copy to clipboard
source https://www.myget.org/F/sebnilsson/api/v3/index.json

nuget AspNetSeo.CoreMvc  ~> 0.8.0-CI00016
Copy to clipboard

> choco install AspNetSeo.CoreMvc --version 0.8.0-CI00016 --source https://www.myget.org/F/sebnilsson/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "sebnilsson" -SourceLocation "https://www.myget.org/F/sebnilsson/api/v2"
Install-Module -Name "AspNetSeo.CoreMvc" -RequiredVersion "0.8.0-CI00016" -Repository "sebnilsson" -AllowPreRelease
Copy to clipboard

Browse the sources in this package using Visual Studio or WinDbg by configuring the following legacy symbol server URL: https://www.myget.org/F/sebnilsson/symbols/


ASP.NET SEO

Helpers for handling the SEO-data for ASP.NET web-applications.

Provides a SeoHelper-class which is easily accessible in Controllers, Views and through ActionFilterAttributes.

SeoHelper

Properties

The SeoHelper-class exposes multiple properties to get or set multiple SEO-related data:

  • LinkCanonical: Gets or sets the canonical link for web-page.

    • SiteUrl: Gets or sets the main URL for web-site. Used as base for the canonical link.
  • MetaDescription: Gets or sets the meta-description for web-page.

  • MetaKeywords: Gets or sets the meta-keywords for web-page.

  • MetaRobots: Gets or sets meta-robots instructions web-page.

  • OgDescription: Gets or sets the open graph description for web-page. Falls back on value in MetaDescription.

  • OgImage: Gets or sets the open graph image for web-page.

  • OgSiteName: Gets or sets the open graph site-name for web-page. Falls back on value in SiteName.

  • OgTitle: Gets or sets the open graph title for web-page. Falls back on value in PageTitle.

  • OgType: Gets or sets the open graph type for web-page.

  • OgUrl: Gets or sets the open graph URL for web-page. Falls back on value in LinkCanonical.

  • PageTitle: Gets or sets the title for a web-page.

    • SiteName: Gets or sets the name for the web-site. Used as base for DocumentTitle.
  • DocumentTitle: Gets the document-title for a web-page. Combines PageTitle and SiteName.

    • DocumentTitleFormat: Gets or sets the format for the document-title. Default value is {0} - {1}, where {0} is the value from PageTitle and {1} is the value from SiteName.

Methods

  • SetCustomMeta(string key, string value): Add any custom meta-tag.
  • SetMetaRobots(bool index, bool follow): Specify the instructions for robots. Updates the value for MetaRobots.

Notes

LinkCanonical can be set as absolute URL (https://example.com/section/page.html), as a relative URL (/section/page.html) or using ASP.NET's app-relative URL-format (~/section.page.html). Relative URLs will automatically get converted to absolute URLs, either from provided SiteUrl or from the base of the requested URL.

ActionFilterAttributes

The properties exposed by the SeoHelper-class all have corresponding action-filter-attributes are available for Controllers and Controller-actions.

For example, [PageTitle] can be used for an action, if no logic is needed for the value, while [SiteName] can be used for a controller. Using another [SiteName]-attribute on an action will override the one used on the controller.

Examples of attribute-usage:

[SiteName("Website name")]
[SiteUrl("https://production-url.co/")]
public class InfoController : SeoController
{
    [PageTitle("Listing items")]
    [MetaDescription("List of the company's product-items")]
    public ActionResult List()
    {
        var list = GetList();
        
        if (list.Any())
        {
            Seo.PageTitle += $" (Total: {list.Count})";
            Seo.LinkCanonical = "~/pages/list.html";
        }
        else
        {
            Seo.SetMetaRobots(index: false, follow: true);
        }

        return View(model);
    }
}

ASP.NET Core MVC

Configuration

To register the SEO-helper as a service for Dependency Injection you just need to use the framework's provided extension-method in the ConfigureServices method inside Startup.cs:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddSeoHelper();
    }
}

Accessing the SeoHelper-class

With the configured Dependency Injection you can access the SeoHelper-class through constructor-injection or by accessing the RequestServices-object in the HttpContext.

The framework provides an extension-method for IServiceProvider for getting the SeoHelper-instance:

public IActionResult Edit()
{
    var seoHelper = HttpContext.RequestServices.GetSeoHelper();
    // ...
}

Tag Helpers

Tag Helpers are available to render the values set through the SeoHelper-class. They also expose attributes to override or set the values on the fly in the markup.

Examples: <document-title /> renders the combined PageTitle and SiteName. <link-canonical /> renders the canonical URL for the page. <og-url /> renders the set URL for the page and falls back to value used in <link-canonical />.

Individual tags will not be rendered if there is no valid data provided for them, either through the SeoHelper-class or exposed attributes.

Setting default values

To set the webb-application’s default base-title and default base canonical link, which can be overridden if needed, the configuration during registering the service for Dependency Injection can be used:

public void ConfigureServices(IServiceCollection services)
{
    // ...
    services.AddSeoHelper(
        siteName: "Website name",
        siteUrl: "https://production-url.co/");
}

ASP.NET MVC

Support for classic ASP.NET MVC is deprecated.

  • .NETStandard 1.6
    • AspNetSeo (>= 0.8.0-CI00016)
    • Microsoft.AspNetCore.Mvc.Core (>= 1.0.0)
    • Microsoft.AspNetCore.Mvc.Razor (>= 1.0.0)
    • Microsoft.AspNetCore.Mvc.ViewFeatures (>= 1.0.0)
    • NETStandard.Library (>= 1.6.1)
  • .NETStandard 1.6: 1.6.0.0

                        
Assembly Assembly hash Match
/lib/netstandard1.6/aspnetseo.coremvc.dll f7649c835e95409ea600fe26f70ab13f1

Owners

sebnilsson

Authors

Sebastian Nilsson

Project URL

https://github.com/sebnilsson/AspNetSeo

License

Unknown

Info

166 total downloads
8 downloads for version 0.8.0-CI00016
Download (8.58 KB)
Download legacy symbols (25.7 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.1 10.37 KB Thu, 13 Jun 2019 16:04:42 GMT 7
1.0.0 10.36 KB Thu, 13 Jun 2019 15:59:20 GMT 8
0.8.6.1 10.02 KB Tue, 15 Jan 2019 11:16:29 GMT 8
0.8.6 9.9 KB Tue, 15 Jan 2019 09:15:14 GMT 7
0.8.5 9.85 KB Mon, 14 Jan 2019 16:00:08 GMT 10
0.8.1-CI00025 8.87 KB Thu, 18 May 2017 17:27:02 GMT 10
0.8.1-CI00024 8.87 KB Thu, 18 May 2017 17:02:54 GMT 13
0.8.1-CI00023 8.86 KB Thu, 18 May 2017 16:47:21 GMT 14
0.8.1-CI00022 8.84 KB Thu, 18 May 2017 16:27:19 GMT 12
0.8.0 8.61 KB Fri, 12 May 2017 15:10:24 GMT 9
0.8.0-CI00021 8.84 KB Thu, 18 May 2017 16:20:50 GMT 8
0.8.0-CI00020 8.84 KB Thu, 18 May 2017 16:11:02 GMT 10
0.8.0-CI00019 8.84 KB Thu, 18 May 2017 16:03:40 GMT 12
0.8.0-CI00018 8.84 KB Thu, 18 May 2017 15:57:45 GMT 11
0.8.0-CI00017 8.76 KB Thu, 18 May 2017 15:30:32 GMT 8
0.8.0-CI00016 8.58 KB Fri, 12 May 2017 15:16:34 GMT 8
0.8.0-CI00015 8.58 KB Fri, 12 May 2017 13:35:49 GMT 11