No owin.Environment item was found in the context.

Vote:
 

Background:

  1. installed VS and episerver plugin
  2. installed nuget episerver thing
  3. created new alloy project.  created dummy user.
  4. Added new emptyproject.
  5. Could not login. Dummy user created for Alloy nor windows login works (as am not a local admin, its a domain login)
  6. So created use programatically using this code (cant include links - causes server error when post, so including a code snippit):
https://world.episerver.com/blogs/kristoffer-linden/dates/2017/12/create-episerver-login-account-by-code/

8. Ran the project.
9. hit localhost://xxx/episerver

Get this:

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.]
   System.Web.HttpContextExtensions.GetOwinContext(HttpContext context) +78
   EPiServer.Cms.UI.AspNetIdentity.<>c.<ConfigureContainer>b__0_3(IServiceLocator s) +31
   EPiServer.ServiceLocation.Internal.TypedFactory`1.<Create>b__2_0(IServiceLocator s) +13
   lambda_method(Closure , IBuildSession , IContext ) +181

[StructureMapBuildException: Failure while building 'Lambda: Invoke(value(EPiServer.ServiceLocation.Internal.StructureMapConfiguredType`1+<>c__DisplayClass11_0`1[EPiServer.Shell.Security.UISignInManager,EPiServer.Shell.Security.UISignInManager]).instanceAccessor, value(EPiServer.ServiceLocation.Internal.StructureMapConfiguredType`1[EPiServer.Shell.Security.UISignInManager])._serviceLocator)', check the inner exception for details
1.) Lambda: Invoke(value(EPiServer.ServiceLocation.Internal.StructureMapConfiguredType`1+<>c__DisplayClass11_0`1[EPiServer.Shell.Security.UISignInManager,EPiServer.Shell.Security.UISignInManager]).instanceAccessor, value(EPiServer.ServiceLocation.Internal.StructureMapConfiguredType`1[EPiServer.Shell.Security.UISignInManager])._serviceLocator)
2.) Instance of EPiServer.Shell.Security.UISignInManager
3.) Container.GetInstance(EPiServer.Shell.Security.UISignInManager)
]
   lambda_method(Closure , IBuildSession , IContext ) +491
   StructureMap.Building.BuildPlan.Build(IBuildSession session, IContext context) +92
   StructureMap.BuildSession.BuildNewInSession(Type pluginType, Instance instance) +92
   StructureMap.Pipeline.NulloTransientCache.Get(Type pluginType, Instance instance, IBuildSession session) +14
   StructureMap.BuildSession.ResolveFromLifecycle(Type pluginType, Instance instance) +47
   StructureMap.SessionCache.GetObject(Type pluginType, Instance instance, ILifecycle lifecycle) +128
   StructureMap.SessionCache.GetDefault(Type pluginType, IPipelineGraph pipelineGraph) +100
   StructureMap.Container.GetInstance(Type pluginType) +178
   EPiServer.ServiceLocation.StructureMapServiceLocator.DoGetInstance(Type serviceType, String key) +40
   EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +42

[ActivationException: Activation error occurred while trying to get instance of type UISignInManager, key ""]
   EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +101
   EPiServer.ServiceLocation.ServiceLocatorImplBase.GetInstance() +60
   EPiServer.ServiceLocation.Injected`1.get_Service() +36
   EPiServer.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +26

FYI, I did a clean, and restarted VS. did not help

#209475
Edited, Nov 14, 2019 17:10
Vote:
 

FYI, I tried setting optimizeCompilations="false" in Web.config, which is apparently the workaround, but now I get the below when trying to launcha page or trying to login with /episerver.

Server Error in '/' Application.
The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- No assembly found containing a Startup or [AssemblyName].Startup class.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

#209477
Nov 14, 2019 17:27
Vote:
 

When you deleted the Alloy project you probably removed all necessary start-up code, e.g. the class called startup.cs which contains all the Owin configuration.

#209478
Nov 14, 2019 17:52
johnv - Nov 15, 2019 8:53
Hi, the alloy project is just a different visual studio project - there is no interaction between projects. If I create 3 empty projects, and run one, it doesn't use anything from the other 2 - they are just source code in a different directory structures right?

Just in case, i restored the allow project from backup, and it doesn't make any difference. The alloy project is not used by the new empty project.

If I look in my new empty site project, I cant see startup.cs. I am not sure if this is a bug in the episerver VS plugin, or there is some other reason why this file was not created.

As a test, I just created another new "empty site" project. It too is missing startup.cs. If I create a second alloy project, from scratch, it does contain the file. So if startup.cs is needed to run a project, there is show stopping bug in the creation of the empty project? I.e. if you create an empty project, it wont run. There is no mention of this in the docs - it says you should be able to create an empty project and login. It doesnt mention having to manually create a startup.cs file.
Vote:
 

Hi johnv,

You've started quite many different threads about your issue so really hard to follow which one is active ;-)

1# If you add multiplte Episerver projects to a Visual Studio solution by default the projects don't share anything between each other. They have separate databases, look at web.congig 'connectionstring' element

2# When you create a new epmty Episerver project, it doesn't use ASP.Net Identity BUT ASP.Net memebership&rolemanager (look at web.config, authentication mode is 'Forms' and you have the entries membership (defaultProvider=MultiplexingMembershipProvider) and roleManager (defaultProvider=MultiplexingRoleProvider). The Multiplexing***Provider is a special provider that can combine different providers but only one of those is used to create new entries, other providers are used only for reading (sorry this might confuse you for now). So in the default setup these multiplexing ones use SQL server based providers + Windows, which means that you can for example use your local (or domain) account to sign in (but it needs to be a member of the local Administrator group, which you already have noticed in some other thread). => and now to the startup.cs not being there, it shouldn't because that is used in ASP.Net identity authentication, so that is the reason why there is no startup.cs generated by the Episerver project template (and besides the file name could be anything because it is not about file name but OWIN startup).

So if you can't use your windows account to login, you can always create a simple create-account.aspx and in that create a default admin user to the SQL membership, see the API documentation in MSDN. Then start your project in Visual Studio and go to this "secret" aspx page and it creates the account for you and then you can login using that account (just remember that you don't deploy this file to a test or production environment ;-) ).

While doing this, you could actually change the membership and roleManager to not support Windows at all:

  • change membership defaultProvider to SqlServerMembershipProvider value
  • change roleManager defaultProvider to SqlServerRoleProvider value
  • whit the above configuration the users and roles are only used from the database

And as a side note, the ASP.Net Identity is the more modern way to do it, so maybe you should just actually just switch to it. Create empty Episerver project and then another Alloy project (which uses Identity) and then compare the web.config files to see the difference in the configuration and then copy the Identity code from the Alloy project to your empty project and You should get the Identity based authentication to work in your project (in Alloy project you are mainly interested of the Startup.cs (owin magic happens in this file, the assembly: OwinStartup(xxxx) attribute) and AdministratorRegistrationPage.cs)

#209536
Nov 16, 2019 19:46
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.