Skip to content

Instantly share code, notes, and snippets.

@shirhatti
Created August 3, 2016 01:06
Show Gist options
  • Save shirhatti/e143b773ce9dcfb4b83889966deb7c7f to your computer and use it in GitHub Desktop.
Save shirhatti/e143b773ce9dcfb4b83889966deb7c7f to your computer and use it in GitHub Desktop.
Minimal ASP.NET Core to return 404
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
}
},
"publishOptions": {
"include": [
"web.config"
]
}
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
namespace ConsoleApplication
{
public class Startup
{
public void Configure(IApplicationBuilder app) {
app.Run(async (context) =>
{
context.Response.ContentType = "text/plain";
context.Response.StatusCode = 404;
await context.Response.WriteAsync("Custom 404 page");
});
}
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="dotnet" arguments=".\four-o-four.dll"/>
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment