case AuthenticationStatus.Failed: in openid using asp.net
i am trying to implement the openid concept but failed. i have try different sample form internet and run them. when i run they ask me for authetication for provider. suppose i select google they redirect me to gmail site. i enter my email and password and submit it. but instead of redirect me to successful login page. it redirect me to login page and said login Failed case execute. one thing more when i open my gmail account it has opened. i dont know why status is failed. this bit of code one of sample i have tried.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
OpenIdRelyingParty OIDRP = new OpenIdRelyingParty();
IAuthenticationResponse str = OIDRP.GetResponse();
if (str != null)
{
switch (str.Status)
{
case AuthenticationStatus.Authenticated:
NotLoggedIn.Visible = false;
Session["GoogleIdentifier"] = str.ClaimedIdentifier.ToString();
开发者_如何学运维 Response.Redirect("Home.aspx"); //redirect to main page of your website
break;
case AuthenticationStatus.Canceled:
lblMessage.Text = "Cancelled.";
break;
case AuthenticationStatus.Failed:
lblMessage.Text = "Login Failed.";
break;
}
}
}
protected void OpenLogin_Click(object src, CommandEventArgs e)
{
string str = e.CommandArgument.ToString();
OpenIdRelyingParty openid = new OpenIdRelyingParty();
var b = new UriBuilder(Request.Url) { Query = "" };
IAuthenticationRequest req= openid.CreateRequest(str, b.Uri, b.Uri);
req.RedirectToProvider();
}
}
I had this same problem. The time on my server was off by just a few minutes and the ticket was expiring.
See: DotNetOpenAuth Failing to work on Live Server
精彩评论