我有以下腳本:爲什麼Request.IsAuthenticated是假的
function OpenIdLogon(e) {
$.post("/Account/OpenIdLogOn/", { token: e }, function (data) {
$("#userNavigation").html(data);
$(".auth_box").hide();
$(".kb_fading").hide();
});
}
這是操作:
public ActionResult OpenIdLogOn(string token)
{
WebClient cli = new WebClient();
string json = cli.DownloadString(new Uri("http://ulogin.ru/token.php?token=" + Request.Params["token"] + "&host=" + Request.Url.Host));
var obj = JObject.Parse(json);
if (obj["error"] == null)
{
var userName = obj["nickname"].Value<string>();
var email = obj["email"].Value<string>();
FormsAuthentication.SetAuthCookie(userName, true);
}
return PartialView("UserNavigation");
}
而且,我的UserNavigation:
@if (Request.IsAuthenticated)
{
<a href="#" class="username"><span>@Context.User.Identity.Name</span><i class="icon iUser"></i></a>
<ul class="headLine_link">
<li><a href="#">Profile</a></li>
<li>
@Html.ActionLink("Logg Off", "LogOff", "Account", null, new { @class = "exit" })</li>
</ul>
}
else
{
<ul class="headLine_link">
<li><a id="regLink">Register</a></li>
<li><a id="authLink">Log On</a></li>
</ul>
}
中的問題只有刷新頁面後,Request.IsAuthenticated
才爲真。
感謝您的解釋。 – user348173 2012-03-02 07:49:34