This is a migrated thread and some comments may be shown as answers.

System.Web.HttpException: Response is not available in this context

8 Answers 932 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
CSurieux
Top achievements
Rank 2
CSurieux asked on 02 Sep 2009, 04:37 PM
Hello,

I get this after an exception in an ajax callback (using RadAjaxManager) when I try to redirect to an error page using
Ajax redirect.
My code
            if ( IsInAsyncPostBack && ( AjaxManager != null ) )  
            {  
                if ( url.StartsWith("~/") )  
                    url     =   ResolveClientUrl(url);  
                AjaxManager.Redirect(url);  
            }  
            else  
                Response.Redirect(url,endResponse);  
 

May be ajaxmanager should not get Page.Response but HttpContext.Current.Response ?

May be the idea of redirecting using ajax during a call back is bad ?
In this case how to incorporate ajax in my general errors manager which redirects to a standard error page.


Thanks for help
CS

8 Answers, 1 is accepted

Sort by
0
SamJ
Top achievements
Rank 1
answered on 03 Sep 2009, 05:44 AM
Hi,

Here is described how to redirect to another page with ajax:
http://www.telerik.com/help/aspnet-ajax/ajxredirectingtoanotherpage.html

And for custom error redirection, you can try setting the AllowCustomErrorsRedirect property of the ScriptManager and see how it works:
<asp:ScriptManager ID="ScriptManager1" runat="server" AllowCustomErrorsRedirect="true" /> 




Additionally, can you confirm that the code in the if statement is executed, not only this in the else block?

Regards,
SamJ
0
CSurieux
Top achievements
Rank 2
answered on 03 Sep 2009, 11:34 AM
Thanks, but I know this, I am using it regularly due to IIS7 pb with Ajax.
The effect of my code is to detect erro occuring inside a call back and to try using Ajax redirect...but the concept seems to have been shorten somewhere before completion, certainly lack of time, very common usage nowdays....

Yes I confirm that the exception occurs in RadAjaxManager, stack trace identity it as caller.

CS
0
SamJ
Top achievements
Rank 1
answered on 03 Sep 2009, 11:42 AM
Hi Christian,

In this case I assume you can try to handle the errors following the suggestions here:
http://www.telerik.com/help/aspnet-ajax/ajxerrorhandling.html

Does this work for you?

Thanks,
SamJ



0
CSurieux
Top achievements
Rank 2
answered on 03 Sep 2009, 12:36 PM
Thanks again,

Have you been there ?
when clicking on <customErrors> Element we get
http://msdn.microsoft.com/en-us/library/y123fsf7.aspx

and that's final story :)

More seriously, this process doesn't comply with my own error flow....
I would prefer Telerik not doing an access to Page property attached to scriptmanager or ajaxmanager to get Response because it is no more available at the stage I need it.
Using HttpContext.Current could work.

It could be a telerik bug .


CS
0
Mira
Telerik team
answered on 08 Sep 2009, 10:06 AM
Hi Christian,

Would you please provide us more information on your scenario and what is the desired by you functionality that can not be implemented using the RadAjaxManager?

I am looking forward to your reply.

Regards,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
CSurieux
Top achievements
Rank 2
answered on 08 Sep 2009, 10:41 AM
Hello Mira,

In my error scenario, all exceptions are trapped as soon as possible and transformed in a generic app exeption depending on context, then these exceptions are catched by the general app error handler in Global.asax, here after some analysis the response is redirected to different error pages.

When the error occurs in a postback, no pb everything works.
When error occurs during an ajax callback, I was expecting to be able to redirect from clientside using ajaxmanager redirect, but it appears that code in ajaxmanager uses the Page property to access Response.
This doesn't work because Page.Response is no more accessible (I get an exception and see from the exception stack it occurs in ajaxmanager trying to access Page.Response), it should use HttpContext.Response because it seems to be available even when Page.response is no more accessible.


Regards
CS
0
CSurieux
Top achievements
Rank 2
answered on 09 Sep 2009, 09:11 AM
Mira,

 To be more factual, here is the stack trace on exception catching:
[E]ErrorHandler ProcessUnhandledException Unexpected error, ex3 : System.Web.HttpException: Response is not available in this context.
   at System.Web.UI.Page.get_Response()
   at Telerik.Web.UI.RadAjaxControl.Redirect(String location)
....

May this help you correcting.

Regards
CS
0
Mira
Telerik team
answered on 10 Sep 2009, 03:22 PM
Hi Christian,

Unfortunately I am still unable to find out what is the issue.

Would please tell me what in the approach for Redirecting to another page and Error Handling For Ajax Requests does not work for your scenario?


Kind regards,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Ajax
Asked by
CSurieux
Top achievements
Rank 2
Answers by
SamJ
Top achievements
Rank 1
CSurieux
Top achievements
Rank 2
Mira
Telerik team
Share this question
or