Terminate the session on IIS - asp.net

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
}
}

Related

why thread comes before response.write

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")

ASP.NET using JQuery Progress bar

I have a question about how to use JQuery progress bar to wait until long process finished.
I have a web page with a button and when the user hits this button ,some operation on server occurred. For example inserting records into DB like this:
Int32 val = Int32.Parse(Request.QueryString["PLCID"].ToString());
String _MachineName = String.Empty;
_MachineIP = String.Empty;
DBLayer.getMachineByPLCID(val, out _MachineName, out _MachineIP);
I need to show progress bar for the user and prevent him from taking any action till the process finished.
please help!
If you want only to disable the button and make redirection after the processing has finished, you can use this sample:
http://tpeczek.com/2010/07/reporting-server-side-operation.html
You just need to replace re-enabling the button with proper call to window.location.

How to test a confirm dialog with Cucumber?

I am using Ruby on Rails with Cucumber and Capybara.
How would I go about testing a simple confirm command ("Are you sure?")?
Also, where could I find further documentation on this issue?
The selenium driver now supports this
From Capybara you would access it like this:
page.driver.browser.switch_to.alert.accept
or
page.driver.browser.switch_to.alert.dismiss
or
page.driver.browser.switch_to.alert.text
Seems like there's no way to do it in Capybara, unfortunately. But if you're running your tests with the Selenium driver (and probably other drivers that support JavaScript), you can hack it. Just before performing the action that would bring up the confirm dialog, override the confirm method to always return true. That way the dialog will never be displayed, and your tests can continue as if the user had pressed the OK button. If you want to simulate the reverse, simply change it to return false.
page.evaluate_script('window.confirm = function() { return true; }')
page.click('Remove')
I've implemented these two web steps in /features/step_definitions/web_steps.rb:
When /^I confirm popup$/ do
page.driver.browser.switch_to.alert.accept
end
When /^I dismiss popup$/ do
page.driver.browser.switch_to.alert.dismiss
end
If you want to specifically test the message being displayed, here's a particularly hacky way to do so. I don't endorse it as beautiful code, but it gets the job done. You'll need to load http://plugins.jquery.com/node/1386/release, or change it to do cookies natively if you don't want jQuery.
Use this sort of story:
Given I am on the menu page for the current booking
And a confirmation box saying "The menu is £3.50 over budget. Click Ok to confirm anyway, or Cancel if you want to make changes." should pop up
And I want to click "Ok"
When I press "Confirm menu"
Then the confirmation box should have been displayed
And these steps
Given /^a confirmation box saying "([^"]*)" should pop up$/ do |message|
#expected_message = message
end
Given /^I want to click "([^"]*)"$/ do |option|
retval = (option == "Ok") ? "true" : "false"
page.evaluate_script("window.confirm = function (msg) {
$.cookie('confirm_message', msg)
return #{retval}
}")
end
Then /^the confirmation box should have been displayed$/ do
page.evaluate_script("$.cookie('confirm_message')").should_not be_nil
page.evaluate_script("$.cookie('confirm_message')").should eq(#expected_message)
page.evaluate_script("$.cookie('confirm_message', null)")
end
Updating this for current releases of Capybara. Most Capybara drivers today support the modal API. To accept a confirm modal you would do
accept_confirm do # dismiss_confirm if not accepting
click_link 'delete' # whatever action triggers the modal to appear
end
This can be used in Cucumber with something like
When /^(?:|I )press "([^"]*)" and confirm "([^"]*)"$/ do |button, msg|
accept_confirm msg do
click_button(button)
end
end
which will click the named button and then accept a confirm box with text matching msg
The capybara-webkit driver supports this as well.
Scenario: Illustrate an example has dialog confirm with text
#
When I confirm the browser dialog with tile "Are you sure?"
#
=====================================================================
my step definition here:
And(/^I confirm the browser dialog with title "([^"]*)"$/) do |title|
if page.driver.class == Capybara::Selenium::Driver
page.driver.browser.switch_to.alert.text.should eq(title)
page.driver.browser.switch_to.alert.accept
elsif page.driver.class == Capybara::Webkit::Driver
sleep 1 # prevent test from failing by waiting for popup
page.driver.browser.confirm_messages.should eq(title)
page.driver.browser.accept_js_confirms
else
raise "Unsupported driver"
end
end
Prickle adds some handy convenience methods for working with popups in selenium and webkit
This gist has steps to test a JS confirm dialog in Rails 2 and 3 with any Capybara driver.
It's an adaptation of a previous answer, but doesn't need the jQuery Cookie plugin.
Tried the above answers with no luck. In the end this worked for me:
#browser.alert.ok

Get ASP.NET Session Last Access Time (or Time-to-Timeout)

I'm trying to determine how much time is left in a given ASP.NET session until it times out.
If there is no readily available time-to-timeout value, I could also calculate it from its last access time (but I didn't find this either). Any idea how to do this?
If you are at the server, processing the request, then the timeout has just been reset so the full 20 minutes (or whatever you configured) remain.
If you want a client-side warning, you will need to create some javascript code that will fire about 20 minutes from "now". See the setTimeout method.
I have used that to display a warning, 15 minutes after the page was requested. It pops up an alert like "your session will expire on {HH:mm}, please save your work". The exact time was used instead of "in 5 minutes" as you never know when the user will see that message (did he return to his computer 10 minutes after the alert fired?).
For multi-page solution one could save last request time in cookie, and javascript could consider this last access time for handling warning message or login out action.
I have just implemented a solution like the one asked about here and it seems to work. I have an MVC application and have this code in my _Layout.chtml page but it could work in an asp.net app by placing it in the master page I would think. I am using local session storage via the amplify.js plugin. I use local session storage because as Mr Grieves says there could be a situation where a user is accessing the application in a way that does not cause a page refresh or redirect but still resets the session timeout on the server.
$(document).ready(function () {
var sessionTimeout = '#(Session.Timeout)'; //from server at startup
amplify.store.sessionStorage("sessionTimeout", sessionTimeout);
amplify.store.sessionStorage("timeLeft", sessionTimeout);
setInterval(checkSession, 60000); // run checkSession this every 1 minute
function checkSession() {
var timeLeft = amplify.store.sessionStorage("timeLeft");
timeLeft--; // decrement by 1 minute
amplify.store.sessionStorage("timeLeft", timeLeft);
if (timeLeft <= 10) {
alert("You have " + timeLeft + " minutes before session timeout. ");
}
}
});
Then in a page where users never cause a page refresh but still hit the server thereby causing a reset of their session I put this on a button click event:
$('#MyButton').click(function (e) {
//Some Code that causes session reset but not page refresh here
amplify.store.sessionStorage("sessionTimeout", 60); //default session timeout
amplify.store.sessionStorage("timeLeft", 60);
});
Using local session storage allows my _Layout.chtml code to see that the session has been reset here even though a page never got refreshed or redirected.
You can get the timeout in minutes from:
Session.Timeout
Isn't this enough to provide the information, as the timeout is reset every request? Don't know how you want to display this without doing a request?
Anyhow, best way is on every request setting some Session variable with the last access time. That should provide the info on remote.

How to show status of huge process to client(web)

Environment : ASP.NET, C#
I am writing a web program that will export 12 tables to another database. When the user click the "Export" button, the export process will get started. The thing is, I like to show some messages to client such as "preparing..., deleting old records..., exporting..., export completed."
But now, It is showing all status once 12 table are completed.
Please guide me how to do this.
Doing long processes like this is on a web page is probably not a good idea, you will need change the timeout settings on pages etc
Rather build a windows service that does all the work. You can then use the Page to initialte the process. The service could update some status that is read by the page. This way the page does very little work, ie initiate the process and poll for status updates. This can be done via simple jquery/ajax calls.
try this
put this on c#
and call ajavascript function per process
Page.RegisterClientScriptBlock("1","alert('add to table now')");
Use a javascript timer to periodically load content from a status page or service.
The timer is fairly simple:
setTimeout('checkProcessStatus()', waitTime);
The update itself depends on your choice of tech - for instance if using MVC and jQuery:
function checkProcessStatus() {
//dynamically add the html from the status page to <div id="taskStatusPanel"
$('#taskStatusPanel').load('export/status/' + taskId);
//set timer to call this again
setTimeout('checkProcessStatus()', waitTime);
}
Then the ExportController.Status action would return a simple view that displayed the HTML for the current status.

Resources