filterattribute

Need some help with a custom ASP.NET MVC IExceptionFilter

删除回忆录丶 提交于 2019-12-11 09:53:31
问题 i'm trying to make my own ExceptionFilter. Out of the box, ASP.NET MVC comes with the [HandleError] attribute. This is great -> but it returns some html error View. As such, I'm wanting to return some json error message. So i'm making my own. Now, everything works great until i test my url. I keep getting an error. this is the message.... C:\Temp\curl-7.19.5>curl -i http://localhost:6969/search/foo?name=1234&key=test1xxx HTTP/1.1 401 Unauthorized Server: ASP.NET Development Server/9.0.0.0

MVC/Unity - How to inject dependencies into custom FilterAttributes?

大兔子大兔子 提交于 2019-12-08 18:03:02
问题 I Have a custom HandleErrorAttribute that extends FilterAttribute . How can I have Unity inject dependencies into this attribute at the same time that it injects the controller's dependencies itself? 回答1: Ok, figured it out. Mostly I used Ben's solution above from the blog post he pointed to. The problem is that Unity behaves a little differently. You can't inject dependencies on the filters directly, because they are of type IActionFilter and IExceptionFilter respectively. This led me to

Is it possible to use Dependency Injection/IoC on an ASP.NET MVC FilterAttribute?

别等时光非礼了梦想. 提交于 2019-12-08 02:43:35
问题 I've got a simple custom FilterAttribute which I use decorate various ActionMethods . eg. [AcceptVerbs(HttpVerbs.Get)] [MyCustomFilter] public ActionResult Bar(...) { ... } Now, I wish to add some logging to this CustomFilter Action .. so being a good boy, I'm using DI/IoC ... and as such wish to use this pattern for my custom FilterAttribute . So if i have the following... ILoggingService and wish to add this my custom FilterAttribute .. i'm not sure how. Like, it's easy for me to do the

Is it possible to use Dependency Injection/IoC on an ASP.NET MVC FilterAttribute?

早过忘川 提交于 2019-12-06 08:09:12
I've got a simple custom FilterAttribute which I use decorate various ActionMethods . eg. [AcceptVerbs(HttpVerbs.Get)] [MyCustomFilter] public ActionResult Bar(...) { ... } Now, I wish to add some logging to this CustomFilter Action .. so being a good boy, I'm using DI/IoC ... and as such wish to use this pattern for my custom FilterAttribute . So if i have the following... ILoggingService and wish to add this my custom FilterAttribute .. i'm not sure how. Like, it's easy for me to do the following... public class MyCustomFilterAttribute : FilterAttribute { public MyCustomFilterAttribute