簡體   English   中英

如何在ASP.NET MVC中的控制器中為特定用戶提供操作方法的訪問權限

[英]How to provide access of action methods for particular user in a controller in asp.net mvc

在這里,假設我們有兩個用戶User1和User2,並且控制器中有兩種操作方法,

  public class HomeController:Controller
   {

     public ActionResult Method1()
     {
       return View();
     }

     public ActionResult Method2()
     {
       return View();
     }
   }

對於user1,我想提供兩種方法的訪問權限,對於user2,我只想提供訪問方法1。

在MVC中怎么可能? 請任何人幫助我嗎?

您可以使用Authorize屬性並可以如下裝飾代碼:

public class HomeController:Controller
   {

     public ActionResult Method1()
     {
       return View();
     }

     [Authorize(Users="user1")]
     public ActionResult Method2()
     {
       return View();
     }
   }

更多細節 :-

http://msdn.microsoft.com/zh-CN/library/system.web.mvc.authorizeattribute.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM