This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.Configure<CookiePolicyOptions>(options => | |
{ | |
// This lambda determines whether user consent for non-essential cookies is needed for a given request. | |
options.CheckConsentNeeded = context => true; | |
options.MinimumSameSitePolicy = SameSiteMode.None; | |
}); | |
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(cookieOptions => { | |
cookieOptions.LoginPath = "/"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page | |
@model AuthenticationSample.Pages.Admin.IndexModel | |
@{ | |
} | |
<h1>Admin</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.AspNetCore.Identity; | |
namespace PasswordHasherTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var passwordHasher = new PasswordHasher<string>(); | |
Console.WriteLine(passwordHasher.HashPassword(null, "strong password")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.Configure<RouteOptions>(options => | |
{ | |
options.ConstraintMap.Add("slug", typeof(SlugParameterTransformer)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SlugParameterTransformer : IOutboundParameterTransformer | |
{ | |
public string TransformOutbound(object value) | |
{ | |
return value?.ToString().ToSlug(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
public static class Extensions | |
{ | |
public static string ToSlug(this string value, bool toLower = true) | |
{ | |
if (value == null) | |
return ""; | |
var normalised = value.Normalize(NormalizationForm.FormKD); | |
const int maxlen = 80; | |
int len = normalised.Length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddMvc().AddRazorPagesOptions(options => | |
{ | |
options.Conventions.Add(new PageRouteTransformerConvention(new HyphenateRouteParameterTransformer())); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Routing; | |
using System.Text.RegularExpressions; | |
public class HyphenateRouteParameterTransformer : IOutboundParameterTransformer | |
{ | |
public string TransformOutbound(object value) | |
{ | |
if (value == null) | |
{ | |
return null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IProductService | |
{ | |
List<string> GetProductNames(); | |
} | |
public class ProductService : IProductService | |
{ | |
public List<string> GetProductNames() | |
{ | |
return new List<string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProductConstraint : IRouteConstraint | |
{ | |
private readonly IProductService productService; | |
public ProductConstraint(IProductService productService) | |
{ | |
this.productService = productService; | |
} | |
public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection) |