【发布时间】:2020-02-02 06:45:43
【问题描述】:
我正在用 ASP.NET MVC 开发一个登录页面,但我遇到了一个问题:
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.
请求的网址: /Verify
我厌倦了自定义路线,但似乎无法修复它。 这是我这里唯一的控制器
public class HomeController : Controller
{
// GET: Home
MySqlConnection conn = new MySqlConnection();
MySqlCommand cmd = new MySqlCommand();
MySqlDataReader dr;
[HttpGet]
public ActionResult Index()
{
return View();
}
void connectionString()
{
conn.ConnectionString = "Server=localhost;Database=prodavnica;Uid=root`;Pwd=1234;Port=3306";
}
[HttpPost]
public ActionResult Verify(Account acc)
{
connectionString();
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "select * from prodavnica.vraboteni where korisnik='" + acc.Username + "'and lozinka='" + acc.Password + "' ";
if(dr.Read())
{
conn.Close();
return View("Success");
}
else
{
conn.Close();
return View();
}
}
}
} 路线配置:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
这是项目的前端,我也有一个布局,我尝试了多次,但我仍然得到同样的错误
/head>
<body>
<div class="login-form">
<form action="Verify" method="post">
<h2>Најави се</h2>
<div class="form-group">
<label>Корисник : </label>
<input type="text" name="Username" class="form-control" required="required" />
</div>
<div class="form-group">
<label>Лозинка: </label>
<input type="password" name="Password" class="form-control" required="required" />
</div>
<div class="form-group clearfix">
<button type="submit" class="btn btn-primary pull-left">
Најави се
</button>
<label class="checkbox-inline pull-left remember-me"><input type="checkbox" /> Запамти ме</label>
</div>
<div><a href="#">Проблеми со најавувањето ? </a></div>
</form>
</div>
它有一个 post 方法。
【问题讨论】:
-
请求的 url 应该有
http://yoursite/Home/Verify-- 而不仅仅是http://yoursite/Verify...正在测试哪些? -
我尝试更改 ' url: "{controller}/{action}/{id}",' 以显示主页,但我仍然收到相同的错误
-
是的,我正在通过浏览器对其进行测试。它只显示:localhost:44334/Verify
-
影响您的测试的两件事:1)您正在测试的控制器操作是一个 POST 操作,因此您无法使用浏览器对其进行测试(我最初错过了这个事实)2)即使您是控制器操作尝试测试是 GET 它仍然无法使用:
localhost:44334/Verify,因为它必须是localhost:44334/Home/Verify -
我应该更改路由配置吗?
标签: c# mysql asp.net-mvc