我在asp.net mvc3项目上工作。我正在使用autofac进行DI。 我有一个属性说autofac mvc3属性注入
public class MustBeLoggedInAttribute : ActionFilterAttribute
{
private IUserContext Context {get;set;}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!Context.IsLoggedIn)
filterContext.Result = new RedirectResult("https://stackoverflow.com/users/logon");
base.OnActionExecuting(filterContext);
}
}
所以我需要我的依赖IUserContext注入到这个属性。 我将如何实现它。我发现代码在这里和那里actionfiterprovider, 但无法找到任何完整的。
帮助将不胜感激。
问候
成员Parminder
的'AuthorizeAttribute'做了你想做的事,也没有地方'Autofac'注入的属性创建过程特性。 – Eranga
Eranga - AuthorizeAttribute适用于基本授权,但在基本任何事情之后都会落空。 – Phill
你们没有明白这一点。我在询问有关注射剂的信息,可以用于其他目的。这里的代码只是一个例子。 – Parminder