Merhaba MVC login sayfası yapmaya çalışıyorum ve veri tabanındaki tablomda tuttuğum username ve password’u girip giriş yap dediğimde aşağıdaki resimdeki hata karşıma çıkıyor nasıl çözebilirim?
Not= Kodlarımı aşağıya ekliyorum.
- login.cshtml Sayfası
@{
ViewBag.Title = "Login";
Layout = "~/Views/_LayoutPage1.cshtml";
}
<h1>Spin Login Form </h1>
<div class="clear-loading spinner">
<span></span>
</div>
<div class="w3ls-login box box--big">
<!-- form starts here -->
<form action="Verify" method="post">
<div class="agile-field-txt">
<label><i class="fa fa-user" aria-hidden="true"></i> Username </label>
<input type="text" name="Name" placeholder="Enter User Name" required="" />
</div>
<div class="agile-field-txt">
<label><i class="fa fa-unlock-alt" aria-hidden="true"></i> password </label>
<input type="password" name="Password" placeholder="Enter Password" required="" id="myInput" />
<div class="agile_label">
<input id="check3" name="check3" type="checkbox" value="show password" onclick="myFunction()">
<label class="check" for="check3">Show password</label>
</div>
<div class="agile-right">
<a href="#">forgot password?</a>
</div>
</div>
<!-- script for show password -->
<script>
function myFunction() {
var x = document.getElementById("myInput");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
<!-- //end script -->
<input type="submit" value="LOGIN">
</form>
</div>
<!-- //form ends here -->
<!--copyright-->
<div class="copy-wthree">
<p>
© 2018 Spin Login Form . All Rights Reserved | Design by
<a href="http://w3layouts.com/" target="_blank">W3layouts</a>
</p>
</div>
<!--//copyright-->
- Create.cshtml Sayfası
@{
ViewBag.Title = "Create";
Layout = "~/Views/_LayoutPage1.cshtml";
}
<h2>Login Successfully</h2>
- Error.cshtml Sayfası
@{
ViewBag.Title = "Error";
Layout = "~/Views/_LayoutPage1.cshtml";
}
<h2>Something Wrong</h2>
3 ) _LayoutPage Sayfası
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<link href="~/styles/font-awesome.css" rel="stylesheet" />
<link href="~/styles/style.css" rel="stylesheet" />
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
4 ) Account.cs Sayfası
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Login_MVC_.Models
{
public class Account
{
public string Name { get; set; }
public string Password { get; set; }
}
}
4 ) AccountController.cs Sayfası
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Login_MVC_.Models;
using System.Data.SqlClient;
namespace Login_MVC_.Controllers
{
public class AccountController : Controller
{
SqlConnection con = new SqlConnection();
SqlCommand com = new SqlCommand();
SqlDataReader dr;
// GET: Account
[HttpGet]
public ActionResult Login()
{
return View();
}
void connectionString()
{
con.ConnectionString="data source=DESKTOP-LIPBFQF; database=LoginDb; 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");
}
}
}
}