【发布时间】:2016-10-17 11:46:20
【问题描述】:
我有一个 asp.net mvc 项目,当进入 loginPage 我的 url 看起来像:
我不希望它看起来像这样,并且在 routConfig 文件中我已经这样做了:
routes.MapRoute(
name: "LogIn",
url: "LogIn",
defaults: new { controller = "Account", action = "Login" }
);
这应该使网址像这样:
我错过了什么?
编辑:
登录操作:
[AllowAnonymous]
public ActionResult Login()
{
return View();
}
编辑 2: @pwas 提到这是在视图中设置的,所以我通过删除 returnUrl 参数来更改它:
<section role="main" id="login">
<div class="panel center-block logInBlock" style="width:300px;">
<div class="panel-heading loginHeadPadding"><h1>Logga in</h1></div>
<div class="panel-body loginBodyPadding">
@using (Html.BeginForm("Login", "Account", new { }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<div class="form-group text-left">
@Html.LabelFor(m => m.UserName, "Användarnamn")
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control", placeholder = "Användarnamn" })
</div>
<div class="form-group text-left">
@Html.LabelFor(m => m.Password, "Lösenord")
@Html.PasswordFor(m => m.Password, new { @class = "form-control", placeholder = "Lösenord" })
</div>
<input type="submit" value="Logga in" class="btn btn-primary btn-block" />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
}
</div>
</div>
</section>
问题依旧
【问题讨论】:
-
我认为你应该使用 Url Patterns msdn.microsoft.com/en-us/library/…
-
那是在你创建一个新应用时由
AccountController中的方法生成的。这样当用户导航到需要授权的方法时,他们会自动重定向到登录页面,并且当他们提交时,会重定向回他们导航到的页面(对于您的 url,到 @987654328 @方法HomdeController) -
%2F是 url 编码的。它被解码 bslur id.. '/.Route has nothing to do with tjat. CheckUrl.Action` 或ActionLink在视图中生成此 url。 -
做了一些改动,请检查修改。
-
@Stephen Muecke 'PreserveLoginUrl' 未包含在 appsettings 中,当您说“修改 web.config.cs”时,您的意思是什么?如果可以,请提供答案。
标签: c# asp.net-mvc asp.net-mvc-5