我目前正在做一个简单的登录应用程序,它还允许用户更改密码。但是,我@Html.ActionLink
没有重定向到更改密码页面,我认为这是因为我在 web.config 中的设置。我如何解决它?
这是我的代码。
Index.chtml(登录页面)
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<h2>@ViewBag.Title</h2>
@using(Html.BeginForm())
{
@Html.LabelFor(login => login.Username)
@Html.TextBoxFor(login => login.Username)<br/>
@Html.LabelFor(login => login.Password)
@Html.PasswordFor(login => login.Password)<br/>
<input type="submit" value="Login" />
@Html.ActionLink("Change Password", "Index", "ChangePW")
@Html.ValidationSummary()
}
@ViewBag.Error
网页配置
<location>
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="Content">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="Scripts">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
单击后生成的 HTML 代码Change Password
:
<div>
<h2>BlueBerry Login</h2>
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"> </script>
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
<h2></h2>
<form action="/Login?ReturnUrl=%2fChangePW" method="post">
<label for="Username">User name: </label>
<input data-val="true" data-val-required="The User name: field is required." id="Username" name="Username" type="text" value="" />
<br/>
<label for="Password">Password: </label>
<input data-val="true" data-val-required="The Password: field is required." id="Password" name="Password" type="password" />
<br/>
<input type="submit" value="Login" />
<a href="/ChangePW">Change Password</a>
<div class="validation-summary-valid" data-valmsg-summary="true">
<ul>
<li style="display:none"></li>
</ul>
</div>
</form>
</div>
更新@Html.ActionLink
当我进入应用程序时
我尝试使用它并且它有效。真的很奇怪……
更新 2
这是登录控制器的代码
public class LoginController : Controller
{
//
// GET: /Login/
#region Declarations
MembershipHelper _mem = new MembershipHelper();
#endregion
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(MasterUser user)
{
if (ModelState.IsValid)
{
if (_mem.ValidateUser(user.Username, user.Password)) //successful
{
FormsAuthentication.SetAuthCookie(user.Username, false);
user = _mem.LoggedUser;
Session["loggedUser"] = user;
return RedirectToAction("Index", "Home");
}
ModelState.AddModelError("",_mem.Status);
}
else
{
ModelState.AddModelError("", "User does not exist");
}
return View();
}
}