asp.net-mvc OwinStartup 不触发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20203982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OwinStartup not firing
提问by Jeff Treuting
I had the OwinStartup configuration code working perfectly and then it stopped working. Unfortunately I'm not sure exactly what I did to get it to stop working and am having a really hard time figuring it out.
我让 OwinStartup 配置代码完美运行,然后它停止工作。不幸的是,我不确定我做了什么才能让它停止工作,而且我真的很难弄清楚。
To make sure I have the basics covered, I doubled checked to make sure the I have the
为了确保我掌握了基础知识,我再次检查以确保我拥有
[assembly:OwinStartup(typeof(WebApplication.Startup))]
attribute assigned properly and made sure that I don't have an appSetting for owin:AutomaticAppStartup that is set to false so I made one set to true to be safe as there was nothing there before.
属性分配正确,并确保我没有设置为 false 的 owin:AutomaticAppStartup 的 appSetting,因此我将一个设置为 true 以确保安全,因为之前没有任何内容。
<add key="owin:AutomaticAppStartup" value="true" />
I also tried specifically calling out the appSetting:
我还尝试专门调用 appSetting:
<add key="owin:appStartup" value="WebApplication.Startup" />
Before it stopped working I upgraded the Microsoft.Owin.Security NuGet packages to 2.0.2, so I tried reverting them to 2.0.1 (that was a pain) but it didn't change anything. I have WebActivator installed on the project and am using that to bootstrap other things but I've tested that on a fresh WebApplication template and it works there so I don't think that is the culprit.
在它停止工作之前,我将 Microsoft.Owin.Security NuGet 包升级到 2.0.2,所以我尝试将它们恢复到 2.0.1(这很痛苦)但它没有改变任何东西。我在项目上安装了 WebActivator 并使用它来引导其他东西,但我已经在一个新的 WebApplication 模板上测试了它并且它在那里工作,所以我认为这不是罪魁祸首。
I also tried removing my Startup class and using Visual Studio to add a new one using the OWIN Startup Class type in Add New Item and that isn't getting called either. Next I tried adding a second Startup class since I know it will throw an exception if there is more than one OwinStartup attributes defined, but it isn't throwing any exception there.
我还尝试删除我的 Startup 类并使用 Visual Studio 使用添加新项中的 OWIN Startup Class 类型添加一个新类,并且也没有被调用。接下来我尝试添加第二个 Startup 类,因为我知道如果定义了多个 OwinStartup 属性,它会抛出异常,但它不会在那里抛出任何异常。
Not sure what else to try. Any thoughts?
不知道还有什么可以尝试的。有什么想法吗?
Update
更新
Turns out that Resharper removed the reference to Microsoft.Owin.Host.SystemWeb when I used it to remove unused references.
事实证明,当我使用它删除未使用的引用时,Resharper 删除了对 Microsoft.Owin.Host.SystemWeb 的引用。
回答by Praburaj
Make sure you have installed Microsoft.Owin.Host.SystemWebpackage in the project. This package is needed for startup detection in IIS hosted applications. For more information you can refer to this article.
确保你已经Microsoft.Owin.Host.SystemWeb在项目中安装了包。IIS 托管应用程序中的启动检测需要此包。有关更多信息,您可以参考这篇文章。
回答by Simon_Weaver
If you've upgraded from an older MVC version make sure you don't have
如果您从较旧的 MVC 版本升级,请确保您没有
<add key="owin:AutomaticAppStartup" value="false" />
in your web.config. It will suppress calling the startup logic.
在您的web.config. 它将抑制调用启动逻辑。
Instead change it to true
而是将其更改为 true
<add key="owin:AutomaticAppStartup" value="true" />
I realize you already mentioned this but sometimes people (like me) don't read the whole question and just jump to the answers...
我意识到您已经提到了这一点,但有时人们(像我一样)不会阅读整个问题而只是跳到答案......
Somewhere along the line - when I upgraded to MVC 5 this got added and I never saw it until today.
沿着这条线的某个地方 - 当我升级到 MVC 5 时,它被添加了,直到今天我才看到它。
回答by Aaron Sherman
Alternative answer to the original problem discussed - Owin "not firing." In my case I spent hours thinking it wasn't firing due to being unable to set a breakpoint in it.
讨论的原始问题的替代答案 - Owin“不开火”。就我而言,由于无法在其中设置断点,我花了几个小时认为它没有触发。
When debugging OWIN startup in visual studio
在visual studio中调试OWIN启动时
IIS Express - Running "F5" will break on the OWIN startup code
IIS - Running "F5" will notbreak until after OWIN (and global.asax) code is loaded. If you attach to W3P.exe you will be able to step into it.
IIS Express - 运行“F5”将中断 OWIN 启动代码
IIS -在加载 OWIN(和 global.asax)代码之前,运行“F5”不会中断。如果您附加到 W3P.exe,您将能够进入它。
回答by Remotec
If you are having trouble debugging the code in the Startupclass, I have also had this problem - or I thought I did. The code was firing but I believe it happens before the debugger has attached so you cannot set breakpoints on the code and see what is happening.
如果您在调试Startup类中的代码时遇到问题,我也遇到了这个问题——或者我认为我遇到了。代码正在触发,但我相信它发生在调试器附加之前,因此您无法在代码上设置断点并查看发生了什么。
You can prove this by throwing an exception in the Configurationmethod of the Startupclass.
您可以通过Configuration在Startup类的方法中抛出异常来证明这一点。
回答by Rasmus
DEBUGGING TIPS
调试技巧
If debugging does not work try using IIS Express or try the method below for local IIS
如果调试不起作用,请尝试使用 IIS Express 或针对本地 IIS 尝试以下方法
Using local IIS
使用本地 IIS
For some reason this method enables debugging of this method:
出于某种原因,此方法可以调试此方法:
- Request a webpage
- Attach to w3wp.exe process
- Touch the web.config file
- Request a webpage
- 请求一个网页
- 附加到 w3wp.exe 进程
- 触摸 web.config 文件
- 请求一个网页
Extra tip
额外小费
Maybe doing this will flush a cache:
也许这样做会刷新缓存:
In web.config add the optimizeCompilations attribute with a false value
<compilation debug="true" ... optimizeCompilations="false">
Run site
- Undo the change in web.config
在 web.config 中添加带有 false 值的 optimizeCompilations 属性
<compilation debug="true" ... optimizeCompilations="false">
运行站点
- 撤消 web.config 中的更改
回答by randomsolutions
I had a similar issue to this and clearing Temporary ASP.NET Files fixed it. Hope this helps someone.
我有一个类似的问题,清除临时 ASP.NET 文件修复了它。希望这可以帮助某人。
回答by Ufuk Hac?o?ullar?
I had the same problem. Microsoft.Owin.Host.SystemWeb package was installed but during the installation NuGet was not able to add the dll as a reference for some reason. Make sure your project has that reference. If not you can try to reinstall:
我有同样的问题。Microsoft.Owin.Host.SystemWeb 包已安装,但在安装过程中,由于某种原因,NuGet 无法添加 dll 作为参考。确保您的项目具有该参考。如果没有,您可以尝试重新安装:
update-package Microsoft.Owin.Host.SystemWeb -reinstall
I had an error like below on reinstall but somehow it worked:
我在重新安装时遇到了如下错误,但不知何故它起作用了:
System call failed. (Exception from HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED))
系统调用失败。(来自 HRESULT 的异常:0x80010100 (RPC_E_SYS_CALL_FAILED))
回答by Grey Wolf
In my case, the IIS application pool was not set to v4. It was v2.
就我而言,IIS 应用程序池未设置为 v4。这是 v2。
Changed the AppPool to v4 and everything was okay.
将 AppPool 更改为 v4,一切正常。
回答by James Rapson
I had same problem when I added Owin to an existing web project. I eventually found the problem was due to the following in the web.config file.
当我将 Owin 添加到现有的 Web 项目时,我遇到了同样的问题。我最终发现问题是由于 web.config 文件中的以下内容造成的。
<assemblies>
<remove assembly="*" />
<add assembly="System.Web.Mvc" />
<add assembly="System.Web.WebPages" />
...
</assemblies>
The remove assembly="*" was causing the problem. When I remove this line the Owin startup code ran. I eventually change it to the following and it worked perfectly
删除程序集="*" 导致了问题。当我删除这一行时,Owin 启动代码运行了。我最终将其更改为以下内容,并且效果很好
<assemblies>
<remove assembly="*" />
<add assembly="Microsoft.Owin.Host.SystemWeb" />
<add assembly="System.Web.Mvc" />
<add assembly="System.Web.WebPages" />
<add assembly="System.Web.Helpers" />
...
</assemblies>
回答by Sean Song
In my case, my website's output path is changed by somebody, the IIS Express even not load OWIN, and the setup class will not be hit of course. After I set the output path as "bin\", it works well.
就我而言,我的网站的输出路径被某人更改了,IIS Express甚至不加载OWIN,当然也不会命中安装类。我将输出路径设置为“bin\”后,效果很好。

