我正在 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.
请求的URL:/验证
我厌倦了一条自定义路线,但它似乎并没有解决它。 这是我这里唯一的 Controller
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 方法。
最佳答案
我认为您需要在该表单操作上执行/Verify 或/Home/Verify,缺少初始斜杠。
如果这不起作用,请在 chrome 中打开开发人员工具,并在网络选项卡上确保它是一个发布请求,并确保参数被正确传递给操作。如果您需要帮助,请在此处发布您看到的内容。
关于c# - 如何在 asp.net mvc 中修复 404 'Resource cannot be found',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58227752/