OkOwin.SelfHost 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package OkOwin.SelfHost --version 1.0.2
NuGet\Install-Package OkOwin.SelfHost -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OkOwin.SelfHost" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OkOwin.SelfHost --version 1.0.2
#r "nuget: OkOwin.SelfHost, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OkOwin.SelfHost as a Cake Addin
#addin nuget:?package=OkOwin.SelfHost&version=1.0.2

// Install OkOwin.SelfHost as a Cake Tool
#tool nuget:?package=OkOwin.SelfHost&version=1.0.2
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Microsoft.Owin.FileSystems;
using Microsoft.Owin.StaticFiles;
using Owin;
using System.Web.Http;

namespace TestOwinSelfHostWebApi
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {

#if DEBUG
            app.UseErrorPage();
#endif

            app.UseCors(CorsOptions.AllowAll);

            #region Cors Domain

            //var policy = new CorsPolicy()
            //{
            //    AllowAnyHeader = true,
            //    AllowAnyMethod = true,
            //    SupportsCredentials = true
            //};

            //// list of domains that are allowed can be added here
            //policy.Origins.Add("domain");
            ////be sure to include the port:
            ////example: "http://localhost:8081"

            //app.UseCors(new CorsOptions
            //{
            //    PolicyProvider = new CorsPolicyProvider
            //    {
            //        PolicyResolver = context => Task.FromResult(policy)
            //    }
            //});

            #endregion

            app.MapWhen(context =>
            {
                return context.Request.Path.Value.StartsWith("/people");

            }, builder =>
            {
                builder.Run(async (context) =>
                {
                    await context.Response.WriteAsync("people");

                });
            });

            app.Map("/a/index", builder =>
            {
                builder.Run(async (context) =>
                {
                    await context.Response.WriteAsync("aaaaa");

                });
            });

            app.Map("/b/index", builder =>
            {
                builder.Run(async (context) =>
                {
                    await context.Response.WriteAsync("bbbb");

                });
            });

            //WebApi
            var config = GetWebApiConfig();
            app.UseWebApi(config);

            //wwwroot
            var fileOptions = new FileServerOptions()
            {
                RequestPath = PathString.Empty,
                EnableDefaultFiles = true,
                EnableDirectoryBrowsing = false,
                FileSystem = new PhysicalFileSystem(@".\wwwroot"),
            };
            fileOptions.StaticFileOptions.ServeUnknownFileTypes = true;
            app.UseFileServer(fileOptions);

            app.UseWelcomePage();
        }

        private HttpConfiguration GetWebApiConfig()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
            name: "Default",
            routeTemplate: "api/{controller}/{action}",
            defaults: new { id = RouteParameter.Optional }
            );

            //config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("datatype", "json", "application/json"));

            config.Formatters.Remove(config.Formatters.XmlFormatter);

            config.Formatters.JsonFormatter.SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings()
            {
                NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
            };

            return config;
        }

    }
}

using Microsoft.Owin.Hosting;
using System;

namespace TestOwinSelfHostWebApi
{
    class Program
    {
        static void Main(string[] args)
        {
            WebApp.Start<Startup>("http://*");
            Console.WriteLine("启动成功");
            Console.ReadKey();
        }
    }
}

mkdir "$(TargetDir)wwwroot"
xcopy "$(ProjectDir)wwwroot" "$(TargetDir)wwwroot" /S /E /C /Y
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.2.0" newVersion="4.2.2.0" />
      </dependentAssembly>
    </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OkOwin.SelfHost:

Package Downloads
OkOwin.SignalR

My package description.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 1,982 11/23/2023
1.0.2 2,668 4/11/2023