c# – 外部认证不重定向到外部站点

前端之家收集整理的这篇文章主要介绍了c# – 外部认证不重定向到外部站点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有一个奇怪的事情发生在这里.

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

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

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

  1. public void ConfigureAuth(IAppBuilder app)
  2. {
  3. // Enable the application to use a cookie to store information for the signed in user
  4. app.UseCookieAuthentication(new CookieAuthenticationOptions
  5. {
  6. AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/Account/Login")
  7. });
  8. // Use a cookie to temporarily store information about a user logging in with a third party login provider
  9. app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  10.  
  11. // Uncomment the following lines to enable logging in with third party login providers
  12. //app.UseMicrosoftAccountAuthentication(
  13. // clientId: "",// clientSecret: "");
  14.  
  15. //app.UseTwitterAuthentication(
  16. // consumerKey: "",// consumerSecret: "");
  17.  
  18. //app.UseFacebookAuthentication(
  19. // appId: "",// appSecret: "");
  20.  
  21. app.UseGoogleAuthentication();
  22. }

用户点击链接登录Google时,会调用ExternalLogin方法

  1. [HttpPost]
  2. [AllowAnonymous]
  3. [ValidateAntiForgeryToken]
  4. public ActionResult ExternalLogin(string provider,string returnUrl)
  5. {
  6. // Request a redirect to the external login provider
  7. return new ChallengeResult(provider,Url.Action("ExternalLoginCallback","Account",new { ReturnUrl = returnUrl }));
  8. }

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

  1. public override void ExecuteResult(ControllerContext context)
  2. {
  3. var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
  4. if (UserId != null)
  5. {
  6. properties.Dictionary[XsrfKey] = UserId;
  7. }
  8. context.HttpContext.GetOwinContext().Authentication.Challenge(properties,LoginProvider);
  9. }

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

根本没有报告错误.

另一个有趣的是,我试图创建另一个MVC5应用程序,但是在VS2013中我得到一个“对象引用未设置为对象的实例”弹出窗口,结果项目缺少通常默认的帐户控制器.

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

我没有想到下一步去哪里.

更新1
认为这可能与我的电脑有关,我已经将该网站部署到Azure,而且问题仍然存在.这是否意味着它可能与丢失的程序集相关,并且没有正确报告?
我已经运行fusionlog,但是我看不到有约束力的失败.

用干净的Windows 8和VS2013安装新的虚拟机,看看是否可以在这里找到一个新的项目.

更新2
好的,只是运行了另一轮“网络”捕获,当用户选择外部提供商时,它会发布到ExternalLogin操作,但响应是401未授权.可能是什么原因造成的?

解决方法

好,

我想出了这个问题的重要部分.

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

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

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

猜你在找的C#相关文章