如何在MVC中实现身份验证和授权? [英] How to implement Authentication and Authorization in MVC?
问题描述
如何在MVC中实现身份验证和授权?
我用它作为 -
public ActionResult默认值()
{
if(Session [UserId] == null)
{
Session.Abandon();
返回RedirectToAction(登录,登录);
}
else
{
返回查看();
}
}
成功登录后,重定向主控制器和操作 - 默认。
这里我检查会话用户ID值,如果它为null然后转到登录控制器并调用登录方法。
我知道在mvc中有一个名为Authenticate的属性,但我不知道如何使用它。
Plz给我解决方案和代码。
谢谢..
Ashish
How to implement Authentication and Authorization in MVC?
I have used it as-
public ActionResult Default()
{
if (Session["UserId"] == null)
{
Session.Abandon();
return RedirectToAction("Login", "Login");
}
else
{
return View();
}
}
After successfully logging, redirects on Home controller and action - Default.
Here i am check session userid value if it is null then go to Login controller and invoke login method.
I know that in mvc there is a attribute named as Authenticate but i am not aware how to use it.
Plz give me solution and code.
Thanks..
Ashish
推荐答案
要获得有关授权和身份验证的简要知识,这些链接可能会有所帮助。
http://www.dotnet-tricks.com/Tutorial/mvc /G54G220114-Custom-Authentication-and-Authorization-in-ASP.NET-MVC.html [ ^ ]
http://msdn.microsoft.com/en-us/library /vstudio/wce3kxhd(v=vs.100).aspx [ ^ ]
:)
To have a brief knowledge on Authorization and Authentication these links may be helpful.
http://www.dotnet-tricks.com/Tutorial/mvc/G54G220114-Custom-Authentication-and-Authorization-in-ASP.NET-MVC.html[^]
http://msdn.microsoft.com/en-us/library/vstudio/wce3kxhd(v=vs.100).aspx[^]
:)
这篇关于如何在MVC中实现身份验证和授权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!