Skip to content

Instantly share code, notes, and snippets.

@artisticcheese
artisticcheese / admembership.cs
Created October 12, 2017 18:21
AD membership function
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
# escape=`
# Image with SDK to build .NET Core application from source
FROM microsoft/aspnetcore-build:2.0.0-nanoserver As builder
WORKDIR /source/
COPY source .
RUN dotnet restore; dotnet publish -c Release
FROM microsoft/aspnetcore:2.0.0-nanoserver
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"]
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = true;
options.UrlPrefixes.Add("http://+:80/");
})
# escape=`
# Image with NET CORE installation to extract executables for final image
FROM microsoft/aspnetcore:2.0.0-nanoserver As CoreBuild
# Image with SDK to build .NET Core application from source
FROM microsoft/aspnetcore-build:2.0.0-nanoserver As builder
WORKDIR /source/
COPY source/iis .
[Authorize(Roles = "Domain Admins")]
public IActionResult Windows()
{
return Content ("You are " + User.Identity.Name + "; Authentication Type:" + User.Identity.AuthenticationType );
}
[Authorize(Roles = "Domain Users")]
public IActionResult Users()
{
return Content("You are " + User.Identity.Name + "; Authentication Type:" + User.Identity.AuthenticationType);
}
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseIISIntegration()
services.Configure<IISOptions>(options => {
options.AutomaticAuthentication = true;
});
services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);
@artisticcheese
artisticcheese / Dockerfile
Last active June 2, 2021 13:03
Dockerfile to build IIS + nanoserver + ASP.NET core
# escape=`
# Image with NET CORE installation to extract executables for final image
FROM microsoft/aspnetcore:2.0.0-nanoserver As CoreBuild
# Middleware image used to extract ASP.NET core module
From microsoft/iis as WindowsBuild
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"]
# Installing NET CORE webhosting in middleware image so latest module and configuration schema is extracted for final image
ADD https://download.microsoft.com/download/B/1/D/B1D7D5BF-3920-47AA-94BD-7A6E48822F18/DotNetCore.2.0.0-WindowsHosting.exe ".\hosting.exe"
@artisticcheese
artisticcheese / a.ps1
Last active September 9, 2017 20:42
GMSa
Invoke-WebRequest "https://raw.githubusercontent.com/Microsoft/Virtualization-Documentation/live/windows-server-container-tools/ServiceAccounts/CredentialSpec.psm1" -UseBasicParsing -OutFile $env:TEMP\cred.psm1
import-module $env:temp\cred.psm1
New-CredentialSpec -Name win -AccountName containerhost
#This will return location and name of JSON file
Get-CredentialSpec
Name Path
---- ----
win C:\ProgramData\docker\CredentialSpecs\win.json
@artisticcheese
artisticcheese / a.ps1
Created September 9, 2017 19:57
Enable GMSA account
Enable-WindowsOptionalFeature -FeatureName ActiveDirectory-Powershell -online -all
Get-ADServiceAccount -Identity containerhost
Install-ADServiceAccount -Identity containerhost
Test-AdServiceAccount -Identity containerhost