外部身份验证不会重定向到外部站点

Bre*_*een 10 c# asp.net asp.net-mvc asp.net-mvc-5 asp.net-identity

在这里发生了一件奇怪的事情.

我已经构建了一个ASP.NET MVC5网站,并通过ASP.NET身份使本地帐户正常工作.

我现在正在尝试启用外部身份验证,但发生了一些奇怪的事情.

我确定我已经按照正确的步骤.我在我的Startup.Auth.cs中有这个:

    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: "");

        //app.UseFacebookAuthentication(
        //   appId: "",
        //   appSecret: "");

        app.UseGoogleAuthentication();
    }
Run Code Online (Sandbox Code Playgroud)

当用户单击要使用Google登录的链接时,将调用ExternalLogin方法:

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult ExternalLogin(string provider, string returnUrl)
    {
        // Request a redirect to the external login provider
        return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
    }
Run Code Online (Sandbox Code Playgroud)

我通过调试验证的是进入ChallengeResult类的ExecuteResult方法:

        public override void ExecuteResult(ControllerContext context)
        {
            var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
            if (UserId != null)
            {
                properties.Dictionary[XsrfKey] = UserId;
            }
            context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
        }
Run Code Online (Sandbox Code Playgroud)

但是,在浏览器中,没有任何反应.我只是得到一个空白页面,我希望重定向到Google登录页面.

根本没有报告错误.

另一个有趣的事情是我尝试创建另一个MVC5应用程序,但我在VS2013中得到一个"对象引用没有设置为对象的实例"弹出窗口,并且生成的项目缺少默认情况下通常存在的帐户控制器.

我已经修复了VS2013的安装,我重新安装了Update 1,并且我还更新了解决方案中的所有Nuget软件包.

我已经没有了下一步的想法.

更新1 认为这可能与我的PC有关,我已将网站部署到Azure,问题仍然存在.这是否意味着它可能与缺少的装配有关,并且没有正确报告?我已经运行了fusionlog,但我没有看到绑定失败.

通过干净安装Windows 8和VS2013来启动新VM,看看我是否可以在那里运行新项目.

更新2 好了,只是运行了另一轮"网络"捕获,当用户选择外部提供商时,它会发布到ExternalLogin操作,但响应是401 Unauthorized.可能是什么导致了这个?

Bre*_*een 12

好,

我弄清楚问题是什么(重要的部分).

首先,我仍然不知道为什么当我创建一个MVC项目时,我没有得到一个脚手架的AccountController类.

但是,似乎我的问题是我的登录按钮是通过"谷歌"而不是"谷歌"作为提供者.

说真的!?套管对提供商的名称很重要,我有点惊讶,但你去了.