how authorization asp(mvc) project from controller?

无人久伴 提交于 2019-12-02 11:33:52

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

System.Web.HttpContext.Current.User.Identity.Name

in where ever you need!.

If you want authorization on your whole controller, just set the Authorize attribute on your controller:

[Authorize]
public class AuthenticationController : Controller
{

}

If you want authorization on a sigle action:

public class AuthenticationController : Controller
{
    [Authorize]
    public ActionResult Index()
    {
        ViewBag.Message = "Welcome, " + HttpContext.User.Identity.Name;
    }
}

EDIT: Only authenticated users will be able to navigate through authorized methods or controllers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!