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
2 changes: 1 addition & 1 deletion Microsoft.FeatureManagement.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetingConsoleApp", "exam
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FeatureManagement.Telemetry.ApplicationInsights", "src\Microsoft.FeatureManagement.Telemetry.ApplicationInsights\Microsoft.FeatureManagement.Telemetry.ApplicationInsights.csproj", "{7964DC66-B2D3-412D-B18A-86D1E07D149D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EvaluationDataToApplicationInsights", "examples\EvaluationDataToApplicationInsights\EvaluationDataToApplicationInsights.csproj", "{1502529E-47E9-4306-98C4-BF6CF7C7C275}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VariantAndTelemetryDemo", "examples\VariantAndTelemetryDemo\VariantAndTelemetryDemo.csproj", "{1502529E-47E9-4306-98C4-BF6CF7C7C275}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorServerApp", "examples\BlazorServerApp\BlazorServerApp.csproj", "{12BAB5A6-4EEB-4917-B5D9-4AFB6253008E}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature management provides a way to develop and expose application functionalit
* [ASP.NET Core Web App (Razor Page)](./examples/RazorPages)
* [ASP.NET Core Web App (MVC)](./examples/FeatureFlagDemo)
* [Blazor Server App](./examples/BlazorServerApp)
* [ASP.NET Core Web App with Feature Flag Telemetry](./examples/EvaluationDataToApplicationInsights)
* [ASP.NET Core Web App with Variants and Telemetry](./examples/VariantAndTelemetryDemo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is called VariantAndTelemetryDemo. Can we use singular here for consistency if there is no grammer issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weirdly- I think the grammar makes sense. This is an app that has variants (plural). But when describing something as a demo- it doesn't need to be plural. Like FilterDemo (instead of FiltersDemo).

If others feel strongly to align the two- I'd prefer changing the package to VariantsAndTelemetryDemo

* [ASP.NET Core Web App with Variant Service](./examples/VariantServiceDemo)

## Contributing
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace EvaluationDataToApplicationInsights.Pages
namespace VariantAndTelemetryDemo.Pages
{
public class CheckoutModel : PageModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace EvaluationDataToApplicationInsights.Pages
namespace VariantAndTelemetryDemo.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.FeatureManagement;

namespace EvaluationDataToApplicationInsights.Pages
namespace VariantAndTelemetryDemo.Pages
{
public class IndexModel : PageModel
{
Expand All @@ -22,7 +22,7 @@ public IndexModel(

public async Task<IActionResult> OnGet()
{
Username = Request.Cookies["username"];
Username = HttpContext.User.Identity.Name;

if (string.IsNullOrEmpty(Username))
{
Expand Down
4 changes: 4 additions & 0 deletions examples/VariantAndTelemetryDemo/Pages/RandomizeUser.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page
@model VariantAndTelemetryDemo.Pages.RandomizeUserModel
@{
}
30 changes: 30 additions & 0 deletions examples/VariantAndTelemetryDemo/Pages/RandomizeUser.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Security.Claims;

namespace VariantAndTelemetryDemo.Pages
{
public class RandomizeUserModel : PageModel
{
public IActionResult OnGet()
{
// Clear Application Insights cookies and
Response.Cookies.Delete("ai_user");
Response.Cookies.Delete("ai_session");

// Generate new user claim
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, Random.Shared.Next().ToString())
};

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

HttpContext.SignInAsync("CookieAuth", principal);

return RedirectToPage("/Index");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - EvaluationDataToApplicationInsights</title>
<title>@ViewData["Title"] - VariantAndTelemetryDemo</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/EvaluationDataToApplicationInsights.styles.css" asp-append-version="true" />
<link rel="stylesheet" href="~/VariantAndTelemetryDemo.styles.css" asp-append-version="true" />
@Html.Raw(JavaScriptSnippet.FullScript)

<script src="~/lib/jquery/dist/jquery.min.js"></script>
Expand All @@ -20,7 +20,7 @@
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">EvaluationDataToApplicationInsights</a>
<a class="navbar-brand" asp-area="" asp-page="/Index">VariantAndTelemetryDemo</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
Expand All @@ -46,10 +46,10 @@

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2023 - EvaluationDataToApplicationInsights - <a asp-area="" asp-page="/Checkout">Checkout</a>
&copy; 2023 - VariantAndTelemetryDemo - <a asp-area="" asp-page="/Checkout">Checkout</a>
</div>
</footer>

@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
</html>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@using EvaluationDataToApplicationInsights
@namespace EvaluationDataToApplicationInsights.Pages
@using VariantAndTelemetryDemo
@namespace VariantAndTelemetryDemo.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Microsoft.FeatureManagement.AspNetCore
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using EvaluationDataToApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.FeatureManagement;
using Microsoft.FeatureManagement.Telemetry.ApplicationInsights;

var builder = WebApplication.CreateBuilder(args);

//
// Use cookie auth for simplicity and randomizing user
builder.Services.AddAuthentication("CookieAuth")
.AddCookie("CookieAuth", options =>
{
options.LoginPath = "/RandomizeUser";
});

//
// What a web app using app insights looks like
//
// Add services to the container.
builder.Services.AddRazorPages();

builder.Services.AddHttpContextAccessor();

builder.Services.AddApplicationInsightsTelemetry();

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

//
// Enter feature management
//
// Enhance a web application with feature management
// Including user targeting capability
// Wire up evaluation event emission
builder.Services.AddFeatureManagement()
.WithTargeting<HttpContextTargetingContextAccessor>()
.WithTargeting()
.AddApplicationInsightsTelemetry();

//
Expand All @@ -50,6 +49,8 @@

app.UseRouting();

app.UseAuthentication();

app.UseAuthorization();

app.MapRazorPages();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand Down