ASP.Net WebAPI OWIN: Why would Request.GetOwinContext() return null?

后端 未结 2 606
抹茶落季
抹茶落季 2021-01-05 12:02

In my production code we\'re having a problem where Request.GetOwinContext() always returns null.

I setup a small test WebAPI controller to try and isolate the probl

2条回答
  •  花落未央
    2021-01-05 12:58

    Another cause (especially after upgrading form ASP.NET MVC4 and / or Empty WebApi Template) is missing Startup.cs file in the root of WebAPI project.

    Also, make sure that you have installed Microsoft.Owin.Host.SystemWeb package.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Owin;
    using Owin;
    
    [assembly: OwinStartup(typeof(TestMVC5.Startup))]
    
    namespace TestMVC5
    {
        public partial class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                ConfigureAuth(app);
            }
        }
    }
    

提交回复
热议问题