我已经阅读了很多关于此的帖子,但仍然无法使其发挥作用。
我正在使用 Visual Studio 2013。我创建了一个新的 MVC 5 项目,并认为使用新的 facebook 登录集成会很酷。它在我的电脑上的 IIS Express 上运行良好。
但是,当我将其上传到生产服务器时,我不断收到非常烦人的“在上下文中找不到 owin.Environment 项目”消息。
这就是我所做的。
- 我从未更改过项目或程序集的名称。
- 程序集名称为 Wodivate
- 命名空间是 Wodivate
-
我有默认的 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);
}
}
}
-
在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();
}
}
}
-
我的 Web.config 文件包括:
<add key="owin:AppStartup" value="Wodivate.Startup, Wodivate" />
<add key="owin:AutomaticAppStartup " value="false" />
我还确保关注了该帖子在上下文中未找到 owin.Environment 项目 - 仅在服务器上并安装了 Microsoft.Owin.Host.SystemWeb
还有其他人坚持这个吗?我已经碰壁3天了。
我也遇到了同样的问题,这是由 IIS 设置引起的。
我的 IIS 部署有一个顶级站点,其下有多个应用程序。您应该确保您的站点级别的“应用程序设置”不与您的应用程序的冲突。
就我而言,我在站点级别有“owin:AutomaticAppStartup = false”,它由我的应用程序继承。
Summary:
- 打开 IIS 管理器
- 选择服务器 -> 应用程序设置。确保此级别没有冲突。
- 选择站点 -> 应用程序设置。确保此级别没有冲突。
Edit:我发现您可以简单地在 web.config 中添加以下 appSetting 来覆盖任何潜在的继承冲突。我建议您首先了解是否存在冲突,以便您可以做出明智的改变。
<add key="owin:AutomaticAppStartup" value="true"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)