在asp.net mvc中以编程方式授权用户

时间:2014-03-14 16:30:58

标签: c# asp.net asp.net-mvc authentication authorization

我需要以编程方式授权用户。

我的控制器周围有authorize属性:

  [Authorize]
  public class ProductsController : Controller

在另一个控制器操作中,我调用了一个webservice,如果成功则返回一个帐号。如果没有,它将返回错误。基本上如果if条件为真,我想在网站的其余部分授权用户。

 if (!string.IsNullOrEmpty(response.AccountNumber))
 {
   //Write code to Authorize user to use the rest of the site...
   then redirect to a page on my site.
 }else
 {
  //not authorized,
 }

该网站的用户将是管理员。

由于

1 个答案:

答案 0 :(得分:1)

老问题,但由于这里除了蟋蟀之外什么都没有,我想我会把来到这里的任何人重新定位到question,这似乎做得很好,涵盖了这个话题。