我必须实现自定义授权过滤器。
(检查Is Authorized,需要Namespace、Controller Name和Action Name)
我没有设法获取命名空间。这是我的代码:
示例控制器.cs:
namespace ExampleProject.Controllers
{
public class ExampleController : Controller
{
[CustomAuth()]
public string Index()
{
return "OK";
}
}
}
CustomAuthFilter.cs:
namespace ExampleProject.Infrastructure.Filters
{
public class CustomAuthAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
string currentNamespace = string.Empty;
string currentController = string.Empty;
string currentAction = string.Empty;
var routeData = httpContext.Request.RequestContext.RouteData;
currentController = routeData.GetRequiredString("controller"); //Example
currentAction = routeData.GetRequiredString("action"); //Index
currentNamespace = How??????? // ExampleProject.Controllers
...
}
}
}
如何获得命名空间?
提前谢谢了。