【发布时间】:2014-04-24 17:44:46
【问题描述】:
我已经阅读了很多关于此的帖子,但仍然无法使其正常工作。 我正在使用 Visual Studio 2013。我创建了一个新的 MVC 5 项目,并认为使用新的 facebook 登录集成会很酷。它在我的 IIS Express 中的 PC 上运行良好。
但是当我将它上传到生产服务器时,我不断收到非常烦人的“No owin.Environment item was found in the context”消息。
这就是我所做的。
- 我从未更改过我的项目或程序集的名称。
- 程序集名称是 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" /> 我还确保关注 No owin.Environment item was found in the context - only on server 上的帖子并安装了 Microsoft.Owin.Host.SystemWeb
还有其他人坚持这个吗?我已经碰壁了 3 天了。
【问题讨论】:
-
我也看到了那个帖子,但它对我不起作用。看看是否有人看过所有这些帖子并且仍然卡住或找到不同的方法来解决它。真是太奇怪了..
-
确保您的 Web.config 确实位于生产服务器上的正确位置...
-
你终于让它工作了吗?我遇到了同样的问题。肯定找到了启动类,所以这一定是别的东西。最烦人的是,这只发生在生产机器上,而不是本地主机上。
标签: c# visual-studio-2013 owin