如何从控制器授权asp

如何从控制器授权asp

本文介绍了如何从控制器授权asp(mvc)项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASP的新手,我为我的Web项目创建了一个登录页面,但是我设置了身份验证,但无法为我的项目设置授权!我看到了许多这样的链接身份验证ASP.NET Web API中的访问和授权但是无法在我自己的项目中实现这些功能,我不知道该从哪里开始?!谢谢您的帮助!

I'm new in asp and I created a login page for my web project but and I set authentication but I can not set authorization for my project! I saw many links like this Authentication and Authorization in ASP.NET Web APIbut couldn't implementation those on my own project, I don't know where I must to start?!thank you for your help!

这是我的控制者:

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 5 Identity model(请检查此处此处).然后,您应该通过适合您项目的任何更改来实现它.关于ASP.NET 5 Identity的最重要的事情之一是它的简单性和灵活性,可以与不同的用户类型一起使用,并且只需对方法使用批注即可实现可访问性.如果您以前有SQL Membership的经验,请检查此处,以了解如何从SQL成员身份迁移到ASP.NET Identity.或者,如果您以前有ASP.NET Membership的经验,请检查此处,以了解如何从ASP.NET成员身份迁移到ASP.NET身份.关于how say: "welcome PERSON NAME" ?上的问题,在实施ASP.NET 5 Identity之后,您只需要拥有

You need to fully understand ASP.NET 5 Identity model (Check here and here). Then you should implement that with any changes suits to your project. One of the most important things about ASP.NET 5 Identity is its simplicity and flexibility to use with different user types and accessibility with just using annotations for methods. If you have previous experience with SQL Membership, check here to find out how to Migrating from SQL Membership to ASP.NET Identity. Or if you have previous experience with ASP.NET Membership, check here to find out how to Migrate from ASP.NET Membership to ASP.NET Identity.About your question on how say: "welcome PERSON NAME" ?, after implementation ASP.NET 5 Identity, you just need to have

在任何需要的地方!

这篇关于如何从控制器授权asp(mvc)项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 10:36