why thread comes before response.write - asp.net

when I run the code, the thread process before the response.write !! why and how to make them in order ?
insertUser.ExecuteNonQuery()
con.Close()
Response.Write("Done successfully ...")
Thread.Sleep(4000)
Response.Redirect("Default.aspx")

A response is a one-time thing in a web application. You can't "respond a little, do something else, and respond some more." This is especially true when you consider something like Response.Redirect() which modifies the headers of the response. (Essentially, Response.Redirect() will entirely "clobber" any content that you've added to the response so that the user will never see it.)
It looks like what you're trying to do here is:
Show the user a message.
Wait a few seconds.
Send the user to another page.
There are a couple of standard ways to accomplish this. You can either respond with a page that includes step 1 which, in client-side code, performs steps 2 and 3 or you can perform step 3 in server-side code and on the second page perform step 1 (and possibly two, hiding the message after a few seconds).
For example, let's say you want to show the message on Page A, wait a few seconds, then send the user to Page B. Then in Page A you might include something like this:
<script type="text/javascript">
$(function() {
$('#dialog-message').dialog({
modal: true,
buttons: {
Ok: function() {
$(this).dialog('close');
}
},
close: function() {
window.location.href='Default.aspx';
}
});
});
</script>
<div id="dialog-message">Done successfully ...</div>
Using jQuery, what this does is show the user a dialog (using the jQuery UI Dialog) with the intended message, and when the user closes the dialog it then performs the redirect.

You can do it using client side functionality in your code
plese refer following link
http://social.msdn.microsoft.com/Forums/da/sharepointdevelopmentprevious/thread/087c6b95-fe8d-48ea-85e6-b7fbcb777a5c

Web Response will get on the page only after the complete processing of webrequest,ie you can see response after the excution of code completly.So your code is excuting correct order.You can test it by insert Response.End() methord as shown below
insertUser.ExecuteNonQuery()
con.Close()
Response.Write("Done successfully ...")
Response.End();
Thread.Sleep(4000)
Response.Redirect("Default.aspx")

Related

Google reCAPTCHA response success: false, no error codes

UPDATE: Google has recently updated their error message with an additional error code possibility: "timeout-or-duplicate".
This new error code seems to cover 99% of our previously mentioned mysterious
cases.
We are still left wondering why we get that many validation requests that are either timeouts or duplicates. Determinining this with certainty is likely to be impossible, but now I am just hoping that someone else has experienced something like it.
Disclaimer: I cross posted this to Google Groups, so apologies for spamming the ether for the ones of you who frequent both sites.
I am currently working on a page as part of a ASP.Net MVC application with a form that uses reCAPTCHA validation. The page currently has many daily users.
In my server side validation** of a reCAPTCHA response, for a while now, I have seen the case of the reCAPTCHA response having its success property set to false, but with an accompanying empty error code array.
Most of the requests pass validation, but some keep exhibiting this pattern.
So after doing some research online, I explored the two possible scenarios I could think of:
The validation has timed out and is no longer valid.
The user has already been validated using the response value, so they are rejected the second time.
After collecting data for a while, I have found that all cases of "Success: false, error codes: []" have either had the validation be rather old (ranging from 5 minutes to 10 days(!)), or it has been a case of a re-used response value, or sometimes a combination of the two.
Even after implementing client side prevention of double-clicking my submit-form button, a lot of double submits still seem to get through to the server side Google reCAPTCHA validation logic.
My data tells me that 1.6% (28) of all requests (1760) have failed with at least one of the above scenarios being true ("timeout" or "double submission").
Meanwhile, not a single request of the 1760 has failed where the error code array was not empty.
I just have a hard time imagining a practical use case where a ChallengeTimeStamp gets issued, and then after 10 days validation is attempted, server side.
My question is:
What could be the reason for a non-negligible percentage of all Google reCAPTCHA server side validation attempts to be either very old or a case of double submission?
**By "server side validation" I mean logic that looks like this:
public bool IsVerifiedUser(string captchaResponse, string endUserIp)
{
string apiUrl = ConfigurationManager.AppSettings["Google_Captcha_API"];
string secret = ConfigurationManager.AppSettings["Google_Captcha_SecretKey"];
using (var client = new HttpClient())
{
var parameters = new Dictionary<string, string>
{
{ "secret", secret },
{ "response", captchaResponse },
{ "remoteip", endUserIp },
};
var content = new FormUrlEncodedContent(parameters);
var response = client.PostAsync(apiUrl, content).Result;
var responseContent = response.Content.ReadAsStringAsync().Result;
GoogleCaptchaResponse googleCaptchaResponse = JsonConvert.DeserializeObject<GoogleCaptchaResponse>(responseContent);
if (googleCaptchaResponse.Success)
{
_dal.LogGoogleRecaptchaResponse(endUserIp, captchaResponse);
return true;
}
else
{
//Actual code ommitted
//Try to determine the cause of failure
//Look at googleCaptchaResponse.ErrorCodes array (this has been empty in all of the 28 cases of "success: false")
//Measure time between googleCaptchaResponse.ChallengeTimeStamp (which is UTC) and DateTime.UtcNow
//Check reCAPTCHAresponse against local database of previously used reCAPTCHAresponses to detect cases of double submission
return false;
}
}
}
Thank you in advance to anyone who has a clue and can perhaps shed some light on the subject.
You will get timeout-or-duplicate problem if your captcha is validated twice.
Save logs in a file in append mode and check if you are validating a Captcha twice.
Here is an example
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response'])
file_put_contents( "logfile", $verifyResponse, FILE_APPEND );
Now read the content of logfile created above and check if captcha is verified twice
This is an interesting question, but it's going to be impossible to answer with any sort of certainly. I can give an educated guess about what's occurring.
As far as the old submissions go, that could simply be users leaving the page open in the browser and coming back later to finally submit. You can handle this scenario in a few different ways:
Set a meta refresh for the page, such that it will update itself after a defined period of time, and hopefully either get a new ReCAPTCHA validation code or at least prompt the user to verify the CAPTCHA again. However, this is less than ideal as it increases requests to your server and will blow out any work the user has done on the form. It's also very brute-force: it will simply refresh after a certain amount of time, regardless of whether the user is currently actively using the page or not.
Use a JavaScript timer to notify the user about the page timing out and then refresh. This is like #1, but with much more finesse. You can pop a warning dialog telling the user that they've left the page sitting too long and it will soon need to be refreshed, giving them time to finish up if they're actively using it. You can also check for user activity via events like onmousemove. If the user's not moving the mouse, it's very likely they aren't on the page.
Handle it server-side, by catching this scenario. I actually prefer this method the most as it's the most fluid, and honestly the easiest to achieve. When you get back success: false with no error codes, simply send the user back to the page, as if they had made a validation error in the form. Provide a message telling them that their CAPTCHA validation expired and they need to verify again. Then, all they have to do is verify and resubmit.
The double-submit issue is a perennial one that plagues all web developers. User behavior studies have shown that the vast majority occur because users have been trained to double-click icons, and as a result, think they need to double-click submit buttons as well. Some of it is impatience if something doesn't happen immediately on click. Regardless, the best thing you can do is implement JavaScript that disables the button on click, preventing a second click.

Meteor: send message to user at hot code push

How can I let the user know when they are getting a hot code push?
At the moment the screen will go blank during the push, and the user will feel it's rather weird. I want to reassure them the app is updating.
Is there a hook or something which I can use?
Here's the shortest solution I've found so far that doesn't require external packages:
var ALERT_DELAY = 3000;
var needToShowAlert = true;
Reload._onMigrate(function (retry) {
if (needToShowAlert) {
console.log('going to reload in 3 seconds...');
needToShowAlert = false;
_.delay(retry, ALERT_DELAY);
return [false];
} else {
return [true];
}
});
You can just copy that into the client code of your app and change two things:
Replace the console.log with an alert modal or something informing the user that the screen is about to reload.
Replace ALERT_DELAY with some number of milliseconds that you think are appropriate for the user to read the modal from (1).
Other notes
I'd recommend watching this video on Evented Mind, which explains what's going on in a little more detail.
You can also read the comments in the reload source for further enlightenment.
I can image more complex reload logic, especially around deciding when to allow a reload. Also see this pacakge for one possible implementation.
You could send something on Meteor.startup() in your client-side code. I personally use Bert to toast messages.

Terminate the session on IIS

I have a requirement that is :--
On click of ‘Logout’ link, popup message “This will terminate the session and close the browser. Do you want to continue?” with Yes and No buttons. On click of ‘Yes’, session should be terminated in IIS server and current tab of browser closed.
To implement this I have writen below piece of code but I dont know how to terminate the session on IIS
<script language="vbscript">
Function OnClickLogout()
dim Answer, msg
Msg = "This will terminate the session and close the browser. Do you want to continue?"
Answer = MsgBox(Msg, vbYesNo + vbCritical, "Error")
if Answer = vbYes then
window.close
else
'Retrun to the previous page
end if
End Function
</script>
Could anyone please suggest me how to do this in vbscript. My website is in ASP but its a legacy application so I have to do the code!!!
Couldn't you simply use JavaScript? We us it all the time at work in our ASP Classic projects. Something like that to start off:
function DeleteProductGroup(){
var r=confirm("Are you sure you want to delete this product group?");
if (r==true){//here goes the code if user presses YES
}
else{//here goes the code if user presses NO
}
}

How to get received sms from sms web service without page refresh and auto

I have a web service for send sms from website. I can get the received sms by calling Page_load codes. But I want get this messages automatically then send a message(sms) to sender. It means I want relpay to his sms without page load or refresh page automatically.
Put your data into a div, Use ajax and call your ajaxified function after every desired time using interval. ...
some thing like
$(document).ready(function(){
var refresh = setInterval(function(){
// Do something every 1 seconds like call an ajax function
$('#youdiv').ajax(); //this is dummy, for right syntax follow the link at the end of answer
}, 1000); // 1000 equals to 1 sec
});
Read more about ajax
http://api.jquery.com/jQuery.ajax/

Cancel form.submit()

In javascript function I am submitin a form:
form.submit();,
with huge amount of data.
Is it possible to cancel this operation beside clicking on browser's stop button?
UPDATE:
Maybe i didn't made my self clear i am submiting large files.
form with uploadcontrol that runs in iframe.
You could do something like what Gmail does: Undo Sending Mails (lab feature).
It justs delays the mail sending by a 5 seconds. If in that time the server receives a undo AJAX call, the mail is not send.
This could potentially increase you serverside complexity, but not that much.
In the case that the information is not sent you could use this:
//IE
document.execCommand('Stop');
//Firefox
window.stop();
So the whole thing would look something like this (pseudocode):
stop_submit(current_id){
try{
document.execCommand('Stop');
}catch(e){}
try{
window.stop();
}catch(e){}
AJAXCall("/myfolder/cancel_submit/", "id="+current_id, "post");
return;
}
This is a classic problem with the client-server architecture. Once the HTTP request has been made, there is no stopping it. You will need a way to restore state after all requests to guarantee that everything is back to the way it was.
Now, you could do this with AJAX and use the abort function. Or, you could try window.stop() or document.execCommand("Stop"), depending on your browser. But those do not solve the problem of the request having already been sent.

Resources