Error 404.0 after login. Asp.Net MVC and IIS 7.5

2019-07-31 13:56发布

问题:

I have a ASP.NET MVC app running over IIS 7.5 . Forms Authenticated enabled

I can access the login page. (Which means that route is ok) but when I log in the app should send a post data to http://localhost/tgpwebged/Account/Login to authenticate the user.

The problem is that my application is looking for /Account/Login in http://localhost/Account/Login (This is not the path).

I am trying without success change this behavior.

This is my route.config

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }

web.config

<authentication mode="Forms">
  <forms loginUrl="Account/Login"/>
</authentication>

View

<form method="post" action="/Account/Login">

Also IIS is set to accept Anonymous login for users to be able to access the login page.

This is the error message I am getting:

TTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Some detailed information:

Requested URL http://localhost:8081/Account/Login (right path: http://localhost:8081/tgpwebged/Account/Login ) Physical Path S:\Projects\Account\Login (Should be S:\Projects\tgpwebged\Account\Login) Logon Method Anonymous Logon User Anonymous

回答1:

The POST is going to wrong URL because that is what you have mentioned in the view. See

<form method="post" action="/Account/Login">

This would always post to <host name>/Account/Login

Try to give either relative path (or substitute absolute path using ResolveUrl method) - for example, in aspx view, you can use

<form method="post" action='<%= this.ResolveUrl("~/Account/Login") %>' >

In razor (cshtml) view, you can try (untested)

<form method="post" action='@Url.Content("~/Account/Login")' >