Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: No owin.Environment

Tags:

c#

asp.net

iis

I feel I've got the same problem as described in this thread. I am working on an ASP.NET MVC web application that runs fine locally. When deployed to our Windows Server 2008 with IIS7, however, I get the following error when trying to log in:

No owin.Environment item was found in the context.

This is the line that triggers this error:

return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();

I have tried all I could find:

  1. Adding <add key="owin:AppStartup" value="My_App.Startup,My-App"/> toe the web.config. My Application has a hyphen in its name, but that should not be a problem, right?
  2. Adding <add key="owin:AutomaticAppStartup" value="true"/> to the web.config.
  3. Adding <modules runAllManagedModulesForAllRequests="true"> to the web.config.
  4. I verified that Microsoft.Owin.Host.SystemWeb is installed and in the bin-folder.
  5. Clearing the ASP.net temporary files.
  6. The app pool is set to "integrated"

It's working just fine locally. What am I missing?

This is not a duplicate of this thread. I have tried the solution from there (see my #1) to no success. Also, I have not changed the namespace.

Edit One solution is to register the OwinHttpHandler explicitly in the web.config but this had some strange side effects (my CSS and JavaScript are not loaded anymore, Status 404?):

<handlers>
    <add name="OWIN" path="*" verb="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler" />
</handlers>
like image 444
peter Avatar asked Jul 16 '15 13:07

peter


1 Answers

Naming Convention: Katana looks for a class named Startup in namespace matching the assembly name or the global namespace.

OwinStartup Attribute: This is the approach most developers will take to specify the startup class. The following attribute will set the startup class to the TestStartup class in the StartupDemo namespace.

[assembly: OwinStartup(typeof(StartupDemo.TestStartup))]

<appSettings>  
  <add key="owin:appStartup" value="StartupDemo.ProductionStartup" />
</appSettings>

The following key, which explicitly specifies the startup class and assembly can also be used:

  <add key="owin:appStartup" value="StartupDemo.ProductionStartup, StartupDemo" />


<appSettings>  
  <add key="owin:appStartup" value="ProductionConfiguration" />       
</appSettings>

The above markup must be used with the following OwinStartup attribute which specifies a friendly name and causes the ProductionStartup2 class to run.

[assembly: OwinStartup("ProductionConfiguration", typeof(StartupDemo.ProductionStartup2))]

namespace StartupDemo
{
    public class ProductionStartup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                string t = DateTime.Now.Millisecond.ToString();
                return context.Response.WriteAsync(t + " Production OWIN App");
            });
        }
    }
    public class ProductionStartup2
    {
        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                string t = DateTime.Now.Millisecond.ToString();
                return context.Response.WriteAsync(t + " 2nd Production OWIN App");
            });
        }
    }
}
like image 75
Jegadeesh Waran Avatar answered Sep 27 '22 20:09

Jegadeesh Waran