sebnilsson - AspNetSeo.Mvc 0.8.0-CI00018

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

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

Copy to clipboard

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

Copy to clipboard

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

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

nuget AspNetSeo.Mvc  ~> 0.8.0-CI00018
Copy to clipboard

> choco install AspNetSeo.Mvc --version 0.8.0-CI00018 --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.Mvc" -RequiredVersion "0.8.0-CI00018" -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.

  • .NETFramework 4.5
    • AspNetSeo (>= 0.8.0-CI00018)
    • Microsoft.AspNet.Mvc (>= 5.0.0)
  • .NETFramework 4.5: 4.5.0.0

                        
Assembly Assembly hash Match
/lib/net45/aspnetseo.mvc.dll 50e0439b34ee4062996959b842c586971

Owners

sebnilsson

Authors

Sebastian Nilsson

Project URL

https://github.com/sebnilsson/AspNetSeo

License

Unknown

Tags

AspNet Mvc AspNetMvc SEO

Info

77 total downloads
5 downloads for version 0.8.0-CI00018
Download (6.94 KB)
Download legacy symbols (18.8 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
0.8.1 7.29 KB Tue, 15 Jan 2019 11:16:30 GMT 7
0.8.1-CI00026 7.3 KB Mon, 14 Jan 2019 15:49:51 GMT 4
0.8.1-CI00025 6.97 KB Thu, 18 May 2017 17:27:04 GMT 6
0.8.1-CI00024 6.97 KB Thu, 18 May 2017 17:02:56 GMT 6
0.8.1-CI00023 6.95 KB Thu, 18 May 2017 16:47:23 GMT 7
0.8.1-CI00022 6.94 KB Thu, 18 May 2017 16:27:21 GMT 7
0.8.0-CI00021 6.93 KB Thu, 18 May 2017 16:20:54 GMT 6
0.8.0-CI00020 6.94 KB Thu, 18 May 2017 16:11:04 GMT 6
0.8.0-CI00019 6.94 KB Thu, 18 May 2017 16:03:42 GMT 6
0.8.0-CI00018 6.94 KB Thu, 18 May 2017 15:57:48 GMT 5
0.8.0-CI00017 6.93 KB Thu, 18 May 2017 15:30:34 GMT 5
0.8.0-CI00016 6.93 KB Fri, 12 May 2017 15:16:36 GMT 6
0.8.0-CI00015 6.93 KB Fri, 12 May 2017 13:35:53 GMT 6