次のようなコードを含む共通のHttpModuleをすべて共有するAsp.Netアプリケーションのグループがあります。
public class MyModule : IHttpModule
{
public void Dispose()
{
}
public void Init( HttpApplication context )
{
context.Error += new EventHandler( context_Error );
}
private void context_Error( object sender, EventArgs e )
{
var lastError = HttpContext.Current.Server.GetLastError();
doSomeStuffWithError(lastError);
var response = HttpContext.Current.Response;
var redirect = GetErrorRedirect(lastError);
response.Redirect(redirect, true);
}
}
これは、1つを除くすべてのアプリケーションで完全に正常に機能します。正しく動作しない場合は、response.Redirect(...)が動作していないようです。私が期待するリダイレクトの代わりに、Asp.Netは標準のエラーページにリダイレクトしています。このアプリケーションの構成を確認しましたが、他のアプリケーションとの違いや大きな違いは見られません。
この問題を調査しているときに、次のようにもう1行のコードでエラーハンドラーを変更しました。
private void context_Error( object sender, EventArgs e )
{
var lastError = HttpContext.Current.Server.GetLastError();
doSomeStuffWithError(lastError);
var response = HttpContext.Current.Response;
var redirect = GetErrorRedirect(lastError);
//setting a break point here, i've verified that 'redirect' has a value in all cases
response.Redirect(redirect, true);
var wtf = response.RedirectLocation;
//inspecting the value of 'wtf' here shows that it is null for one application, but equal to 'redirect' in all others.
}
'wtf'にブレークポイントを設定すると、奇妙な動作が見られます。動作するアプリケーションの場合、wtfにはリダイレクトと同じ値が含まれます。ただし、機能していない私のアプリの場合、wtfはnullです。
誰かがこのようにwtfがnullになる原因について何か考えがありますか?