File tree Expand file tree Collapse file tree 3 files changed +21
-65
lines changed
examples/VariantServiceDemo Expand file tree Collapse file tree 3 files changed +21
-65
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- using Microsoft . AspNetCore . Mvc ;
1+ using Microsoft . AspNetCore . Authentication ;
2+ using Microsoft . AspNetCore . Mvc ;
23using Microsoft . AspNetCore . Mvc . RazorPages ;
34using Microsoft . FeatureManagement ;
5+ using System . Security . Claims ;
46
57namespace VariantServiceDemo . Pages
68{
@@ -19,11 +21,22 @@ public IActionResult OnGet()
1921 {
2022 //
2123 // generate a new visitor
22- string visitor = Random . Shared . Next ( ) . ToString ( ) ;
24+ Username = Random . Shared . Next ( ) . ToString ( ) ;
2325
24- Response . Cookies . Append ( "username" , visitor ) ;
26+ // Clear Application Insights cookies and
27+ Response . Cookies . Delete ( "ai_user" ) ;
28+ Response . Cookies . Delete ( "ai_session" ) ;
2529
26- Username = visitor ;
30+ // Generate new user claim
31+ var claims = new List < Claim >
32+ {
33+ new Claim ( ClaimTypes . Name , Username )
34+ } ;
35+
36+ var identity = new ClaimsIdentity ( claims , "CookieAuth" ) ;
37+ var principal = new ClaimsPrincipal ( identity ) ;
38+
39+ HttpContext . SignInAsync ( "CookieAuth" , principal ) ;
2740
2841 return Page ( ) ;
2942 }
Original file line number Diff line number Diff line change 11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT license.
33//
4- using Microsoft . ApplicationInsights . Extensibility ;
54using Microsoft . FeatureManagement ;
6- using Microsoft . FeatureManagement . Telemetry . ApplicationInsights ;
75using VariantServiceDemo ;
86
97var builder = WebApplication . CreateBuilder ( args ) ;
1412// Add services to the container.
1513builder . Services . AddRazorPages ( ) ;
1614
17- builder . Services . AddHttpContextAccessor ( ) ;
15+ //
16+ // Use cookie auth for simplicity and randomizing user
17+ builder . Services . AddAuthentication ( "CookieAuth" ) ;
1818
1919builder . Services . AddApplicationInsightsTelemetry ( ) ;
2020
21- //
22- // App Insights TargetingId Tagging
23- builder . Services . AddSingleton < ITelemetryInitializer , TargetingTelemetryInitializer > ( ) ;
24-
2521//
2622// Add variant implementations of ICalculator
2723builder . Services . AddSingleton < ICalculator , DefaultCalculator > ( ) ;
3531// Including user targeting capability and the variant service provider of ICalculator which is bounded with the variant feature flag "Calculator"
3632// Wire up evaluation event emission
3733builder . Services . AddFeatureManagement ( )
38- . WithTargeting < HttpContextTargetingContextAccessor > ( )
34+ . WithTargeting ( )
3935 . WithVariantService < ICalculator > ( "Calculator" )
4036 . AddApplicationInsightsTelemetry ( ) ;
4137
You can’t perform that action at this time.
0 commit comments