【发布时间】:2013-01-11 15:40:52
【问题描述】:
我有一个用户区域,在其中我注册了以下内容:
context.MapRoute("DefaultRedirect",
"",
new { controller = "Account", action = "Login" }
);
当我使用 routeDebug 时,它告诉我,当我连接到我的网站 www.xxx.com 时,它会尝试调用
area = User, controller = Account, action = Login
当我使用以下方式直接连接时:www.xxx.com/User/Account/Login 我的登录页面出现。
当我不使用 routeDebug 并连接到我的网站 www.xxx.com 时,我会收到一条错误消息:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /
这是我的控制器操作方法:
public class AccountController : Controller
{
//
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login()
{
ViewBag.ReturnUrl = "xx";
return View("~/Areas/User/Views/Account/Login.cshtml");
}
我很困惑,因为 routeDebug 似乎表明我将转到正确的控制器和操作,但是当我不使用它并放置断点时,它似乎并没有转到控制器操作。
【问题讨论】:
-
你能验证 ~/Areas/User/Views/Account/Login.cshtml"); 存在于这个位置 - 这可能是错误。我只涉足 MVC,但如果你这样做应该可以只需 return View(); 因为这将解析为帐户控制器的登录视图。
-
如果我直接使用 www.xxx.com/User/Account/Login 调用操作,它就在那里并且它可以工作,但如果我调用 www.xxx.com 则不会
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 routes