我在注销后遇到问题,我重定向到我网站的登录页面。但是,除非我刷新,否则登录页面的 javascript 根本不会执行。
我正在使用以下链接调用 Account 控制器的 LogOff 操作(此代码位于单独的控制器中):
@Html.ActionLink("Logout", "LogOff", "Account", null, new { data_icon = "gear", @class = "ui-btn-right" })
Account 控制器中的 LogOff 方法如下所示,其中我传递了一个注销参数,以便在登录视图中检测我从注销操作来到这里:
public ActionResult LogOff()
{
return Redirect(Url.Action("LogOn", "Account", new RouteValueDictionary(new { logout = true })));
}
检查萤火虫,我注意到javascript
$(document).ready(function () { ... });
在我的登录页面中使用的根本不执行。
此外,登录页面的 url 显示为“localhost:#####/Account/LogOff”,而不是我预期的“localhost:#####/Account/LogOn?logout=True”。
如果我之后尝试提交登录表单,那么我将被发送到一个空白页面,其 url 为“http://localhost:#####/?logout=True”
所以我想知道我做错了什么导致页面无法加载其javascript,以及如何解决这个问题。
谢谢!
更新: 这是我的登录控制器方法:
public ActionResult LogOn()
{
List<SelectListItem> cpList = new List<SelectListItem>();
// Retrieve the list of central points from web.config
NameValueCollection centralPoints = (NameValueCollection)ConfigurationManager.GetSection("CentralPointDictionary");
foreach (string cp in centralPoints)
cpList.Add(new SelectListItem { Text = cp as string, Value = centralPoints[cp] as string });
// Check for a cookie containing a previously used central point
string selectedCP = string.Empty;
if (ControllerContext.HttpContext.Request.Cookies["LastCentralPoint"] != null)
selectedCP = ControllerContext.HttpContext.Request.Cookies["LastCentralPoint"].Value;
else if (cpList.Count > 0)
selectedCP = cpList[0].Text;
LogOnModel loginModel = new LogOnModel { CentralPointsList = new SelectList(cpList, "Value", "Text", selectedCP) };
return View(loginModel);
}
我的观点的主体:
<div data-role="page" id="page">
<div data-role="header" data-position="inline">
<div id="languageContainer" data-role="fieldcontain">
<select id="languageSelect" data-mini="true" data-theme="b" data-overlay-theme="d" data-native-menu="false" data-inline="true">
<option value="English">English</option>
<option value="Français">Français</option>
</select>
</div>
</div><!-- /header -->
<div data-role="content" id="contentFrame" class="frame">
<div id="controlFrame">
@using (Html.BeginForm())
{
<div id="centralPoint" class="frame">
@Html.DropDownListFor(model => model.CentralPointAddress, Model.CentralPointsList, new { id = "centralPointSelect", name = "centralPoint", data_mini = "true", data_inline = "true", data_native_menu = "false" })
</div>
<div id="errorMsg">@Html.ValidationSummary()</div>
<div id="credentialsFrame" class="frame">
@Html.TextBoxFor(m => m.UserName, new { id = "userField", type = "text", name = "Username" })
@Html.PasswordFor(m => m.Password, new { id = "passField", type = "password", name = "Password" })
</div>
<input id="loginBtn" type="submit" value="Login" />
<div id="rememberMe" class="frame">
@Html.CheckBoxFor(m => m.RememberMe, new { @class = "custom", data_mini = "true" })
@Html.LabelFor(m => m.RememberMe)
</div>
<div id="forgotPassFrame">
<input id="forgotPass" type="button" data-mini="true" value="Forgot password?" />
</div>
@Html.HiddenFor(m => m.Encrypted, new { id = "encrypted", value = "false" })
}
</div>
@using (Html.BeginForm("SuccessfulLogin", "Account", FormMethod.Get, new { id = "successForm" }))
{
<input id="returnUrl" name="returnUrl" type="hidden" />
}
</div><!-- /content -->
</div><!-- /page -->