Castle Coreを使用してカスタム属性とインターセプタを作成し、属性を使用してコードにセキュリティチェックを挿入しています。例: [セキュリティ(「ROLE1」)]インターセプタの実装では私は傍受しているオブジェクトにどのようにアクセスできますか?
:上記の「いくつかのセキュリティテストを行う」セクションで
public class SecurityInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
object o;
MethodInfo mi = invocation.Method;
SecurityAttribute[] atts = (SecurityAttribute[])mi.GetCustomAttributes(typeof(SecurityAttribute), true);
// if method not marked with Security attribute, then pass on call
if (atts.Length == 0)
{
invocation.Proceed();
}
else
{
//for now assume that there is only one security attribute on the method
//do some security test
{
invocation.Proceed();
}
}
}
は、私が取得するためにHttpContext.Sessionオブジェクトにアクセスする必要がありますいくつかのオブジェクトを保存してセキュリティテストを行います。
コードビハインドasp.netページ、すなわちPageクラスのインスタンスであると仮定します。 this.Contextをこのような属性で使用することはできません。[Security( " Role1 "、this.Context)]属性として は許可していません。
したがって、Interceptメソッド内のhttpContextにアクセスするにはどうすればよいですか?
また、アスペクトのようなやり方でこれを行うより良い方法がありますか?
sidenote(おそらくそれはポストを再編集する価値があります)@ mookid8000 - FactorySupportFacilityは 'UsingFactoryMethod'では必要ありません(旧バージョンのウィンザー)。ファシリティは、XMLを使用してファクトリを指定する場合など、従来のシナリオでのみ有効です。 –
@ Krzysztof私はそれを知らなかった - ありがとう!私はそれに応じて答えを編集しました。 – mookid8000