0

我开发了我们的应用程序并允许用户通过 Facebook、Microsoft、Google、Twitter 和 LinkedIn 登录。

在 Globas.asax 注册服务中:

protected void Application_Start(object sender, EventArgs e)
        {
            BundleTable.EnableOptimizations = !HttpContext.Current.IsDebuggingEnabled;
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ScriptManager.ScriptResourceMapping.AddDefinition("jquery",
                new ScriptResourceDefinition
                {
                    Path = "~/Scripts/jquery-1.10.2.min.js",
                    DebugPath = "~/Scripts/jquery-1.10.2.js"
                });

            this.RegisterAuthenticationProviders();
        }

        private void RegisterAuthenticationProviders()
        {
            OAuthWebSecurity.RegisterFacebookClient("key1", "key2", "Facebook");
            OAuthWebSecurity.RegisterGoogleClient("Google");
            OAuthWebSecurity.RegisterLinkedInClient("key1", "key2", "LinkedIn");
            OAuthWebSecurity.RegisterMicrosoftClient("key1", "key2", "Microsoft");
            OAuthWebSecurity.RegisterTwitterClient("key1", "key2", "Twitter");
        }

单击按钮调用适当的方法:

OAuthWebSecurity.RequestAuthentication("ServiceName", String.Format("~/Login.ashx"));

服务名称为:Microsoft、Google、LinkedIn、Facebook 或 Twitter(根据按下的按钮)。

处理程序 Login.aspx 看起来像:

public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            var result = OAuthWebSecurity.VerifyAuthentication();
            if (result.IsSuccessful)
            {
                var service = (LoginServices)Enum.Parse(typeof(LoginServices), result.Provider, true);
                //Find user in DB, if not find create and login at last
                this.TryLogin(result, context, service);

                this.RedirectRequest(context);
            }
            else
            {
                // Login failed
                DBLogger.WriteLog(LogPriority.Fatal, String.Format("{0}-{1}_1", this.GetType().Name, "ProcessRequest"), result.Error);
                this.RedirectRequest(context, ErrorMessages.LoginFailed);
            }
    }

Facebook:很好,一切正常

Microsoft:重定向到登录很好,但作为回报,我将返回错误:

The remote server returned an error: (400) Bad Request. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
 Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.
Source Error: 
 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 

[WebException: The remote server returned an error: (400) Bad Request.]
   System.Net.HttpWebRequest.GetResponse() +6442312
   DotNetOpenAuth.AspNet.Clients.MicrosoftClient.QueryAccessToken(Uri returnUrl, String authorizationCode) +334
   DotNetOpenAuth.AspNet.Clients.OAuth2Client.VerifyAuthentication(HttpContextBase context, Uri returnPageUrl) +142
   DotNetOpenAuth.AspNet.OpenAuthSecurityManager.VerifyAuthentication(String returnUrl) +239
   Microsoft.Web.WebPages.OAuth.OAuthWebSecurity.VerifyAuthenticationCore(HttpContextBase context, String returnUrl) +129
   Microsoft.Web.WebPages.OAuth.OAuthWebSecurity.VerifyAuthentication(String returnUrl) +86
   Login.ProcessRequest(HttpContext context) +18
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

Google 和 LinkedIn:点击我报告 javascript 错误的链接:Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0

Twitter点击链接我报javascript错误:

Sys.WebForms.PageRequestManagerServerErrorException: Error occurred while sending a direct message or getting the response.

这些按钮在页面的 OnInit 事件中注册 onclick envet。

你知道为什么我的代码不起作用吗?谢谢

更新

问题解决了。这就是 UpdatePanel 中的 ImageButtons

4

1 回答 1

0

对于 LinkedIn,只需更新软件包,它肯定会起作用。

更新包 DotNetOpenAuth.Core

点击“输入”并享受。

于 2016-08-17T15:38:54.263 回答