how to notify webserver when user closes the browser (in asp.net)? - c#

I am developing a relay chat application , divided into 2 panes.
right pane - > The Chat responses of users (this uses a ASP.NET Multiline Label control placed inside the update panel , so when any user types the responses and submits it is added to this control)
left panes -> the list of users currently online(this uses ASP.NET list control which is also placed inside the update panel).
below this is the textbox for the user to enter text and a send button to post his response.
everything works fine. But when user closes the browser window instead of clicking the log out button. the list on the left pane is not getting refreshed.
It happens properly , when the user logs out.
IS there any way to knock of the users name from the list if the user closes the browser?(even before his session is expired on the server side).?
sorry i couldn expose the screen shot.
can any one suggest an idea along with a sample code snippet.?
thanks
vijay

You can do it the other way around: ping the server from the browser with an ajax call periodically. If no ping received, remove the user.

You can use Javascript to detect when the browser has been closed, and then kick-off an AJAX request back to the server notifying that the user left.

Related

How to Fix issues related to DirectLineChannel prompt choice options not displayed in chat bot window developed using V4 SDK in C#?

I am trying to create a chatbot which is having multiple waterfall dialog classes using C# and BOT SDK V4. I have created a HTML page and placed the DirectLine channel Secret Key Iframe data into it and published it to Azure successfully and opened it in the browser. The browser opens with a in-built welcome message something like: Hi bot name type Hi to continue.
If i have Choice options done through prompt options to be displayed as buttons but these are not displayed through direct line channel but works very good in Web Chat Channel?
Attached image shows the issue:
a "WebChatbotHtml_optionbtndisplayed.jpg"
b. "DirectLinechannelHtml_optionbtnnotdisplayed.jpg"
Now, in the main dialog class i have implemented the Login mechanism using the Oauth Prompt in th html page that was created above i see the login link getting displayed using which i have successfully logged in this will navigate to another waterfall dialog having prompt options with some custom choice buttons, whee if i click on a choice button the next step will be executed and respective action will be triggered.
The issue i have is normally the options are displayed for me to access but in the html that i created the all other things like login link and navigation is happening but the choice buttons are not displayed its like they are getting hidden.
or Sometimes the Choice Option buttons are not displayed at all in the Direct Channel Web chat bot
The query is how to fix the issue?
To make my query to be understood in a better way please find below set of things:
1. WaterfalldiaglogClass1:
STEP 1: Has login option/link displayed through Oauth Prompt.
STEP 2: Gets token validates it and displays login successful message and then navigates to second waterfalldialogClass
2. WaterFallddialogClass2:
STEP 1: Custom choices are displayed through Prompt options lets say 1,2,3,4
STEP 2: Capture the choice getting clicked and perform respective action
I created a HTML page where the I frame code i copied with secret code of Direct Line Channel
Published it to azure successfully with no errors or warnings
Opened the html page in a browser the chat bot opens successfully with a welcome default message like: HI i am bot,enter Hi to continue
User sends hi and logins using the login link available displayed in dialog class 1 and login successful message is displayed
Navigated successfully to second dialog successfully as i can see the prompt message given as part of prompt option and custom choices in the code
Current Issue: The option buttons 1,2,3,4 are not getting displayed it is getting hidden somehow
Need help in resolving the issue Please provide detailed step by step guide in resolving it as i am new to BOT and coding .
language: C#
Bot Framework: V4
I have tried increasing height width and other % values in the HTML page and republished it but not successful. The same thing works in web chat channel i.e. if i keep secret code inside the HTML page of webchat channel without any issues.
Issue Image attached for reference.
Expected Result: Data or choices should be shown as it is working in Webchat channel
Actual Result: Not working the choice options are not visible to choose
There are two versions of Embedded Web Chat at the moment: Gemini and Scorpio. Embedded Web Chat is currently in the process of slowly transitioning all clients from Scorpio to Gemini. It appears your embedded Web Chat is still using Scorpio which unfortunately does not support the OAuth prompt. In the near future, you will be able to manually request your client to be switched to Gemini.
In the meantime, you can add either add Web Chat v4 to your site using a CDN or wait for your client to be migrated to Gemini.
For more details regarding Embedded Web Chat, take a look at the documentation.
Hope this is somewhat helpful.

MessageBox appears but does not pop up

I have a message box that has ok or cancel as options to ensure the user wishes to change the name of a company. However, this message box doesn't pop up on the current screen, instead it just appears on the windows task bar and blinks there.
May I know how do I make it appear?
var ConfirmResult = MessageBox.Show("Are you sure you want to change the name of the Company?", "Confirm Update!", MessageBoxButtons.OKCancel);
edit: This is in asp.net web forms.
You must understand and distinct the programs that runs on desktop, and the programs that runs on server and send the results to some web browser.
In this case the MessageBox, is creates new window on the desktop side – is not work for a web application, not make sense at all.
To make a message box in a browser, you need to think different – you make the message box using some css and javascript and you render that on the page on the browser.You handle the events with javascript and/or post back
get some ideas: https://www.w3schools.com/howto/howto_js_alert.asp

Browser back button does not work with asp controls

I have a site with few asp:CheckBoxList and asp:DropDownList controls. Checking few options or selecting few items in the dropdowns makes the back button browse to same page just with previous selections. I would like the back button on the browser take the user to the previous website visited. As example: if the last visited site was: default.aspx, then the back button from my current site should go back to default.aspx.
Adding few header options regarding caching only broke the back button to: Page Not Found message.
How can the user browse back to the default.aspx by the first back button clicked on the browser?
Just need to confirm, are u using IE 10 to run the web system?
I had encounter asp control component not working properly when i was using IE 10.
Maybe consider using other browser type like firefox and safari to see if it can work properly

How to Insert Confirm Dialog Between Forms.Authentication and ReturnUrl?

I am revamping the authentication system of an ASP.net webforms application (which relies on Forms.Authentication) to limit each user to a single browser session. To support this, I have created a new IHttpModule which uses an application variable to maintain a dictionary that maps userId to sessions, patterned after this article.
All of that is working great, but there is one more component that we want to add: an ok/cancel dialog displayed after login is successful, warning the user that their first session will be closed if they proceed. If they choose to cancel, then we need to interrupt the login process without sending the user to the returnUrl set via Forms.Authentication.
So far, my attempts have been around adding this to the loggedIn event, where the sessionId is captured and compared, however my attempts at stopping things once this point occurs have not worked out -- the user is redirected past my confirm dialog without anything actually firing.
Thus the question: How can I insert a confirm dialog to the login process of Authentication.Forms?
Something you might try - make the form auth an ajax call, then handle your dialog on the client side. So, for example, intercept the login form post using jquery, do an ajax post of the login form, get json or something else back, and then pop the dialog with a redirect on the client side.

Simulating a button click within ascx page

I need to simulate a button click on my ascx page. The user firstly clicks on a button on the service home page which links to a certain service and a new window opens for that related service. If they are not logged in it directs them to the login page. A querystring is sent with it to keep note of what service they had originally clicked. When the user then logs in they are redirected back to the services page and the querystring of what they clicked on before is sent also.
I have up to this point working fine. The problem is that when I'm redirected back to the online services page I need to simulate an onclick event which will open the new window. I cant click on an the onclick method for the button as there is none, everything is done dynamically. Any ideas?
I would have thought the easiest way to achieve what it sounds like you're trying to do is in the code behind for your Online Services Page check to see whether the query string contains the url for the service they clicked on before you sent them to the login page, if it does then add some javascript to run on start up which launches the pop-up (using the ClientScriptManager.RegisterStartupScript method: http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx).
If you absolutely have to fire the click event you can also do that from your javascript by finding the button you want to click by it's ClientId (using getElementById) and then calling the javascript click() method on it. Here is an example: http://www.w3schools.com/jsref/met_html_click.asp

Categories

Resources