1
我想在动态代理拦截器方法中找到控制器和动作名称 我检查堆栈跟踪接近不好的方式beacase它不是最后堆栈 这是我的代码获取方法城堡windsor拦截器方法中的来电者(控制器名称和动作名称)
全球ASAX城堡配置
IWindsorContainer ioc = new WindsorContainer();
ioc.Register(
Component.For<IMyService>().DependsOn()
.ImplementedBy<MyService>()
.Interceptors<MyInterceptor>()
.LifeStyle.PerWebRequest);
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(ioc));
ioc.Register(
Component.For<IInterceptor>()
.ImplementedBy<MyInterceptor>());
控制器类
private IMyService _service;
public HomeController(IMyService service)
{
_service = service;
}
public ActionResult Index()
{
_service.HelloWorld();
return View();
}
服务类
public class MyService : IMyService
{
public void HelloWorld()
{
throw new Exception("error");
}
}
public interface IMyService
{
void HelloWorld();
}
拦截器类
//i want to find Controller name
public class MyInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
//?? controller name ?? method Name
invocation.Proceed();
}
}
感谢你在我loggingInterceptor
获取类名和方法名,但我想主叫类名称,而不是调用的类和方法方法 !我使用企业库实例的城堡并正常工作 – ARA 2013-05-06 15:13:36