Skip to content

Instantly share code, notes, and snippets.

@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"
services.Configure<IISOptions>(options => {
options.AutomaticAuthentication = true;
});
services.AddAuthentication(Microsoft.AspNetCore.Server.IISIntegration.IISDefaults.AuthenticationScheme);
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseIISIntegration()
[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);
}
# 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 .
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = true;
options.UrlPrefixes.Add("http://+:80/");
})
# 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';"]
@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.");
PS C:\Windows\system32> get-wmiobject -ComputerName 172.19.173.92 -Class win32_computersystem
Domain : ad.local
Manufacturer : Microsoft Corporation
Model : Virtual Machine
Name : CONTAINERHOST
PrimaryOwnerName :
TotalPhysicalMemory : 4105752576
@artisticcheese
artisticcheese / a.dockerfile
Last active March 13, 2018 15:27
dockerfile part for appinsights
WORKDIR prep
RUN Invoke-WebRequest "https://go.microsoft.com/fwlink/?linkid=517856" -UseBasicParsing -OutFile appinsights.msi; `
Start-Process -filepath "appinsights.msi" -ArgumentList "/quiet" -PassThru | Wait-Process; `
Remove-Item .\* -recurse -force -Verbose
RUN Import-Module 'C:\Program Files\Microsoft Application Insights\Status Monitor\PowerShell\Microsoft.Diagnostics.Agent.StatusMonitor.PowerShell.dll'; `
Start-ApplicationInsightsMonitoring -Name 'default web site' -InstrumentationKey '3c069cb6-fc1a-4bab-974c-0a4245ae7f1b'