我得到这个错误,因为我的项目无法找到OWIN启动类的参考。我甚至通过Nuget安装了所有的OWIN参考包,仍然得到相同的问题。我使用的是Visual Studio 2012和MVC4。

在尝试加载应用程序时发生了以下错误。

没有找到包含OwinStartupAttribute的程序集。 没有找到包含Startup或[AssemblyName]的程序集。启动类。禁用OWIN启动发现,添加appSetting owin:在你的web.config中,AutomaticAppStartup的值为“false”。 要指定OWIN启动程序集、类或方法,请添加 appSetting owin:使用完全合格的启动类或 config中的配置方法名称。


当前回答

在Visual Studio 2013 RC2中,有一个模板。只需将其添加到App_Start文件夹。

模板生成这样一个类:

using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(WebApiOsp.App_Start.Startup))]

namespace WebApiOsp.App_Start
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
        }
    }
}

其他回答

如果你不想使用OWIN启动,这是你应该添加到你的网页。配置文件:

在AppSettings下添加以下行:

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

这是它在你的web.config中的样子:

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

在我的情况下,我登录到ftp服务器。备份了ftp服务器上的当前文件。手动删除ftp服务器上的所有文件。干净的解决方案,重新部署代码。它工作。

在Visual Studio 2013 RC2中,有一个模板。只需将其添加到App_Start文件夹。

模板生成这样一个类:

using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(WebApiOsp.App_Start.Startup))]

namespace WebApiOsp.App_Start
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
        }
    }
}

看看Startup.cs文件,你可能会错过其中一个。这个文件是OWIN的入口点,所以听起来好像这个缺失了。看看这里的OWIN Startup类,了解发生了什么。

正如您的错误所指定的,您可以在web上禁用此功能。通过做以下配置…

禁用OWIN启动发现,添加appSetting owin:在你的web.config中,AutomaticAppStartup的值为“false”

我在尝试SignalR并将其从项目中移除后遇到了这个问题。为了解决这个问题,我不得不删除远程服务器上站点的bin文件夹的内容,然后再次发布。