通常、通常のaspx
ファイルでは、次System.Attribute
のようにページの先頭で使用できます。
[AuthorizePage()]
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
public class AuthorizePage : System.Attribute
{
public AuthorizePage()
{
//do some stuff to authorize
}
}
また、ページが初期化される前に、属性のコンストラクターが実行され、ユーザーが現在ログインしていることを確認するために何らかの処理が行われます。それ以外の場合、属性コンストラクターはユーザーをログイン ページにリダイレクトします。
HttpHandler
(ashx
ファイル)でも同じことをしたかったのですが、ashx ページでは属性が初期化されません。
[AuthorizePage()]
public class AjaxHandler : MuCustomClassBase, IHttpHandler, IReadOnlySessionState
{
//The interface implementations and some other custom private methods
}
ashx
このページに AJAX 呼び出しを行います。これが属性が実行されない理由でしょうか? または、他に知っておくべきことはありますか?
最終的に、カスタム System.Attribute を ashx ファイルに対して実行する方法を知りたいです。