Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:

Scott Sauber scottsauber

:shipit:
View GitHub Profile
View ConfigurationBuilderExample.cs
var configurationBuilder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{Environment}.json");
if (Environment.IsDevelopment())
{
configurationBuilder.AddUserSecrets();
}
configurationBuilder.AddEnvironmentVariables();
View Index.cshtml.cs
[Authorize(PolicyName="Admin")]
public class IndexModel : PageModel
{
public void OnGet()
{
// do something
}
}
View Index.cshtml.cs
[Authorize]
public class IndexModel : PageModel
{
public void OnGet()
{
// do something
}
}
View Startup.cs
// OLD WAY FROM ASP.NET CORE PRIOR TO 3.0!!!!!!!!!
public class Startup
{
// Other Startup code omitted
public void ConfigureServices(IServiceCollection services)
{
// OLD WAY FROM ASP.NET CORE PRIOR TO 3.0!!!!!!!!!
services.AddMvc(options =>
{
var policy = new AuthorizationPolicyBuilder()
View Startup.cs
public class Startup
{
// Other Startup code omitted
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthorization(options =>
{
options.FallbackPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
View Startup.cs
public class Startup
{
private readonly IHostingEnvironment _hostingEnvironment;
public Startup(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public void ConfigureServices(IServiceCollection services)
View Startup.cs
public class Startup
{
private readonly IWebHostEnvironment _environment;
public Startup(IWebHostEnvironment environment)
{
_environment = environment;
}
public void ConfigureServices(IServiceCollection services)
View Startup.cs
// ASP.NET Core 2.2 and earlier
public void ConfigureServices(IServiceCollection services, IHostingEnvironment hostingEnvironment)
{
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddJsonOptions(options =>
{
options.SerializerSettings.Formatting = hostingEnvironment.IsDevelopment() ? Formatting.Indented : Formatting.None;
});
}
View RazorViewToStringRenderer.cs
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using System;
View inputField.test.js
import React from "react";
import { render, fireEvent } from "react-testing-library";
import InputField from "./InputField";
import { Formik } from "formik";
test("should have validation error given input field is touched and error exists on form", async () => {
const fieldName = "firstName";
const labelName = "First Name";
const { getByLabelText, findByTestId } = render(
<Formik