Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No owin.Environment item was found in the context

Microsoft recently introduced new ASP.NET Identity - replacement for old (Simple)Membership. Unfortunately, I can't use this new membership system in my old project because it throws System.InvalidOperationException: No owin.Environment item was found in the context. This is a known bug, but Microsoft keeps silence about this issue. The easiest way to reproduce this bug - it's to create a new web application (MVC, WebForms or WebApi - doesn't matter) in VS 2013 (with Web Tools 2013 Preview Refresh) and then go to the login page. It will work. Then change namespace in your application to anything else than original namespace and login page will throw that error. Changing namespace back to original (the one you used at the creation of a project) will solve this problem.

It looks like .net stores somewhere something related to the original namespace, but I can't find what and where, it's not in the project folder. I know that stackoverflow is not a place for a bug reports, I just hoping that someone already found a solution for this issue or maybe people involved in the development of ASP.NET Identity will see this.

like image 652
graycrow Avatar asked Aug 14 '13 13:08

graycrow


5 Answers

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.

like image 147
pranav rastogi Avatar answered Nov 20 '22 22:11

pranav rastogi


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

<add key="owin:AutomaticAppStartup" value="true" />
like image 17
cesar-moya Avatar answered Nov 20 '22 22:11

cesar-moya


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">
like image 17
Drol Avatar answered Nov 20 '22 21:11

Drol


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

like image 10
Gatis Bergšpics Avatar answered Nov 20 '22 20:11

Gatis Bergšpics


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.

like image 8
Luiz Bicalho Avatar answered Nov 20 '22 22:11

Luiz Bicalho