Detecting Session Timeout in Silverlight - c#

The SL3 DataGrid has a download XLS column to download the details of the record in Excel format. On click of the Download button, first the user is prompted with a SaveFileDialog to select the file and then a WCF call is made to fetch the details of the selected record. Using 3rd party excel helper library, the records are added to an excel sheet and the file is saved.
The problem is that when the Session has timed out (say, due to idleness), the click functions perfectly well, prompting the user to specify the file to save, and then a redirect is made to the login page (as expected, since we are handling the not authenticated errors etc).
However, the user is now in an illusion that an empty Excel file has been downloaded.
So, is there a way to detect from Silverlight page, if the Session has timed out?
And thereby showing the SaveFileDialog only when the Session is available.

You can probably send the heartbeat from Silverlight to ASP.NET. This is very common issues in Ajax world as well. As you can use Javascript in Silverlight as well, you may want to check this solution Keeping ASP.NET Session Open / Alive
If you dont like to JS then you can either use HttpWebRequest or WebClient to communicate with asp.net ...

Related

Saving source code of webpage that needs login

I understood how to login to Gmail using c#, but when I try to go to the webpage it does not recognize I have logged in to Gmail.
Overall, I need to login to Gmail, and then access a webpage once I'm logged in, and save its source code, all using c#, preferably without having to open a browser, just doing all within the c# application.
Edit: I have logged in to Gmail successfully. But when I then go to the website, it doesn't recognize that I'm logged in. I need a way to do it in the same session. I tried researching but couldn't understand how to do it.
I'm pretty sure that you can't Download the source code behind gmail, that is must likely closely guarded for security reasons, you can maybe get a response and try to download a list of mails if you want to make a Outlook lookalike.
if you need it all in one session, you need to find a way to share that across programs, your C# app runs in a separate environment then a browser does and cannot inter act directly, this has to be done through a API, socket communication etc.
you can however if all you want to do is to access gmail through your own program add the Web-browser component, from the toolbox to your form. (if you have one)
this is just a blank space (looks like a giant text box) that web pages can easily be loaded into. No URL bar, no controls in any way just completely blank
and then control the pages though your source code.
but what i wonder is why do you what this, why not just make your browser log you in automatically ?
To also use the same session in the browser you should transfer the session cookie to the browser. I don't know if this is possible. I don't even know if Gmail likes/allows this.
I would suggest you try something different (not trying to transfer sessions for example), like opening Gmail in the browser instead of your C# program.
You also can't download Gmail's source.

Get hyperlink click event of MS office applications

I have a strange requirement from my client. They want to have some hyperlinks witin the documents of any MS office applications like MS word, excel, powerpoint etc. If any sentence is hyperlinked with some value, can i get an event of that hyperlink in my asp.net C# code.? I have stuided INTEROP dll of .net. I know that a new excel workbook can be created or a word document can be created but can i get an event of the hyperlink that lies within the document.?
please help
Couple of things you could do here.
You could make all the hyperlinks point to a specific web page that does what you need to do.
Or, you could register your own protocol. Instead of http you could register myProtocol protocol and make all the links in the docs myProtocol://my.custom.protocol. Having your application registered to handle that protocol.
register as the default web browser. This would allow you to handle all the links without changing the current documents.
Each has its own problems obviously. A web page isnt local so it doesnt have all the ability that a local app has, a custom protocol isnt very user friendly, and hijacking the default web browser could make your users upset.
This idea should be rethought, but there are a few options.

How to avoid security page while doing automatic login using web browser control?

Friends
My task is using C# window application have to automatic login to site and on that first page which comes after login. there is link and after clicking on that link user can download excel file.
i can implement this like i can make exe of this and put it on my schedule and i ll set the time. so it automatically download the excel file.
i completed till login code but am facing problem after login it shows me security question page.
so how can i avoid this page? And when exe executed through scheduling then it don't have show any front end? so i have to hide front end so that is also remaing.
Any suggestion related to my concept or code will be very helpful to me.
The whole point of those security questions and captchas is to avoid exactly what you are trying to achieve and prevent access to the site from automated scripts and bots. If the authors of the website decided to put them on the website it is because they didn't want their website to be used the way you intent to use it. So I am afraid that there is no official and easy way to achieve this task.

Disable browser caching the page and javascript running in Azure

Whenever we deploy an application and the client reviews the app, sometimes the javascript doesn't work (not totally). But when the browser is refreshed, the page works as intended.
I'm suspecting that it has something to do with the cache. Is there a way to disable caching of pages? I'm using Azure with .NET 4.0
Thank you in advance!
The only way I know of to reliably stop caching of files and links in most browsers is to append a random number or time to the file. e.g.
http://www.domain.com/js/script.js?date=20120409120003
This will mean it is a new link each time the page is loaded and next time it goes to get the file it won't have it available in cache.

C# download web-content after submit

I need to automate the download of a file from this site http://stats.smith.com/reports/Default.aspx?btnGo=View+Report. My problem is once I click on the submit buttom I lose control and a download dialog pops up. Is there a way to download the file using c# and avoid the download dialog? I'm currently using the WebBrowser object in the Forms assembly to navigate through the page.
Take a look at the WebClient class
If you want to save a downloaded file to the filesystem from a web browser, there must be user interaction. A web page does not have permission to muck about in a client's file system.
If you want to display the page in the browser, you can try removing the Content-Disposition=attachment;... server response header when the file is downloaded. This will only work if the client has the browser set to display such file types inside the browser.
Your question doesn't specify what you're using to download the file.
If you're asking if you can have a program that runs on a client (either a WinForms app, a console app, or a Windows Service) then you can download a file from a web site using the System.Net.WebClient class and calling the DownloadFile() method.
The accepted answer here (slightly different than you question, so it's not a duplicate) has a link to show how to download a file that requires an HTTP post first.
If you're trying to somehow automate Internet Explorer via a javascript from a web page you're hosting to force a file to download on a user without displaying the dialog box, then no. You can't.

Categories

Resources