Я создал приложение CRUD, у него есть страница входа. но когда я сделал это, я не стал включать авторизацию пользователей. Может ли кто-нибудь показать мне, как включить роли и разрешения пользователей в приложение MVC после его создания, чтобы я мог затем раскрывать только некоторые функции для определенных пользователей?
Это мой контроллер входа в систему
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=LAPTOP-JK299B2R" + "\\" + "SQLEXPRESS; database=Coaching-Database; integrated security = SSPI";
}
[HttpPost]
public ActionResult Verify(Account acc)
{
connectionString();
con.Open();
com.Connection = con;
com.CommandText = "select * from loginpage where username='"+acc.Name+"' and password='"+acc.Password+"'";
dr = com.ExecuteReader();
Session["username"] = acc.Name;
if(dr.Read())
{
con.Close();
return View("Create");
}
else
{
con.Close();
return View("Error");
}
}
}
}
И моя страница входа
@{
ViewBag.Title = "Login";
Layout = "~/Views/_LayoutPage1.cshtml";
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
}
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("RCC Coaching Database", "Default", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("ViewDetails", "Index", "AthleteDetailC")</li>
<li>@Html.ActionLink("Login", "Login", "Account")</li>
</ul>
</div>
</div>
</div>
<body id="bootstrap-overrides" style="background-color: white;" >
<h1 style="color: black">Login Page</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 style="color: black"><i class="fa fa-user" aria-hidden="true"></i> Username </label>
<input style="color: black" type="text" name="Name" placeholder="Enter User Name" required="" />
</div>
<div class="agile-field-txt">
<label style="color: black"><i class="fa fa-unlock-alt" aria-hidden="true"></i> password </label>
<input style="color: black" type="password" name="Password" placeholder="Enter Password" required="" id="myInput" />
<div class="agile_label">
<input style="color: black"id="check3" name="check3" type="checkbox" value="show password" onclick="myFunction()">
<label style="color: black" class="check" for="check3">Show password</label>
</div>
<div class="agile-right">
<a style="color: black" 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-->
</body>