aleripe / AnonymousId

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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
      .SetCustomCookieRequireSsl(true)              // 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.

About

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

License:MIT License


Languages

Language:C# 88.8%Language:Ruby 5.2%Language:CSS 2.8%Language:PowerShell 1.8%Language:HTML 1.3%Language:JavaScript 0.1%