MVC 3 tries to launch URL to View instead of contr

2019-04-25 17:14发布

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.

3条回答
聊天终结者
2楼-- · 2019-04-25 17:58

Try this :go to Project Properties > Web > Start Action

And check the Specific Page option - leaving the text box blank.

查看更多
甜甜的少女心
3楼-- · 2019-04-25 18:09

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

查看更多
一夜七次
4楼-- · 2019-04-25 18:11

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.

查看更多
登录 后发表回答