简体   繁体   中英

How to fix 404 'Resource cannot be found' in asp.net mvc

I am developing a login page in ASP.NET MVC and i am facing an issue:

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.

Requested URL: /Verify

I tired a custom route but it doesn't seem to fix it. This is my only controller in here

 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();

            }

    }
}

} Route config:

     routes.MapRoute(

            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

Here is the front end of the project and also i have a layout, i tried multiple times but i still get the same error

/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>

It has a post method.

I think you need to do /Verify or /Home/Verify on that form action, missing that initial slash.

If that doesn't work, Open up developer tools in chrome and on the network tab ensure it's a post request and ensure the parameter is being passed correctly as well to the action. Please post here what you see if in case you need help with that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM