Owin在web.config中提供启动类(没有自动启动发现) [英] Owin provide startup class in web.config (no automatic startup discovery)

查看:316
本文介绍了Owin在web.config中提供启动类(没有自动启动发现)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的web.config中执行以下操作:

I try to do the following in my web.config:

<appSettings>
   <add key="owin:AutomaticAppStartup" value="false" />
   <add key="owin:appStartup" value="MyNamespace.MyStartupClass" />
</appSettings>

如果我理解此文档应该禁用正确的自动启动检测.因此,我不需要启动属性.

If I understand this documentation correctly automatic startup detection should be disabled. So I do not require a startup attribute.

不幸的是,看起来OWIN无法启动. (我看到这是因为出现错误:HTTP Error 403.14 - Forbidden.我使用控制器来处理对索引文件的请求.)

Unfortunately it looks like OWIN does not start. (I see this because I get the error: HTTP Error 403.14 - Forbidden. I use a controller to handle requests to the index file.)

如果我使用<add key="owin:AutomaticAppStartup" value="true" />并添加启动属性[assembly: OwinStartup(typeof(MyStartupClass))],则应用程序将按预期方式启动.

if I use <add key="owin:AutomaticAppStartup" value="true" /> and add the startup attribute [assembly: OwinStartup(typeof(MyStartupClass))] then the application does startup as expected.

所以问题是为什么?我该怎么办才能解决问题?

So the question is why? What can I do to resolve the issue?

我正在使用OWIN 3.0.0.0

I am using OWIN 3.0.0.0

更新:

这是我的启动类的样子(带有相关部分的缩小版):

This is how my startup class looks like (minified version with relevant parts):

using System.Web.Http;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Owin;
using MyOtherNamespace;

namespace MyNamespace
{
    public class MyOnlineStartup : MyOtherStartup
    {
        public new void Configuration(IAppBuilder app)
        {
            base.Configuration(app); //Call base method! This is important because otherwise ther serilization will not be correct
            HttpConfiguration config = CreateRouting();
            config.Routes.MapHttpRoute("exampleAppNone", "", new { controller = "MyIndex" }, null, null);
            config.Routes.MapHttpRoute("exampleAppIndex", "index.html", new { controller = "MyIndex" }, null, null);
            app.UseWebApi(config); // Use the WebAPI technology.
        }
    }
}

它源自

using System.Linq;
using System.Web.Http;
using Microsoft.AspNet.SignalR;
using Newtonsoft.Json;
using Owin;

namespace MyOtherNamespace
{
    public class MyOtherStartup
    {
        protected static HttpConfiguration CreateMyRouting()
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute(
                "myIndex",
                "my/",
                new
                {
                    controller = "MyIndex"
                },
                null,
                null
                );
            config.Routes.MapHttpRoute(
                "myIndex2",
                "my/index.html",
                new
                {
                    controller = "MyIndex"
                },
                null,
                null
                );
            var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
            config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
            config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto
            return config;
        }

        public void Configuration(IAppBuilder app)
        {
            JsonSerializer serializer = Serialization.ClientJsonSerializer();
            serializer.ContractResolver = new MySerializationContractResolver(false);
            GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => serializer);
            app.MapSignalR("/" + MyRequestHandler.MySignalRPath, new HubConfiguration());          
        }
    }
}

推荐答案

只需在web.config文件中删除以下代码行:

Simply remove this line of code in web.config file:

<add key="owin:AutomaticAppStartup" value="false" />

您的web.config文件现在必须如下所示:

Your web.config file now must look like this:

<appSettings>
    <add key="owin:appStartup" value="MyNamespace.MyStartupClass" />
</appSettings>  

只需添加owin:appStartup键,就不需要启动属性.

By adding just owin:appStartup key you don't need startup attribute.

这篇关于Owin在web.config中提供启动类(没有自动启动发现)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆