错误登录后404.0。 Asp.Net MVC和IIS 7.5 [英] Error 404.0 after login. Asp.Net MVC and IIS 7.5
问题描述
我已经运行在IIS 7.5中一个ASP.NET MVC应用程序。
经过身份验证的启用形式
I have a ASP.NET MVC app running over IIS 7.5 . Forms Authenticated enabled
我可以访问登录页面。 (这意味着这条路线是确定的),但是当我登录的应用程序应该发个帖子的数据的http://本地主机/ tgpwebged /帐号/登录
来验证用户的身份。
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.
问题是,我的应用程序在寻找/帐号/登录的http://本地主机/帐号/登录
(这不是路径)
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.
这是我的 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>
查看
<form method="post" action="/Account/Login">
此外IIS设置为接受匿名登录用户才能够访问登录页面。
Also IIS is set to accept Anonymous login for users to be able to access the login page.
这是我收到错误消息:
TTP错误404.0 - 未找到
您正在寻找已被删除的资源,更名或暂时不可用。
TTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
部分的详细信息:
请求的URL 的http://本地主机:8081 /帐号/登录
(右路径:的http://本地主机:8081 / tgpwebged /账户/登录
)
物理路径S:\\项目\\帐户\\登录(应该是S:\\项目\\ tgpwebged \\帐户\\登录)
登录方法匿名
登录用户匿名
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
推荐答案
在POST会错误的URL,因为这是你在视图中提到。见
The POST is going to wrong URL because that is what you have mentioned in the view. See
<form method="post" action="/Account/Login">
这会一直张贴到&LT;主机名称&gt; /帐号/登录
尽量给无论是相对路径(或使用RESOLVEURL方法代替绝对路径) - 例如,在ASPX视图中,可以使用
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") %>' >
在剃刀(CSHTML)视图中,可以尝试(未经测试)
In razor (cshtml) view, you can try (untested)
<form method="post" action='@Url.Content("~/Account/Login")' >
这篇关于错误登录后404.0。 Asp.Net MVC和IIS 7.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!