HttpResponseExtensions の機能を拡張する HttpResponseExtensions クラスがあります。AJAX Requests でユーザーをリダイレクトするメソッドを追加したいと考えています。ここにチェックを行う私の方法があります:
public static void RedirectUser(this HttpResponse response, string url)
{
if (response.IsRequestBeingRedirecting())
return;
var context = HttpContext.Current;
if (context != null)
{
context.ApplicationInstance.CompleteRequest();
}
if (context != null && context.Request.IsAjaxRequest())
{
context.Items["IsRedirecting"] = true;
RegisterRedirectScript(response,url);
}
else
{
response.Redirect(url, false);
}
}
そして、ここに RegisterRedirectScript メソッドの実装があります
public static void RegisterRedirectScript(this HttpResponse response, string url)
{
var context = HttpContext.Current;
if (context != null)
{
context.Response.Write(string.Format("<script type='text/javascript'>window.location.href = '{0}';</script>", url));
}
}
セッションが無効になっているときに RedirectUser を呼び出しています。ただし、リクエストが ajax one の場合: 次のエラーが表示されます。
The Message recived from the server could not be parsed. Common causes for this error are the response is modified calls to response.write(), response details , HttpModule, OR server trace is enabled. Error detailes next to : window.locat.
radAjaxManager、ClientScriptManager、または ScriptManager を使用してスクリプトを登録できることはわかっています。しかし、HttpResponse クラスに対してはどうすればよいでしょうか?
どんな助けでも大歓迎です。