mvc4 と c# を使用して Web サイトを構築しています。管理コントローラーがあります。そのコントローラーを認証したい。
管理者インデックス ページにログインする方法に基づいて、SQL db テーブル ユーザー (User_NA、User_pwd、および User_role を含む) があります。
[Authorize]
public ActionResult Index(string id="")
{
ViewBag.Admin = id;
return View();
}
ログインとログアウトのアクションがあります。
[HttpGet]
public ViewResult Login()
{
return View();
}
[HttpPost]
public RedirectResult Login(FormCollection form)
{
string uid = Request.Form["userid"];
string pwd = Request.Form["password"];
...............................
else return Redirect("~/Admin/Login");
}
public RedirectResult Logout()
{
System.Web.Security.FormsAuthentication.SignOut();
return Redirect("~/Admin");
}
ログイン アクションに認証コードを書き込むにはどうすればよいですか? また、Web.Config ファイルまたはその他のファイルに変更はありますか?