ASP.NET / MVC:在上下文中找不到owin.Environment项

时间:2015-04-20 22:37:59

标签: asp.net-mvc

我正在使用VS2013进行ASP.NET MVC Web应用程序。该计算机是Windows Server Enterprise,SP2和IIS 7.

我收到以下错误:

Server Error in '/' Application.
No owin.Environment item was found in the context.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: No owin.Environment item was found in the context.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: No owin.Environment item was found in the context.]

我用Google搜索并找到了一个解决方案并在web.config中执行了类似的操作(通过添加<add name="OWIN".... >):

<system.webServer>
    <modules >
        <remove name="FormsAuthenticationModule" />
        <remove name="UrlRoutingModule-4.0" />
        <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
    </modules>  
    <handlers>
        <add name="OWIN" path="*" verb="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler" />
    </handlers>
</system.webServer>  

执行此操作后,Web应用程序正常运行。但是,浏览器找不到CSS和Javascript等所有静态文件(所有静态文件都是404),所以我的应用程序没有样式。

配置

的正确方法是什么
<handlers>
   <add name="OWIN" path="*" verb="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler" />
</handlers>

让我的应用正常运行?或者我还需要做点什么?

谢谢!

1 个答案:

答案 0 :(得分:1)

经过多次测试后我才开始工作了。这是我做的:

<add name="OWIN" path="/Account/*" verb="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler" />

请注意具有特定路径的上述路径属性。我的所有javascript和css文件都在其他顶级目录下。

我不是ASP.NET / MVC专家。如果有人有更好的想法,请告诉我!

干杯。