Microsoft.Owin.Host.SystemWeb and still not received No owin.Environment element was found in context

I read a lot of posts about this, but still can't get it to work. I am using Visual Studio 2013. I created a new MVC 5 project and thought it would be great to use the new facebook login integration. It works fine on my PC in IIS Express.

But when I upload it to the Production server, I continue to receive the very annoying message "No owin.Environment item found in the context".

Here is what I did.

  • I never changed the name of my project or assembly.
  • Build Name - Wodivate
  • Wodivate Namespace
  • I have a default Startup.cs class that contains the following:

    using Microsoft.AspNet.Identity; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Owin; using System.Web.Http; [assembly: OwinStartupAttribute(typeof(Wodivate.Startup))] namespace Wodivate { public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); } } } 
  • App_Start has a Startup.Auth.cs file that contains:

     using Microsoft.AspNet.Identity; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Owin; namespace Wodivate { public partial class Startup { // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); // Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions() { AppId = "xxxxxxxxxxxxxxxxxxx", AppSecret = "xxxxxxxxxxxxxxxxxxxxxxxxx" }; facebookOptions.Scope.Add("email"); //We want to get user email information by adding it in scope. app.UseFacebookAuthentication(facebookOptions); //app.UseGoogleAuthentication(); } } } 
  • My Web.config file includes:

     <add key="owin:AppStartup" value="Wodivate.Startup, Wodivate" /> <add key="owin:AutomaticAppStartup " value="false" /> 
  • I also followed the message No owin.Environment element was found in context - only on the server and Microsoft.Owin.Host.SystemWeb is installed

Anyone else stuck on this? I attack the wall for 3 days.

+8
c # visual-studio-2013 owin
source share
7 answers

I needed another web.config change to solve this problem:

 <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> </system.webServer> 

Although this option is not recommended, I tried:

 <modules> <remove name="Owin" /> <add name="Owin" type="Microsoft.Owin.Host.SystemWeb.OwinHttpModule, Microsoft.Owin.Host.SystemWeb" /> </modules> 

but this gave me an error:

"Operation is not valid due to the current state of the object"

and I'm not sure what is going on there, whether it's the wrong module or something else.

+3
source share

Have you tried to do something like this?

 <system.webServer> <modules runAllManagedModulesForAllRequests="false" /> <handlers> <remove name="StaticFile" /> <add name="OWIN" path="*" verb="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler" /> </handlers> </system.webServer> 
+3
source share

I had the same problem and it was caused by IIS settings.

In my IIS deployment, there was a top-level site with several applications under it. You must make sure that the "Application Settings" at your level of the Site do not conflict with your application.

In my case, I had "owin: AutomaticAppStartup = false" at the site level that my application inherited.

Summary:

  • Open IIS Manager
  • Select "Server" → "Application Settings". Avoid owin conflicts at this level.
  • Select a site → Application Settings. Avoid owin conflicts at this level.

enter image description here


Edit: I found that you can simply add the following appSetting command in web.config to override any potential inherited conflicts. I would recommend to understand if there are conflicts at first, so you can make educated changes.

 <add key="owin:AutomaticAppStartup" value="true"/> 
+2
source share

You have checked the application pool usage mode. OWIN works with the built-in application pool mode. It will not work in classic mode.

+1
source share

When you get the exception "No owin.Environment element was found in context." from Request.GetOwinContext (), this usually means that detecting the OWIN startup class failed.

Make sure IIS runs the code in Startup.cs (in the root folder) at startup. To check if it works on a production server, I would recommend the following. 1) Insert the following line:

 ... System.Diagnostics.Trace.WriteLine("OwinStartup " + this.GetType().Namespace); ConfigureAuth(app); ... 

2) Get the DebugView utility here: https://technet.microsoft.com/en-us/library/bb896647.aspx

3) Run DbgView.exe as an administrator and make sure that the option "Capture / Capture Global Win32" is enabled.

4) When starting IIS, you should see a trace message from the above code (make sure it really rebooted by clicking web.config).

5) If it is not executed check here: http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection

There are a number of reasons why it is not executed. Many of them are in stackoverflow. Another that I will add is the following: make sure that you do not have the parameter “batch = false” in the “compile” node of the website.

+1
source share

What happens is that your BIN does not include a link. In the settings, change it to "Copy local" to TRUE. then publish it again.

0
source share

I struggled with this for DAYS! I tried everything in every post that I could find, and this solved the problem. I developed in VS 2013 and published on VM Server 2008, and I continued to receive the same message "No owin.Environment item found in the context".

I put this entry in the web configuration for the modules and fixed it. I'm not sure I understand why he fixed it, but it happened.

  <modules runAllManagedModulesForAllRequests="true" /> 
0
source share

All Articles