DotNetOpenAuth OpenID MVC 3 プロジェクトを作成しようとしていますが、ユーザー認証ステータスを受け取ることができません。post メソッドは正常に動作しますが、リクエストが HttpGet メソッドに返され、User.Identity.IsAuthenticated ステータスを確認すると、openID プロバイダーに正常にログインすると false が返されます。
問題を解決していない webconfig dotNetOpenAuth untrustedWebRequest で localhost との通信を有効にしましたが、ユーザーが認証済みユーザーとして返されない理由の答えを探すのに何時間も費やしました。
私のコードで認証されたようにopenIDプロバイダーからユーザーが返されない原因となる論理エラーがあるに違いありませんが、私はそれを見つけることができません.
私の質問に答えてくれてありがとう!
私のコントローラー:
namespace DotNetOpenAuth_OpenID.Controllers
{
public class UserController : Controller
{
private static OpenIdRelyingParty openid = new OpenIdRelyingParty();
public IFormsAuthenticationService FormsService { get; set; }
protected override void Initialize(RequestContext requestContext)
{
if (FormsService == null)
{
FormsService = new AuthenticationService();
}
base.Initialize(requestContext);
}
// **************************************
// URL: /User/LogIn
// **************************************
[HttpGet]
public ActionResult LogIn()
{
if (User.Identity.IsAuthenticated) <===== RETURNS FALSE
{
return RedirectToAction("Profile", "User");
}
Identifier id;
if (Identifier.TryParse(Request.Form["openid_identifier"], out id))
{
try
{
var req = openid.CreateRequest(Request.Form["openid_identifier"]);
return req.RedirectingResponse.AsActionResult();
}
catch (ProtocolException ex)
{
//display error by showing original LogOn view
//this.ErrorDisplay.ShowError("Unable to authenticate: " + ex.Message);
return View("Login");
}
//return LogIn(new User { OpenID = id }, Request.Form["ReturnUrl"]);
}
return View("Login");
}
[HttpPost]
public ActionResult LogIn(User model, string returnUrl)
{
string openID = ModelState.IsValid ? model.OpenID : Request.Form["openid_identifier"];
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Profile", "User");
}
else if (!string.IsNullOrEmpty(openID))
{
return Authenticate(openID, returnUrl);
}
else if (ModelState.IsValid)
{
ModelState.AddModelError("error", "The OpenID field is required.");
}
// If we got this far, something failed, redisplay form
return View(model);
}