Asp.net web api 在开发人员计算机上不需要Startup.cs,但部署需要Startup.cs

Asp.net web api 在开发人员计算机上不需要Startup.cs,但部署需要Startup.cs,asp.net-web-api,owin,Asp.net Web Api,Owin,我正在开发一个ASP.NET Web API v2应用程序。我的应用程序在我的开发机器上运行良好,但当我将其部署到服务器时,它会出现以下错误 The following errors occurred while attempting to load the app. - No assembly found containing an OwinStartupAttribute. - No assembly found containing a Startup or [AssemblyName].

我正在开发一个ASP.NET Web API v2应用程序。我的应用程序在我的开发机器上运行良好,但当我将其部署到服务器时,它会出现以下错误

The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- No assembly found containing a Startup or [AssemblyName].Startup class.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
在搜索Google、SO和其他网站后,我发现在我的项目中添加一个默认的Startup.cs类解决了这个问题。问题是我不知道怎么做

  • 添加Startup.cs做了什么
  • 为什么我的应用程序在没有Startup.cs的情况下在我的开发机器上编译和运行
  • 这似乎涉及到
    OWIN
    ,但我甚至没有意识到我在使用任何
    OWIN
    功能

  • 这很可能是因为OWIN搜索其入口点的方式(
    Startup
    class)。在您的开发环境中,项目文件夹中可能有一个DLL,其中包含OWIN启动类。该dll未作为部署步骤的一部分进行部署,因此在部署位置中不存在

    同样,另一个可能性是您正在使用.config转换,并且您已经在DEV配置中定义了一个启动类,但没有在部署的配置中定义

    <appSettings>  
      <add key="owin:appStartup" value="StartupDemo.ProductionStartup" />
    </appSettings>
    
    可能会提供信息

    默认情况下,MVC5使用OWIN管道,因此它是“隐藏的”。也许您是从以前的MVC站点迁移过来的,这就是Startup类丢失的原因


    干杯

    当我将Startup.cs添加到项目中时,似乎无法解析对Microsoft.Owin的引用。我在我的项目引用中看到了Owin.dll,但Startup.cs似乎找不到它。不包括Startup.cs并通过在web.config中使用此值来避免Owin启动检查是否有任何负面影响<代码>
    如果您没有使用任何Owin组件,并且不需要添加到Owin管道,那么我认为这没有任何问题。