This file contains hidden or 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 System.ComponentModel.DataAnnotations; | |
using System.Globalization; | |
using System.Linq; | |
using System.Reflection; | |
namespace Example | |
{ | |
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] | |
public class CompareToAttribute : ValidationAttribute |
This file contains hidden or 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.Http; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.Mvc.Filters; | |
namespace Example.AspNetCore.Mvc | |
{ | |
/// <summary> | |
/// An authorization filter that confirms requests are received over HTTPS. | |
/// </summary> |
This file contains hidden or 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
namespace Example | |
{ | |
public static class SeparatorConstants | |
{ | |
public const char FileSeparator = (char)0x1c; | |
public const char GroupSeparator = (char)0x1d; | |
public const char RecordSeparator = (char)0x1e; | |
public const char UnitSeparator = (char)0x1f; | |
} | |
} |
This file contains hidden or 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.IdentityModel.Tokens.Jwt; | |
using System.Security.Claims; | |
using System.Security.Principal; | |
using System.Text; | |
using Microsoft.IdentityModel.Tokens; | |
namespace Example | |
{ | |
class Token | |
{ |
This file contains hidden or 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 static class HttpContentExtensions | |
{ | |
/// <summary> | |
/// Serialize the HTTP content to a <see cref="ModelStateDictionary"/> as an asynchronous operation. | |
/// </summary> | |
/// <returns>A <see cref="ModelStateDictionary"/> that contains validation errors.</returns> | |
public static async Task<ModelStateDictionary> ReadAsModelStateAsync(this HttpContent content) | |
{ | |
var fields = await content.ReadAsAsync<IDictionary<string, string[]>>(); | |
var modelState = new ModelStateDictionary(); |
This file contains hidden or 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 System.Diagnostics.Contracts; | |
using System.Text; | |
using Microsoft.AspNetCore.Mvc.Filters; | |
namespace WebApplication | |
{ | |
/// <summary> | |
/// A filter that builds a Content Security Policy. | |
/// Mitigates the risk of XSS vulnerabilities. |
This file contains hidden or 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.Mvc.ViewFeatures; | |
using Microsoft.AspNetCore.Razor.TagHelpers; | |
namespace WebApplication.TagHelpers | |
{ | |
/// <summary> | |
/// <see cref="ITagHelper"/> implementation targeting <span> elements with an <c>asp-description-for</c> attribute. | |
/// </summary> | |
[HtmlTargetElement("span", Attributes = AttributeName)] |
This file contains hidden or 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
app.Use(async (context, next) => | |
{ | |
if (!context.Request.Scheme.IsHttps) { | |
context.Response.StatusCode = StatusCodes.Status403Forbidden; | |
await context.Response.WriteAsync("HTTPS is required."); | |
return; | |
} | |
await next.Invoke(); | |
}); |
This file contains hidden or 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 System.ComponentModel.DataAnnotations; | |
using System.Globalization; | |
using System.Linq; | |
using System.Reflection; | |
namespace DataAnnotations | |
{ | |
/// <summary> | |
/// Provides an attribute that compares two properties of a model and |
NewerOlder