0
Webセキュリティ認証に問題があります。ログインできません。認証retrurn常にfalse 私は常にログインページに私を送信します。私はそれをデバッグし、私はこの問題は、常にfalseを返しhttpContext.Request.IsAuthenticated見つけ、任意のヘルプ... コントローラー:Webセキュリティは常に「偽」を返します。
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
[AllowAnonymous]
[HttpPost]
public ActionResult Login(UserProfile register)
{
WebSecurity.Login(register.UserName, register.password, true);
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Index", "Home");
}
return RedirectToAction("Index", "Contact");
}
ビュー:
<h2>@ViewBag.Title.</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@using (Html.BeginForm("Login", "AccountHopital", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Utilisez un compte local pour vous connecter.</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.password, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.password, "", new { @class = "text-danger" })
</div>
</div>
とweb.configファイル:
<system.web>
<membership defaultProvider="SimpleMembershipProvider">
<providers>
<add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership>
<authentication mode="Forms">
<!--<modules>
<remove name="FormsAuthentication" />
</modules>-->
<forms loginUrl="~/AccountHopital/Login" timeout="3600" />
</authentication>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
WebSecurity.Login方法について
Here is the MSDNそれは常にfalseです:HasUserID = falseの場合、にisAuthenticated =偽:/ –
あなたはPOSTログインメソッドの内部でチェックしている場合、それはなります。クッキーなどのために別のアクションにリダイレクトする必要があります。 al。自由に使えるようにする。 1)ログインし、2)上記のコードを使用してログインページに戻ります。再度、あなたの 'WebSecurity.Login'メソッドへの呼び出しを成功させなければなりません**そして**あなたは、そのCookieが適用されるための別のリクエストにリダイレクトする必要があります。 – Tommy
私はformsauthentication.setauthcookieを使用しようとしていますが、それはWebSecurity.Loginのクッキーの問題です。 –