c# – 外部认证不重定向到外部站点
有一个奇怪的事情发生在这里.
我已经建立了一个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 用干净的Windows 8和VS2013安装新的虚拟机,看看是否可以在这里找到一个新的项目. 更新2 解决方法
好,
我想出了这个问题的重要部分. 首先,我还不知道为什么当我创建一个MVC项目时,我没有得到一个脚手架的AccountController类. 但是,似乎我的问题是我的登录按钮是通过“谷歌”而不是“谷歌”作为提供者. 说真的!?我有点惊讶,套管对提供者的名字很重要,但是你去了. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |