Showing posts with label request. Show all posts
Showing posts with label request. Show all posts

Wednesday, March 28, 2012

Accessing Request headers from asp.net web service, invoked using Ajax

I need a small help.

I have a web service, in which I have a web method, which detects the browser locale using asp.net request object.

If I invoke the web service directly from the browser, I am able to get the browser language from Request object'sHTTP_ACCEPT_LANGUAGEheader.

But If I invoke the same web method from some aspx using javascript XMLHttpRequest, I always get the request headerHTTP_ACCEPT_LANGUAGE null.

Is this the behavior of the web services.

Then how can I access the browser language setting for the current request in the web service.

Is there a way to invoke the web service with the same request settings as that of aspx page while using xmlhttp.

Thanks in Advance

Hi,

I saw that you got this issue answered byJohn Saunders athttp://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2341086&SiteID=1, Here is quotation:

You are unlikely to receive a browser language setting if the web service is not called from a browser.

Saturday, March 24, 2012

Abort aysnc request when user clicks a menu link on the web page

Hi,

I've got my web page working with ASP.NET AJAX but the problem is when I click a link on pages menu I don't get taken to the new page until the page I'm on has received all the async. data from the server.

So, I need to know how to abort the async. requests when the menu link is clicked so it takes me straight to the newly requested page.


Thanks
Jon

You may want to look at the update progress. I think the at least the older releases had a way to do that there.
Hi,

You can use the following javascript function to abort an async call.

function CancelAsyncPostBack()
{
Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
}

Hope this helps.

Hi,

Just to test this, I added button to my page which calls the Cancel javascript function. After clicking this button I then click one of the menu links and I don't get taken to the new page until the AJAX stuff has finished.

Below provides more information and hopefully clarifies what I'm doing.


1) On page load a javascript function is called which loops through each row in the DataList table and makes an asynchronous call to a webservice method on the server.

2) It takes 10-20 seconds for the server to calculate the details for each request and then return the results to the callback function on the client, where the results get shown in appropriate columns of the DataList table.


I have 10 rows in my table so end up making 10 near simultaneous calls to the webservice on the server. Whilst waiting for the server to finish responding to these requests I click a link on the page and I want to be taken to the new page immediately. As it stands, I have to wait for the server to respond with all the requested data.


So, my questions are:

1) how do I stop the client waiting for the rest of the data so it goes to the new page?

2) Is it possible to tell the webservice on the server to quit working on the problem?

Thanks
Jon



The reason is because of theInternet Explorer's Simultaneous Connections Limit which is 2 by default.
Please refer to this: ?http://weblogs.asp.net/mschwarz/archive/2005/10/20/428047.aspx

speedbird:

?1) how do I stop the client waiting for the rest of the data so it goes to the new page?

2) Is it possible to tell the webservice on the server to quit working on the problem?

As far as I can tell, there isn't a good way to achieve your requirement.

Hello,

Q) how do I stop the client waiting for the rest of the data so it goes to the new page?
A) What you can do is use JavaScript or HTML anchor to redirect the client to a different page.

Sample: HTML Anchor: <a href=URL_Name target="_self">Click to go to different page</a>

JavaScript Function
function Redirect()
{
location.href='http://www.asp.net';
}

<asp:hyperlink id="hlRedirect" Text="Click Link to Go" onclick="Redirect(); return false;" style="cursor: hand;" runat="server" />

Sample URL:http://forums.advancemicrotech.com/threads/thread051507.aspx
Note: The Start Thread button is the same as your webservice doing its job. Once you click Start Thread button, the thread goes to sleep for 10 seconds, same as your webservice doing something on the server. During this time, you can either click the Redirect button that is created with HTML or the ASP Hyperlink ... as shown above ...


Q) Is it possible to tell the webservice on the server to quit working on the problem?
A) No you cannot tell the webservice to quit working while it's doing its job.

Hope these help ... Cheers.

Ability to fine-tune control over request validation

This is a subject that crosses multiple disciplines, but I'm posting it here (AJAX forum) because it was a partial postback (with Sys.Webforms.PageRequestManagerServerErrorException error) that stumped me.

I have a form that submits regular <input /> tags inside an UpdatePanel (not server controls). I was finishing debugging when I tried submitting something like "test<test>test" for a form value. The page would not do the partial update, and instead threw the error mentioned earlier in an alert box.

After messing around I figured out that it is ASP.NET guarding me against some malicious entry by hackers.

Changing ValidateRequest to false fixed the problem, but I hate to wipe something out completely, without knowing what I'm wiping out.

Is there some way to fine-tune control of what gets validated? Is there any way to know exactly what I've just disabled by setting ValidateRequest to false?

Thanks...

I'll give this one obnoxious bump, just to see if there's someone who may have some knowledge on this topic. If not, maybe it's just one of those areas where MS doesn't want to say what's going on under the covers. It would be nice to know what is going on with the validation, and what, if anything, can be controlled. For example, it would be great to subclass the functionality.


Hi,

It checks the following strings:

1. Is there a "&#" contained in the input string

2. Is there a "<[char]", "<!", "</" in the input string.


Great, thanks Raymond!