在上下文中找到了Microsoft.Owin.Host.SystemWeb并且仍然没有获得owin.Environment项

use*_*747 9 c# owin visual-studio-2013

我已经阅读了很多这方面的帖子,但仍然无法使其发挥作用.我正在使用Visual Studio 2013.我创建了一个新的MVC 5项目,并认为使用新的facebook登录集成会很酷.它在我的电脑上在IIS Express中工作正常.

但是当我将它上传到生产服务器时,我不断收到非常烦人的"在上下文中找到No owin.Environment项目"消息.

这就是我所做的.

  1. 我从未改变过我的项目或装配的名称.
  2. 程序集名称为Wodivate
  3. 命名空间是Wodivate
  4. 我有默认的Startup.cs类,其中包含以下内容:

    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);
            }
    
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  5. 在App_Start中有一个Startup.Auth.cs文件,其中包含:

    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's email information by adding it in scope.
                app.UseFacebookAuthentication(facebookOptions);    
    
                //app.UseGoogleAuthentication();
            }
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  6. 我的Web.config文件包括:

    <add key="owin:AppStartup" value="Wodivate.Startup, Wodivate" />
    <add key="owin:AutomaticAppStartup " value="false" />
    
    Run Code Online (Sandbox Code Playgroud)
  7. 我还确保关注No owin.Invironment项目在上下文中找到 - 仅在服务器上并安装了Microsoft.Owin.Host.SystemWeb

还有其他人坚持这个吗?我已经打了3天了.

Bre*_*dán 3

我需要另一个 web.config 更改来解决这个问题:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

尽管不鼓励这种设置,但我尝试过:

<modules>
  <remove name="Owin" />
  <add name="Owin" type="Microsoft.Owin.Host.SystemWeb.OwinHttpModule, Microsoft.Owin.Host.SystemWeb" />
</modules>
Run Code Online (Sandbox Code Playgroud)

但这给了我错误:

“由于对象的当前状态,操作无效”

我还不确定那里发生了什么,是否是错误的模块或其他原因。