OwinStartup不触发

本文翻译自:OwinStartup not firing

I had the OwinStartup configuration code working perfectly and then it stopped working. 我的OwinStartup配置代码运行正常,然后停止运行。 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. 不幸的是,我不确定到底要怎么做才能使其停止工作,并且很难弄清楚它。

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. 属性已正确分配,并确保我没有将owin:AutomaticAppStartup的appSetting设置为false,所以我将其中之一设置为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. 在它停止工作之前,我将Microsoft.Owin.Security NuGet软件包升级到2.0.2,因此我尝试将它们还原到2.0.1(这很痛苦),但是它没有任何改变。 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. 我在项目上安装了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. 我还尝试删除了Startup类,并使用Visual Studio在“添加新项”中使用OWIN Startup类类型添加了一个新类,但没有一个被调用。 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类,因为我知道如果定义了多个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的引用。


#1楼

参考:https://stackoom.com/question/1Mlyg/OwinStartup不触发


#2楼

Make sure you have installed Microsoft.Owin.Host.SystemWeb package in the project. 确保已在项目中安装了Microsoft.Owin.Host.SystemWeb软件包。 This package is needed for startup detection in IIS hosted applications. 在IIS托管的应用程序中启动检测需要此软件包。 For more information you can refer to this article . 有关更多信息,请参考本文


#3楼

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. 以我为例,我花了数小时以为它无法触发,因为无法在其中设置断点。

When debugging OWIN startup in visual studio 在Visual Studio中调试OWIN启动时

  • IIS Express - Running "F5" will break on the OWIN startup code IIS Express-运行“ F5”将在OWIN启动代码上中断

  • IIS - Running "F5" will not break until after OWIN (and global.asax) code is loaded. IIS-在加载OWIN(和global.asax)代码之后,运行“ F5” 不会中断。 If you attach to W3P.exe you will be able to step into it. 如果您附加到W3P.exe,则可以进入它。


#4楼

If you are having trouble debugging the code in the Startup class, I have also had this problem - or I thought I did. 如果您在调试Startup类中的代码时遇到问题,那么我也有这个问题-或我以为是。 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. 代码正在触发,但是我相信它是在调试器附加之前发生的,因此您无法在代码上设置断点并查看正在发生的情况。

You can prove this by throwing an exception in the Configuration method of the Startup class. 您可以通过在Startup类的Configuration方法中引发异常来证明这一点。


#5楼

I had a similar issue to this and clearing Temporary ASP.NET Files fixed it. 我对此有类似的问题,并且清除了“临时ASP.NET文件”后将其修复。 Hope this helps someone. 希望这对某人有帮助。


#6楼

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 . 在您的web.config It will suppress calling the startup logic. 它将禁止调用启动逻辑。

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时,添加了它,直到今天我才看到它。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值