Skip to content

Instantly share code, notes, and snippets.

View GeorgDangl's full-sized avatar
😎
Coding

Georg Dangl GeorgDangl

😎
Coding
View GitHub Profile
@GeorgDangl
GeorgDangl / ApiKeyRequirement.cs
Created July 10, 2018 14:48
Using Policy Based API Key Authorization in ASP.NET Core
public class ApiKeyRequirement : IAuthorizationRequirement
{
public IReadOnlyList<string> ApiKeys { get; set; }
public ApiKeyRequirement(IEnumerable<string> apiKeys)
{
ApiKeys = apiKeys?.ToList() ?? new List<string>();
}
}
@GeorgDangl
GeorgDangl / Startup.cs
Created July 10, 2018 12:05
Excluding Assemblies from ASP.NET Core MVC Controller Discovery
services.AddMvc()
// This allows to exclude some assembly from controller discovery
.ConfigureApplicationPartManager(a =>
{
var appPart = a.ApplicationParts.FirstOrDefault(ap => ap.Name == "Assembly.Name");
if (appPart != null)
{
a.ApplicationParts.Remove(appPart);
}
})
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<!-- The compression should be turned off to be able to inject content via a rewrite url -->
<!-- CloudFlare will still compress the final response when sending to the client -->
<urlCompression doStaticCompression="false" doDynamicCompression="false"/>
</system.webServer>
</configuration
public class Container
{
public Animal Animal { get; set; }
}
[JsonConverter(typeof(JsonInheritanceConverter), "discriminator")]
[KnownType(typeof(Dog))]
public class Animal
{
public string Foo { get; set; }
namespace Project.SpaExtensions
{
public interface IUserLanguageService
{
string GetUserLocale();
}
}
using LightQuery;
public class ApiController : Controller
{
[LightQuery(forcePagination: true, defaultPageSize: 3)]
[ProducesResponseType(typeof(PaginationResult<User>), 200)]
public IActionResult GetValues()
{
var values = _repository.GetAllValuesAsQueryable();
return Ok(values);
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace></RootNamespace>
<IsPackable>False</IsPackable>
<NoWarn>CS0649;CS0169</NoWarn>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="localPackages" value="./LocalPackages" />
</packageSources>
</configuration>
using Dangl.AVA.Contents;
using Dangl.AVA.Contents.ServiceSpecificationContents;
namespace Dangl.AVA.Converter.Tests.Utilities.TutorialFiles
{
public static class ProjectGenerator
{
public static Project GetProject()
{
var project = new Project();
#begin[GAEB]
#begin[_Dangl]
[_Info]Created with Dangl GAEB Tool, Copyright 2013 - 2018 Georg Dangl, www.dangl-it.com, Version 1.4.15.0 (Built: 11.01.2018 16:13)[end]
#end[_Dangl]
#begin[GAEBInfo]
[Version]1.2[end]
[VersMon]11[end]
[VersJahr]2001[end]
[Datum]17.02.2018[end]
[Uhrzeit]11:07[end]