【发布时间】:2016-11-02 20:25:25
【问题描述】:
我是 asp 新手,我为我的 web 项目创建了一个登录页面,但我设置了身份验证,但我无法为我的项目设置授权!我看到很多这样的链接Authentication and Authorization in ASP.NET Web API 但无法在我自己的项目中实现这些,我不知道我必须从哪里开始?! 谢谢你的帮助!
这是我的控制器:
public class AuthenticationController : Controller
{
private modelLayOut mLO = new modelLayOut();
public bool existBool = false;
// GET: Authentication
public ActionResult Index()
{
return View();
}
public ActionResult applicantAuthentication()
{
return View("ApplicantAuthentication");
}
public ActionResult applicantIsExist()
{
return View("applicantIsExist");
}
public ActionResult applicantPassIsWrong()
{
return View("applicantPassIsWrong");
}
public ActionResult applicantNotExist()
{
return View("applicantNotExist");
}
[HttpPost]
public ActionResult applicantCreate(string Username, string Password, string RepeatPassword)
{
if (mLO.applicantExistCheck(Username))
{
return View("applicantIsExist");
}
else
{
mLO.insertNewApplicant(Username, Password);
return View("ApplicantAuthentication");
}
}
[HttpPost]
public ActionResult applicantAccess(string Username, string Password)
{
if (mLO.applicantAccess(Username, Password))
{
return RedirectToAction("Home", "Home");
}
else
{
if (mLO.applicantExistCheck(Username))
{
return View("applicantPassIsWrong");
}
else
{
return View("applicantNotExist");
}
}
}
//agency part
public ActionResult agencyAuthentication()
{
return View("AgencyAuthentication");
}
public ActionResult agencyPassIsWrong()
{
return View("agencyPassIsWrong");
}
public ActionResult agencyNotExist()
{
return View("agencyNotExist");
}
[HttpPost]
public ActionResult agencyAccess(string Username, string Password)
{
if (mLO.agencyAccess(Username, Password))
{
return RedirectToAction("Home", "Home");
}
else
{
if (mLO.agencyExistCheck(Username))
{
return View("agencyPassIsWrong");
}
else
{
return View("agencyNotExist");
}
}
}
//webAdmin
public ActionResult webAdminAuthentication()
{
return View("WebAdminAuthentication");
}
public ActionResult webAdminAccessWrong()
{
return View("webAdminAccessWrong");
}
[HttpPost]
public ActionResult webAdminAccess(string Username, string Password)
{
if (mLO.webAdminAccess(Username, Password))
{
Session["Username"] = Username;
return RedirectToAction("webAdminPage", "Admin");
}
else
{
return View("webAdminAccessWrong");
}
}
【问题讨论】:
标签: asp.net-mvc login asp.net-mvc-5 asp.net-authorization