I want to silently check for Session existence without Posting back page by using AJAX Timer and AsyncPostBack Trigger.
Now, I would like to know is there anyway to silently check whether ASP.NET C# if (Session["email"] = null) { Response.Redirect("Logout.aspx"); } something of this kind to check for every 10 seconds without Posting Back Page and without using AJAX by using something like jQuery or any other technology that is supported by .NET?
The server can push to a loaded page if you use an asynchronous controller with a partial view which is loading every set amount of time.
http://msdn.microsoft.com/en-us/library/ee728598.aspx
there is only one way to get to the server. send a request. that can be a "standard" request where the browser will refresh the screen when a response is sent. the other type of request is a ajax request. the difference is an ajax request contains a header to inform the server it's an ajax request. when the browser receives the response it will allow the developer to decide what to do with the response. either way a full request/response exchange takes place the only difference is how the browser handles the request.
jquery is a javascript library that includes functionality to make ajax request easier to setup.
to answer you question no, there is no way around making a request.
Related
Regarding this question and also many documents have stated that sending a PUT request directly via form in browser is impossible due to security reason.
However, What I am seeing in Backbone is that it could still send a direct PUT request via browser without a workaround like adding a hidden form field.
And they're confusing to me. Is there anything that I'm missing here?
A form can only send a GET or a POST request, as set in the method attribute.
However, Backbone delegates its requests to jQuery.ajax by default (or whatever you want via Backbone.ajax) which itself wraps XMLHttpRequest, an object that can send PUT/DELETE/PATCH requests.
From https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
XMLHttpRequest is a JavaScript object that was designed by Microsoft
and adopted by Mozilla, Apple, and Google. It's now being standardized
in the W3C. It provides an easy way to retrieve data from a URL
without having to do a full page refresh. A Web page can update just a
part of the page without disrupting what the user is doing.
XMLHttpRequest is used heavily in AJAX programming.
many documents have stated that sending a PUT request directly via browser is impossible due to security reason
Citation please.
Backbone sends a PUT just like it sends any other request, with jQuery,
Backbone.ajax({
type: 'PUT'
...
});
It is just some server side langauges,like PHP, that have problems with receiving a PUT request.
The hidden form field is used when posting from a <form>. Backbone uses javascript.
Regarding to a static link on a web page, the browser will issue GET or POST request to the web site, depending on whether a form of parameters attached.
However, I want the browser to issue a PUT request for that link, how can I do that? I know that Ajax could do it, but I don't want to use Ajax.
I want the browser to issue a PUT request for that link
it seems that PUT and DELETE are currently unsupported in html forms, according to this submission to the w3.
I know that Ajax could do it
Not always true. Because PUT and DELETE are at times unsupported by some browsers, ajax cannot consume them without making a dummy param to trigger a real PUT or DELETE server side, which gives the illusion of full HTTP support by ajax.
I'm calling a static Page method via javascript that takes between 5s and 10 min. I'd like to give my user the choice to either continue waiting for the request to complete or not, and use window.setTimeout() to check back every 30s.
I've tried both location.href = '/newpage.aspx' or firing a button's click handler (which does similar redirect) to redirect the user prior to completion of the page method, to no avail. I can immediately send user to a simple html page, but a redirect to any aspx page involving server-side appears to block. When the page method finally completes, the redirect does succeed.
Is this:
a browser issue? If all modern
browsers support at least 2
concurrent requests per domain, why
wouldn't this work?
a framework
limitation?
a desirable design
pattern or even possible? I've
checked, and after redirecting to an
HTML page, the original request continues processing (db updates, no problem).
Are Page method calls simply not asynchronous from a "concurrent HTTP request" perspective?
Any insight greatly appreciated!
It sounds like you're blocking on InProc Session, which is limited to one concurrent request per unique session. If you don't need access to the Session in your page method, you can disable it by modifying the WebMethod attribute:
[System.Web.Services.WebMethod(EnableSession=false)]
What is AsyncPostBack, SyncPostBack and what is the difference between those methods?
An asynchronous postback is accomplished using javascript to send an XMLHttpRequest, known as AJAX, without leaving the web page you are on. A synchronous postback is a normal form post request from the web page, resulting in a complete request cycle and a (re)display of the same or a different web page. The difference is that with an asynchronous request the web page stays the same and the user can continue to interact with it while the request is taking place. This can make the interface seem more responsive to the user and improve the experience. In a synchronous, or full, postback the web browser must wait while the request is sent back and the new page is loaded. You also lose, if you don't maintain it on the server and reset it on the new page, any state on the original web page.
Hi I have web app which stores certain things on a page in a cookie when the page posts back in case the user doesn't finish what they're doing and come back later. But now I must do a javascript time-out and actively save the info to the cookie rather than wait for the user to postback. All my cookie code is on server side where I use Response and Request objects to read and write cookies and I want to leverage that. So I would like to just use ajax calls to a webservice. Is there a way for me to access Request and Response objects and read and write cookies to the browser via those objects during a webservice call? Or should I just go with javascript?
EDIT: Sorry i wanted to specify that I would like to use jquery-ajax.
Implement an ajax callback on a timer that posts back every n number of seconds. When the ajax posts back, check your constraints and simply update the cookie.
OK so I created the static web method on .cs side of the page and in the method I enable session. So this way, I can save stuff to cookie by making ajax calls and using my already existing .cs cookie code.