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 void Main() | |
{ | |
var template = "Hello {{Name}}, how are you?"; | |
var model = new { Name = "Alice" }; | |
var output = TemplateEngine.Execute(template, model); | |
// Output: "Hello Alice, how are you?" | |
} |
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
<div class="form-group"> | |
<label class="control-label" for="url">URL</label> | |
<input class="form-control" type="url" id="url" placeholder="https://api.example.com/" /> | |
<p class="help-block" id="url-help"></p> | |
</div> |
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
<script src="//tinymce.cachefly.net/4.2/tinymce.min.js"></script> | |
<script> | |
tinymce.init({ | |
selector: 'textarea', | |
images_upload_url: "TinyMceUpload", | |
}); | |
function upload(form) { | |
tinymce.activeEditor.uploadImages(function (success) { | |
form.submit(); |
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 |
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 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
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
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.IdentityModel.Tokens.Jwt; | |
using System.Security.Claims; | |
using System.Security.Principal; | |
using System.Text; | |
using Microsoft.IdentityModel.Tokens; | |
namespace Example | |
{ | |
class Token | |
{ |
OlderNewer