From 9033e67b82d95a812cd92a5a904c78c9a4d4e9d4 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 3 Mar 2026 09:17:25 +0100 Subject: [PATCH] Initial ASP.NET Core Web API with NTLM auth and Swagger Set up FakeNTLMServer project targeting .NET 8.0 with Windows Authentication (Negotiate) and Swagger/OpenAPI support. Added project and solution files, configured authentication and authorization in Program.cs, and included launch settings and logging configuration for development and production environments. --- FakeNTLMServer.csproj | 14 ++++++++++++ FakeNTLMServer.sln | 25 +++++++++++++++++++++ Program.cs | 32 ++++++++++++++++++++++++++ Properties/launchSettings.json | 41 ++++++++++++++++++++++++++++++++++ appsettings.Development.json | 8 +++++++ appsettings.json | 9 ++++++++ 6 files changed, 129 insertions(+) create mode 100644 FakeNTLMServer.csproj create mode 100644 FakeNTLMServer.sln create mode 100644 Program.cs create mode 100644 Properties/launchSettings.json create mode 100644 appsettings.Development.json create mode 100644 appsettings.json diff --git a/FakeNTLMServer.csproj b/FakeNTLMServer.csproj new file mode 100644 index 0000000..a3048ca --- /dev/null +++ b/FakeNTLMServer.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/FakeNTLMServer.sln b/FakeNTLMServer.sln new file mode 100644 index 0000000..89cbe31 --- /dev/null +++ b/FakeNTLMServer.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36717.8 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeNTLMServer", "FakeNTLMServer.csproj", "{D48FB142-068E-4DFD-B9D3-4F314114C6F3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D48FB142-068E-4DFD-B9D3-4F314114C6F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D48FB142-068E-4DFD-B9D3-4F314114C6F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D48FB142-068E-4DFD-B9D3-4F314114C6F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D48FB142-068E-4DFD-B9D3-4F314114C6F3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C23AD91D-109B-423A-9E13-FABF5B1FBE9E} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..7488e3e --- /dev/null +++ b/Program.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Authentication.Negotiate; + +var builder = WebApplication.CreateBuilder(args); + + +// Add services to the container. + +builder.Services.AddControllers(); +builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme) + .AddNegotiate(); +builder.Services.AddAuthorization(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthentication(); +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..d6df54f --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": true, + "anonymousAuthentication": false, + "iisExpress": { + "applicationUrl": "http://localhost:3643", + "sslPort": 44347 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5282", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7217;http://localhost:5282", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}