asp.net-mvc-filters

Register global filters in ASP.Net MVC 4 and Autofac

旧城冷巷雨未停 提交于 2019-12-17 22:36:01
问题 I have a filter like this one: public class CustomFilterAttribute : ActionFilterAttribute, IAuthorizationFilter { public MyPropery Property { get; set; } .... } I need it to be run for every actions in my project I tried to register it in the GlobalFilters but my property doesn't get injected I tried This solution to register my filter but it doesn't get called Any idea on how to do that? 回答1: There's a new way of registering MVC global filters in AutoFac. First, remove the filter

How does one get a list of authorization filters that have been applied to a particular controller action?

不羁岁月 提交于 2019-12-11 03:36:03
问题 In an asp.net MVC application , a colleague is trying to build a role dependent set of UI elements in the web site's layout control, and my colleague wants to make an html extension that appears or doesn't based on the user's role relationship. The colleague wants to be able to test the action that a particular link is linking to and check to see if the user is authorized to even visit that link. In order to do this it would be nice to run all of the authorization filters against the

filters.Add vs FilterProviders.Providers.Add

让人想犯罪 __ 提交于 2019-12-06 07:27:47
问题 I came across a sample MVC3 code which had following in the Global.asax file: public static void RegisterGlobalFilters(....) { filters.Add(new MyFilter1()); .... var provider = new MyFilterProvider(); provider.Add(c => c.HttpContext.IsDebuggingEnabled ? new MyProvider2() : null); FilterProviders.Providers.Add(provider) } Both MyProvider1 and MyProvider2 are implemented with IResultFilter , and I am confused why one of them is added to FilterProviders and the other one is registered as a

filters.Add vs FilterProviders.Providers.Add

自古美人都是妖i 提交于 2019-12-04 13:36:10
I came across a sample MVC3 code which had following in the Global.asax file: public static void RegisterGlobalFilters(....) { filters.Add(new MyFilter1()); .... var provider = new MyFilterProvider(); provider.Add(c => c.HttpContext.IsDebuggingEnabled ? new MyProvider2() : null); FilterProviders.Providers.Add(provider) } Both MyProvider1 and MyProvider2 are implemented with IResultFilter , and I am confused why one of them is added to FilterProviders and the other one is registered as a global filter. Why and when should we add custom filters on FilterProvider , and why and when should we

Enabling SSL in ASP.NET MVC 5 app results in OpenIdConnectProtocolValidator issue

大城市里の小女人 提交于 2019-12-03 07:24:39
问题 I have an ASP.NET MVC 5 app that authenticates against Azure Active Directory. I wanted to enable SSL on it across the app. and hence leveraged global filters as follows: public class FilterConfig { /// <summary> /// Registers the global filters. /// </summary> /// <param name="filters">The filters.</param> public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new RequireHttpsAttribute()); } } After this I also set 'Enable SSL' in the project's properties to

Register global filters in ASP.Net MVC 4 and Autofac

做~自己de王妃 提交于 2019-11-28 18:38:19
I have a filter like this one: public class CustomFilterAttribute : ActionFilterAttribute, IAuthorizationFilter { public MyPropery Property { get; set; } .... } I need it to be run for every actions in my project I tried to register it in the GlobalFilters but my property doesn't get injected I tried This solution to register my filter but it doesn't get called Any idea on how to do that? Pete There's a new way of registering MVC global filters in AutoFac. First, remove the filter registration from your RegisterGlobalFilters because we will have Autofac handle adding them to our controllers

IFilterProvider and separation of concerns

自古美人都是妖i 提交于 2019-11-27 07:54:05
I have a situation where I need to inject some dependencies in a action filter, namely, my custom authorization provider in my custom authorization attribute. I stumbled upon a lot of people and posts who were saying that we should be separating the 'attribute metadata' from the 'behavior'. This makes sense and there is also the fact that filter attributes are not instantiated through the 'DependencyResolver' so it is difficult to inject the dependencies. So I did a little refactoring of my code and I wanted to know if I had it right (I'm using Castle Windsor as the DI framework). First off I

IFilterProvider and separation of concerns

走远了吗. 提交于 2019-11-26 13:53:19
问题 I have a situation where I need to inject some dependencies in a action filter, namely, my custom authorization provider in my custom authorization attribute. I stumbled upon a lot of people and posts who were saying that we should be separating the 'attribute metadata' from the 'behavior'. This makes sense and there is also the fact that filter attributes are not instantiated through the 'DependencyResolver' so it is difficult to inject the dependencies. So I did a little refactoring of my