Onots.AspNetCore.Identity.Anonymous 1.0.1

Middleware for ASP.NET Core to enable the tracking of anonymous users

Based on the initial work by Alessandro Riperi

Install-Package Onots.AspNetCore.Identity.Anonymous -Version 1.0.1
dotnet add package Onots.AspNetCore.Identity.Anonymous --version 1.0.1
<PackageReference Include="Onots.AspNetCore.Identity.Anonymous" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Onots.AspNetCore.Identity.Anonymous --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

AnonymousId

Middleware for ASP.NET Core to enable the tracking of anonymous users

Usage

Register without options:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseAnonymousId();
    ....
}

Register with options:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseAnonymousId(new AnonymousIdCookieOptionsBuilder()
      .SetCustomCookieName("MY_COOKIE_NAME")					// Custom cookie name
      .SetCustomCookieSecurePolicy(CookieSecurePolicy.Always)	// Requires SSL
      .SetCustomCookieTimeout(120)                 				// Custom timeout in seconds
      .SetCustomCookieDomain("www.contoso.com")    				// Custom domain
      .SetCustomCookiePath("/path")               				// Custom path
      .SetCustomHeaderName("AnonymousId"));  			 		// Custom header name
    ....
}

Get AnonymousId:

public class HomeController : Controller
{
  public ViewResult Index()
  {
      IAnonymousIdFeature feature = HttpContext.Features.Get<IAnonymousIdFeature>();
      if (feature != null)
      {
        string anonymousId = feature.AnonymousId;
      }
      ....
  }
}

License

This project is licensed under the terms of the MIT license.

AnonymousId

Middleware for ASP.NET Core to enable the tracking of anonymous users

Usage

Register without options:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseAnonymousId();
    ....
}

Register with options:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseAnonymousId(new AnonymousIdCookieOptionsBuilder()
      .SetCustomCookieName("MY_COOKIE_NAME")					// Custom cookie name
      .SetCustomCookieSecurePolicy(CookieSecurePolicy.Always)	// Requires SSL
      .SetCustomCookieTimeout(120)                 				// Custom timeout in seconds
      .SetCustomCookieDomain("www.contoso.com")    				// Custom domain
      .SetCustomCookiePath("/path")               				// Custom path
      .SetCustomHeaderName("AnonymousId"));  			 		// Custom header name
    ....
}

Get AnonymousId:

public class HomeController : Controller
{
  public ViewResult Index()
  {
      IAnonymousIdFeature feature = HttpContext.Features.Get<IAnonymousIdFeature>();
      if (feature != null)
      {
        string anonymousId = feature.AnonymousId;
      }
      ....
  }
}

License

This project is licensed under the terms of the MIT license.

Version History

Version Downloads Last updated
1.0.1 613 1/16/2018