Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions examples/VariantServiceDemo/HttpContextTargetingContextAccessor.cs

This file was deleted.

21 changes: 17 additions & 4 deletions examples/VariantServiceDemo/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.FeatureManagement;
using System.Security.Claims;

namespace VariantServiceDemo.Pages
{
Expand All @@ -19,11 +21,22 @@ public IActionResult OnGet()
{
//
// generate a new visitor
string visitor = Random.Shared.Next().ToString();
Username = Random.Shared.Next().ToString();

Response.Cookies.Append("username", visitor);
// Clear Application Insights cookies and
Response.Cookies.Delete("ai_user");
Response.Cookies.Delete("ai_session");

Username = visitor;
// Generate new user claim
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, Username)
};

var identity = new ClaimsIdentity(claims, "CookieAuth");
var principal = new ClaimsPrincipal(identity);

HttpContext.SignInAsync("CookieAuth", principal);

return Page();
}
Expand Down
12 changes: 4 additions & 8 deletions examples/VariantServiceDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.Telemetry.ApplicationInsights;
using VariantServiceDemo;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -14,14 +12,12 @@
// Add services to the container.
builder.Services.AddRazorPages();

builder.Services.AddHttpContextAccessor();
//
// Use cookie auth for simplicity and randomizing user
builder.Services.AddAuthentication("CookieAuth");

builder.Services.AddApplicationInsightsTelemetry();

//
// App Insights TargetingId Tagging
builder.Services.AddSingleton<ITelemetryInitializer, TargetingTelemetryInitializer>();

//
// Add variant implementations of ICalculator
builder.Services.AddSingleton<ICalculator, DefaultCalculator>();
Expand All @@ -35,7 +31,7 @@
// Including user targeting capability and the variant service provider of ICalculator which is bounded with the variant feature flag "Calculator"
// Wire up evaluation event emission
builder.Services.AddFeatureManagement()
.WithTargeting<HttpContextTargetingContextAccessor>()
.WithTargeting()
.WithVariantService<ICalculator>("Calculator")
.AddApplicationInsightsTelemetry();

Expand Down
Loading