加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 06:24:05 所属栏目:百科 来源:网络整理
导读:有一个奇怪的事情发生在这里. 我已经建立了一个ASP.NET MVC5网站,并通过ASP.NET身份使本地帐户正常工作. 我现在正在尝试启用外部身份验证,但有一些奇怪的事情发生. 我确定我已经遵循正确的步骤.我在Startup.Auth.cs中有这个: public void ConfigureAuth(IAp
有一个奇怪的事情发生在这里.

我已经建立了一个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();
    }

当用户点击链接以登录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 }));
    }

我通过调试验证了进入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);
        }

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

根本没有报告错误.

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

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

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

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

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

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

解决方法

好,

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

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读