Add the actual filters interface signatures,
Add the AuthorizationFilterAttribute
This commit is contained in:
parent
75bccbae21
commit
457016a6da
|
|
@ -1,4 +1,6 @@
|
||||||
using Microsoft.AspNet.Mvc;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Mvc;
|
||||||
using MvcSample.Models;
|
using MvcSample.Models;
|
||||||
|
|
||||||
namespace MvcSample
|
namespace MvcSample
|
||||||
|
|
@ -7,6 +9,8 @@ namespace MvcSample
|
||||||
// TODO: Add a real filter here
|
// TODO: Add a real filter here
|
||||||
[ServiceFilter(typeof(object), Order = 1)]
|
[ServiceFilter(typeof(object), Order = 1)]
|
||||||
[ServiceFilter(typeof(string))]
|
[ServiceFilter(typeof(string))]
|
||||||
|
[PassThrough(Order = 0)]
|
||||||
|
[PassThrough(Order = 2)]
|
||||||
public class FiltersController : Controller
|
public class FiltersController : Controller
|
||||||
{
|
{
|
||||||
private readonly User _user = new User() { Name = "User Name", Address = "Home Address" };
|
private readonly User _user = new User() { Name = "User Name", Address = "Home Address" };
|
||||||
|
|
@ -18,4 +22,12 @@ namespace MvcSample
|
||||||
return View("MyView", _user);
|
return View("MyView", _user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PassThroughAttribute : AuthorizationFilterAttribute
|
||||||
|
{
|
||||||
|
public async override Task Invoke(AuthorizationFilterContext context, Func<AuthorizationFilterContext, Task> next)
|
||||||
|
{
|
||||||
|
await next(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
||||||
|
public abstract class AuthorizationFilterAttribute : Attribute, IFilter, IAuthorizationFilter
|
||||||
|
{
|
||||||
|
public abstract Task Invoke(AuthorizationFilterContext context, Func<AuthorizationFilterContext, Task> next);
|
||||||
|
|
||||||
|
public int Order { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Microsoft.AspNet.Mvc.Filters;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc
|
||||||
|
{
|
||||||
|
public interface IActionFilter : IFilter<ActionFilterContext>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Microsoft.AspNet.Mvc.Filters;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc
|
||||||
|
{
|
||||||
|
public interface IActionResultFilter : IFilter<ActionResultFilterContext>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Microsoft.AspNet.Mvc.Filters;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc
|
||||||
|
{
|
||||||
|
public interface IAuthorizationFilter : IFilter<AuthorizationFilterContext>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Microsoft.AspNet.Mvc.Filters;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc
|
||||||
|
{
|
||||||
|
public interface IExceptionFilter : IFilter<ExceptionFilterContext>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc.Filters
|
||||||
|
{
|
||||||
|
public interface IFilter<T>
|
||||||
|
{
|
||||||
|
Task Invoke(T context, Func<T, Task> next);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue