No owin.Environment item was found in the context

不打扰是莪最后的温柔 提交于 2019-11-28 09:38:24

Most likely it cannot find the OWIN Startup class. The default convention for the Startup class is [AssemblyName].Startup. If you're no longer following that convention you'll need to specify the full name of your Startup class in the Web.Config.

The next release of Microsoft.Owin.Host.SystemWeb package now throws detailed exception messages when the Startup class cannot be found.

I created two new projects called TesteMvc5.2 and TesteMvc5.0 and both of them didn't work at start

this is because the default namespace is different from the assembly name. but after I put the line

<add key="owin:AppStartup" value="TesteMvc5._2.Startup, TesteMvc5.2" />

on the web.config it worked fine.

I had the exact same error, but as it turned out I had another configuration problem in my web.config. My web.config was missing the attribute defaultLanguage="c#" in the compilation element under system.web.

In this case it will default to VB. So unless you have your Startup class written in VB you should change the default language to C#.

Not correct:

<compilation debug="true" optimizeCompilations="true" targetFramework="4.6.1">

This is correct (unless you use VB):

<compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.6.1">

I had the same issue, it was fixed after making sure this line was in web.config:

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

I tried everything mentioned on this page but nothing worked. Then I found out about a setting in IIS named owin:AutomaticAppStartup. You can find it in the Application Settings page of the IIS Manager for the Default Web Site. Check to see if that setting is true. If not set to true. This worked for me.

This is the website where I found the answer: http://gotoanswer.stanford.edu/?q=Microsoft.Owin.Host.SystemWeb+and+still+getting+No+owin.Environment+item+was+found+in+the+context

I had this same issue. I fixed it with the web.config.

However I had changed the assembly name and namespace and did not find the original assembly name anywhere anymore.

I then discovered that clean was not removing the original assembly from the bin.

Aftter deleting the bin litter, I was able to remove the web.config OWIN entry.

Cleaning ASP.NET temporary files helped me with this exact problem

Mathi Rajan

If you happened to have copied the below config from MVC4, you should remove it from web.config

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

None of the above answers worked for me.

Turned out my project was missing the "Startup" class that contains the following:

using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(NAMESPACE.Startup))]
namespace NAMESPACE
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

This file called "Startup.cs" is located on the root folder (~/) of your project.

My "Web.config" doesn't have any of this "Owin" configuration posted on the other replies.

Had same problem. Thanks for the shared solutions. this..

<add key="owin.AppStartup" value="Namespace.Startup, Namespace"/>
<add key="owin:AutomaticAppStartup" value="false"/>  

fixed for me

I have no idea why this works but it did!

My problem was in VS2013. In the WebConfig, debug was set to true and I got that error. When I set it to false it worked fine and then I reset to true and it continued to work OK!

At first when debug was true before changing to false, I put a break point in my StartUp code and it wasn't reached at all. After changing to false pressing save and then back to true the StartUp code was called and the program works like it should.

adding default language to compilation in web.config did it for me!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!