Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I'm new to ASP MVC, I have a simple question for my login page routing, i got stuck on authentication routes. Could you help me please.

When I attempt to login, it shows:

Server Error in '/' Application.
The resource cannot be found.
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

What I have tried:

AccountController:

[HttpGet]
public ActionResult Login()
{
return View();
}
void connectionString()
{
con.ConnectionString = @"Data Source=.\SQLEXPRESS; Database=WPF; Integrated Security=SSPI";
}
[HttpPost]
public ActionResult Verify(Account acc)
{

connectionString();
con.Open();
com.Connection = con;
com.CommandText = "SELECT * FROM tbl_login where username = '" + acc.Name + "' AND password = '" + acc.Password + "'";
dr = com.ExecuteReader();
if (dr.Read())
{
con.Close();
return View("Create"); }
else
{
con.Close();
return View("Error"); }

RouteConfig.cs

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


routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Posted
Comments
Richard Deeming 2-Apr-20 8:10am    
You're also storing password in plain text. Don't do that.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
Richard Deeming 2-Apr-20 8:11am    
I'd recommend you use one of the pre-built authenticatoin libraries instead. For example:
ASP.NET Identity[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900