ラベル similar の投稿を表示しています。 すべての投稿を表示
ラベル similar の投稿を表示しています。 すべての投稿を表示

2012年3月26日月曜日

Response.Redirect not working in RC version

I am trying to use Response.Redirect in the RC version of AJAX but it is returning an error. I have found a similar post to this issue and it discusses Beta2 vs RC references. I have ensured that all of my references are pointing to the System.Web.Extensions for the RC release yet the problem still exists.

Any ideas as to how I can fix this issue? Sorry if this is repeated, I just didn't find a clear response in the other posts.

But, what's the error? Can you post it?

The error is:

Sys.WebForms.PageRequestManagerParserException: The message received from the server could not be parsed... Error parsing near '<!DOCTYPE html PUB'

My code basically performs a Response.Redirect to another page in the site when a certain condition is met. I am using the AJAX Update Panel and various button control triggers that are all working fine.


You can't place Redirect in partial postback.

PageRequestManagerParserException waits for data from UpdatePanels (for example in JSON format, but I'm not sure), but you Redirect gives another data. In you case it like that redirect doing at server and PageRequestManagerParserException gets new page.

You must do redirect with some javascripts.

You have 2 ways:

1) use my evalscripts.js (it extends UpdatePanels, that it can evaluate javascripts, so you can put window.open('xxxyyy.aspx','_top') in some Literal in Label, and it works)

2) use ScriptManager.RegisterClientScript static method. On this forum is very many messages about it. Try to search. (and yes, you also do it throught javascript's window.open)

And of course try to read documentation. Maybe something changed in RC1 and there are some new methods for redirect. I don't know.


Something at you end is not set up well. Check this to make sure everything checks uphttp://ajax.alpascual.com/Walkthrough/AtlasToAspNetAjax.aspx

jriell:

Thanks for the feedback. Where can I obtain your evalscripts.js?

You can download all this from http://ajax.asp.net


Thanks for the feedback. Where can I obtain your evalscripts.js?

Thank You.

As a followup on the problem I had. I did omit something from the web.config of my site. After adding this element to the web.config, the Response.Redirect code that I have started working. It seems as though this functionality does work in the RC version at least.


jriell:

Thank You.

As a followup on the problem I had. I did omit something from the web.config of my site. After adding this element to the web.config, the Response.Redirect code that I have started working. It seems as though this functionality does work in the RC version at least.

Can you say what you add to web.config? Just interesting.

ps. this is work in RC1 ?


albertpascual:

jriell:

Thanks for the feedback. Where can I obtain your evalscripts.js?

You can download all this from http://ajax.asp.net

this is my own script, and there are now way to obtain it from ajax.asp.net , it can be found athttp://forums.asp.net/thread/1465522.aspx

ResponseFilter & Content-Encoding header, cleared by WriteExceptionJsonString

Hi There,

I have a ResponseFilter adding HTTP compression to my .aspx, ashx, and now .asmx requests, similar to http://blog.madskristensen.dk/post/HTTP-compression-in-ASPNET-20.aspx.

I've just starting using it to compress the web services in a project, which has worked great reducing the traffic immensely. To do this, I've added a response filter to the Response object, and set the "Content-Encoding" header to "gzip". Works great for normal pages and "MyService.asmx/js" requests as well.

Normally, when an exception is thrown inside a web service, the exception is serialised, passed along to the client, and handled by the error callback in javascript code. No worries there.

The error handling stopped working after added the compression as a response filter to the .asmx/js requests. It turns out that the method handles the error "WriteExceptionJsonString" found in "System.Web.Script.Services.RestHandler" clears the response headers before it serialises the exception. This isn't too bad in itself, but the response filter is still in place, so the gzip compression is still used, but now the client consuming the request doesn't know it needs decoding and a javascript error then occurs "result has no properties"

line 4860, result = new Sys.Net.WebServiceError(false, result.Message, result.StackTrace, result.ExceptionType);

Is there a way around this, while still allowing the compression? Or is this some kind behavioral bug in the underlying MS AJAX Rest handler? If theSystem.Web.Script.Services.RestHandler clears the headers... and the content... should it also remove any response filters?

I had a brain wave shortly after posting the previous message.

The HTTP Module I am using did all the Response.Filter setup in the PreRequestHandlerExecute event. That included the Response.AppendHeader("Content-Encoding", "gzip"). The header was subsequently cleared by the System.Web.Script.Services.RestHandler.WriteExceptionJsonString method, but the filter still compress the output stream.

So instead, I moved the Response.AppendHeader("Content-Encoding", "gzip") into the PreSendRequestHeaders event. Now the header gets set correctly for the Response.Filter GZipStream just before the headers are sent.

Hope that helps someone else.