How to Check Application idle for MVC application - c#

I know that similar thing is asked for WPF application but I want to know is there anyway to find out the application idle time for an MVC application so that I can show the session timeout popup like banking websites.
I currently searched on websites and I found this link:
http://community.devexpress.com/blogs/aspnet/archive/2011/06/15/asp-net-how-to-show-a-popup-warning-before-session-timeout.aspx
But if anyone could share better solution, it would be nice.

They typically just start a javascript timer, then after it times out, they just redirect to the logout page. It's actually quite simple, but it has nothing to do with the actual apps idle timeout.
You can add a nifty gui to it, but it's not particularly difficult.

Related

Correct way to start back ground work ASP.NET MVC 5

I'm building a ASP.NET MVC 5 web page currently. It's worth noting I'm fairly new to ASP.NET itself, prior to this I've only dealt with windows desktop applications.
My question is I'm unsure where to start my recurring background work. This work fires checks and updates to the MySql database on the server every few seconds. Currently I'm starting these checks just by adding a start method in the RouteConfig.cs class which I know is the wrong way to do it, just a quick hack while I search for the correct method. Where should I be starting this background work which should be kicked off as soon as the web page is available not when it's first searched for via the browser by a user?
This brings me to another question, a lot more work seemingly but would it be a better/more standard solution to write the background work as a windows service and establish a sort of interface between the web page front end and the windows service?
Search for Quartzin package manager, its best schedular for .net

WebBrowser Control causes whole application to become unresponsive

I have a C# .NET 3.5 application with an embedded web browser. The browser is designed to point to remote sites (Rather than anything local). Everything works fine, but when the page is slow to respond this causes my entire application to become unresponsive until the page is loaded.
I don't mind the browser being unresponsive while it does its thing, but the application going too is far from ideal.
Is there a good way to prevent this? Would it be beneficial to run the WebBrowser on a seperate thread - that's a bit beyond my skillset right now and I don't think the WebBrowser control really likes multithreading? But I can learn if needs be.
See the answer #2 on this question for a solution on how to run it on a separate thread: BackgroundWorker and WebBrowser Control
You might as well read answer #1 too, it explain the behaviors you are seeing (WebBrowser control blocking UI thead).
As it happens I found that the root cause of this was my application running as administrator. Exactly the same issue was seen when using Internet Explorer - as such, I've simply rewritten the bits that required admin privileges so I'm now no longer seeing the original issue.
this happened only on win7;I use fiddler2 to Monitor HTTP/HTTPs traffic .I find embedded web browser to visit this web:http://ctldl.windowsupdate.com/msdownload/update/v3/static/trustedr/en/disallowedcertstl.cab?50ff94e72ac1a75c;the solution is follow:http://support.microsoft.com/kb/2730040/en (Method 2 or Method 3).you can try it.other u can use .net framework4.0,then u haven't this problem.

Allowing a WPF browser application to navigate to a separate web page when finished?

I have a WPF browser application that collects user data and adds it to a database to tell them when their software is out of date.
All of that works fine, but the problem is when the application finishes its stuff, I want the web page itself to change (i.e., detect the web app has hit a 'finished' state, then autonagivate to a results page or something).
I can't think of a way to accomplish this, since the web app itself doesn't seem to be able to change the IFRAME it's contained in, much less the page outside of that, or signal to javascript or anything.
Any ideas?
I'd make an variable to keep progress/step of work. And a timer which would check if progress=="done" or sth.
Maybe this is not the best way of solving this but I don't know WPF much and that solution first came to mind

How to dynamically run process in asp.net

I am designing a website and it uses Windows Forms (in Visual Studio 10) in which for example i have five-six URLs. Now i am displaying them on home page of my website xyz.com
What i want is, i want to calculate total no. of tweets for all links and display links based on no. of times they are being tweeted/retweeted.
for a url we can calculate no. of tweet using twitter api http://urls.api.twitter.com/1/urls/count.json?url=YourURL
I know all the stuff like receiving JSON values in a string and parsing json to retrieve tweet counts and then compare and display links based on the priority etc.
What i have been using till now it is initiating all the process using a Click_Button.
But i want to know how can i automate this all for each 10 minutes. Its like a end user can see urls priority with just refreshing the page.
One way to do this is to run a scheduled task ever 10 mins which interacts with the DB. The web application also interacts with the DB and thus the two systems are distinct.
Side note: it is strongly recommended to use only console applications as scheduled tasks. If you make a windows form application will will have some issues.
As Kieren Johnstone has pointed out in another answer the best way to do this would be to write a windows service.
I still recommend the solution as described above as a first step since it is easy to debug and test.
Additionally, give some serious consideration to logging and error reporting -- with background tasks you can never know to much about what the heck it was doing when it broke.
If timing itself is not important (it doesn't have to be 10 minutes precisely), I would suggest binding to any event that fires when users use your application. No point in calculating anything if noone is using it :-)
So you could use a login, or page load, or whatever happens at an interval roughly like the interval you wish to achieve.
You can always store a DateTime variable somewhere that you can check to see when the calculation was last made. Something like:
public void MyEventHasFired()
{
DateTime dateLastProcessed = ... //Database? Session data? Anything goes.
if(dateLastProcessed < DateTime.Now.AddMinutes(-10))
{
//calculate
...
dateLastProcessed = DateTime.Now;
}
}
The best solution is definitely a Windows Service. It can be started, stopped and managed well, it's easy to log, maintain..
Scheduled Tasks are very prone to problems. At least in a Windows Service you can configure it to start automatically, re-start if there's a problem, you can control the timing yourself in the code, and catch/handle exceptions as you wish.
The best scheduler i know is Quartz.net
It'is not simple to use but it works great.
You can find an example with asp.net there http://blogs.planetcloud.co.uk/mygreatdiscovery/post/ASPNET-Scheduled-Tasks-with-QuartzNET.aspx
Anyway i agree with Kieren Johnstone: you should use a windows service

Auto populate / screen scrape multipage webform

Firstly apologies if this is a duplicate question, I have spent a while searching and can't find anything that looks to be the same.
I need to automate the completion of a multi page web form and then process the result from within an asp.net system. The ideal solution would be to create a web service which takes in some data, then processes it through the website and returns a result - I can then use this in any app that requires this functionality. The form that needs completing is quite complicated, and also includes some if / then / else logic when going through e.g:
Complete personal details
Enter postcode
If 1 result found goto 5
Display list of possible addresses, when one selected goto 5
If time at address < 3 years, display new address page
etc.
I have created a solution which launches an ActiveX browser control and controls the website as if a user were entering the data which works well however is subject to a limit on concurrent users (anything > 1 starts to cause issues, >2 is not allowed by windows default settings), is there a better way of doing this? I've heard of Selenium although not used it, would this be a possible solution?
I have looked at using the WebClient class, and have used this in the poast for screen scraping systems however I don't know how I could chain these calls together to allow for the full workflow.
FYI - this work is all being undertaken with the full knowledge and consent of the site owner. They have a queue of development tasks which building an internal API does not feature on so whilst they are happy for this type of solution to be implemented, will not be able to change anything their end.
Thanks in advance
There is a .NET port of Watir called WatiN - it might be worth giving that a try if you haven't already.

Categories

Resources