首页 > 代码库 > 如何定义一个有效的OWIN Startup Class

如何定义一个有效的OWIN Startup Class

  1. 命名约定

    Katana在程序集内的程序集名称空间下查找一个叫做Startup的类,

  2. 通过属性指定
    [assembly: OwinStartup(typeof(OwinConsoleApp.Startup))]
  3. 通过配置文件
<add key="owin:appStartup" value="http://www.mamicode.com/OwinConsoleApp.Startup1" />

 定义友好命名的Startup类

<appSettings>    <add key="owin:appStartup" value="http://www.mamicode.com/ProductionConfiguration" />       </appSettings>

 

[assembly: OwinStartup("ProductionConfiguration", typeof(StartupDemo.ProductionStartup2))]namespace StartupDemo{    public class ProductionStartup    {        public void Configuration(IAppBuilder app)        {            app.Run(context =>            {                string t = DateTime.Now.Millisecond.ToString();                return context.Response.WriteAsync(t + " Production OWIN App");            });        }    }    public class ProductionStartup2    {        public void Configuration(IAppBuilder app)        {            app.Run(context =>            {                string t = DateTime.Now.Millisecond.ToString();                return context.Response.WriteAsync(t + " 2nd Production OWIN App");            });        }    }}

 

如何定义一个有效的OWIN Startup Class