MVC 3 尝试启动 URL 来查看而不是控制器操作
有时,当我启动 MVC 3 项目时,它会尝试加载正在呈现的视图的完全限定 URL,而不是控制器内的操作(这会导致 404 错误)。其他时候它工作得很好并且实际上像预期的那样击中了控制器动作,但它大约是 50/50。
它有时访问的 URL 是: http://localhost:xxxx/Views/Account/LogOn.cshtml
这是 Global.asax 文件中的默认路由设置:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "LogOn", id = UrlParameter.Optional }
);
我还尝试删除 /{id } 路由中的参数,因为我认为登录屏幕不需要它。
有什么想法吗?目前,该项目的设置非常简单,使用 AccountController 等中的默认操作方法 LogOn。我所做的唯一一件事就是更改 global.asax 文件中的控制器和操作。
Sometimes when I launch my MVC 3 project it attempts to load the fully qualified URL for the view being rendered instead of the action within the controller (Which gives me a 404 error). Other times it works fine and actually hits the controller action like it's supposed to, but it's about 50/50.
The URL it hits sometimes is: http://localhost:xxxx/Views/Account/LogOn.cshtml
Here is the default route setup in the Global.asax file:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "LogOn", id = UrlParameter.Optional }
);
I also tried removing the /{id} parameter from the route as I don't feel it's needed for the logon screen.
Any ideas? Currently the project is setup pretty simply with the default action method LogOn in the AccountController etc. The only thing I did was change the controller and action in the global.asax file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:转到
项目属性
>网络
>开始操作
并选中
特定页面
选项 - 将文本框留空。Try this :go to
Project Properties
>Web
>Start Action
And check the
Specific Page
option - leaving the text box blank.您可能正在使用 Visual Studio,并且在点击调试时可能正在积极编辑 .cshtml 页面。
当您查看代码文件或来自不在启动项目(即您的 EF/模型项目)的项目中的文件时,请尝试启动调试器,并查看是否将调试器启动到正确的 URL。
项目属性中可能有一个指定启动 URL 的设置。我会寻找它并编辑这篇文章,如果我找到它。
You are probably using Visual Studio and you probably are actively editing a .cshtml page when you hit debug.
Try launching the debugger when you are either looking at a code file or a file from a project that isn't in the startup project (ie, your EF/model project) and see if that launches the debugger to the correct URL.
There might be a setting in the project properties that specifies the startup URL. I'll look for it and edit this post if I find it.
我猜你使用的是 cassini (VS.Net 中的内置开发 Web 服务器)?如果是这样,我总是会遇到这个问题,这似乎是 VS.Net 中的一个错误。切换到 IIS 7.5,你就不再得到它了
I'm guessing you using cassini (builtin dev web server in VS.Net)? If so I get this all the time and seams to be a bug in VS.Net. Switch to IIS 7.5 and you don't get it any more