Is it possible to write a background function in a master page that triggers after a specific period of time, say 5 hours?
function()
{
execute code from the clsGeneral Class
}
Please suggest how this can be implemented.
Pre IIS 7.5 you don't. (technically you can, but it's stupid). IIS is free to terminate your app whenever he wants, and when IIS is restarted, apps are restarted "lazily" (until someone opens a page of your web app, the web app isn't started).
From IIS 7.5 onward you could using the Application Warm-Up Module (sadly the beta was removed :-) ). With it you create a Thread that waits the specified time and does something. Quite easy.
The "right" solution is normally to create a Windows Service and use Quartz. Read here for example Scheduler for ASP.NET?
Related
We have an ASP.Net application used by many customers installed on their own servers. Because it is installed on their end with each having different databases and URL bindings etc I created a console application a while ago that gets a zip file and extracts it to c:\inetpub location to append the latest application changes. This console app is added to scheduled tasks to create an automated update.
Obviously when anyone accesses the site for the first time after it does this they have to wait a little longer whilst the site rebuilds. I changed the console application to include a Process.Start(urlofapp) so that it should hopefully do this as part of the update so the next morning that first user doesn't have to wait for the rebuild.
I have tested it ok running myself but not yet released as my concern is that this url process is kept open. Can anyone enlighten me as to whether this would be the case as I don't want this to happen or can give me any ideas as to how to rebuild the site manually as part of the console app.
IIS has had an auto-start apps feature for quite some time. You just have to enable it. You can find more info from the Gu, and the IIS site.
Safer instead to use a start page which loads everything on the server in the background. If you do this logic in an async method which in turn is called from an MVC controller for example then this can potentially run whilst the main page has finished. Alternatively use a threaded Task and show a start page that is only returned whilst setup is taking place.
Well, we have an web application deployed on:
Windows Server 2012
IIS 8.
Target .net Framework 4.0
DevExpress Ver: 13.1.8 (third-party controls)
Now the issue is this, some of the pages stop responding when we try to load them. (after few time- not specific)
To make them in working again we have to restart 'World Wide Web Publishing Service' or sometime 'IIS' as well.
But after few hours, again the pages stop responding. Browser does't even give any error message, just keep trying
to load page and go in 'Waiting for Server Response' state.
And this behavior is not for all page. Even under this scenario some other pages still work. It means application is running
but some pages are note working.
I have also check that there is no dead lock at database level.
Also, IIS 8 is enable with both 3.5 and 4.5 options.
Note: We have some other applications on the same server running fine.
Can you please suggest me that how can I resolve this issue,
Thanks
Qazi
I suggest to create a Hello World! page and load it.
If the Hello World page even doesn't load, analyse the IIS log .
especially look at the value of "Win32Status" . If its not 0, use - net helpmsg [Win32StatusCode] in command line . This should give you enough clue for troubleshooting.
I suspect it is the HTTP Compression that is causing the issue; dump the HTTP Compression in Web Extensions, and then it will behave better.
Check also your CPU and RAM workload.
I have a console application which basically sends emails once per day.
The Windows server administrator disallows this technique and doesn't want to allow extra software on the computer (launched by a scheduled task or a service).
I've been asked to evaluate the possibility of redeveloping a part of the application and integrate it into the IIS application pool but I don't think IIS can do this. Is it possible ? If so, how ?
The only approach I've looked at so far is to redevelop it as a web application and launch a web page everyday with a scheduled task, but I'd like to avoid that.
Let's analyze your options:
Use task scheduler in your server to launch console app
Use task schedule**r in your server to **web service hosted in IIS
Have an IIS application running 100% of time in an infinite loop that that checks time every minute and if it happens to be the correct time send the emails
Have a windows service.
Use task scheduler in a different server to invoke
Analyzing each one of them:
KO: Your administrator does not want console apps and process is not isolated.
KO: You have process isolated but still you are installing a console app.
OK: Not very good for performance but your fulfills your admin conditions.
KO: Your admin does not want windows services.
??: Probably your admin will not want to use an extra server
Proposed solution: As you can see only options 3 and 5 might pass the filter. Ask him
Correct solution I did similar things in the past and went for option 2. You have to convince your admin that solution 3 is a bad idea and probably 5 is already out of the question. When he had to choose the lesser of the evils option 2 is the best :-)
NOTE: You don't mention it but in case you have a SQL Server or similar you can store there an scheduled task too...
I had similar questions when I was moving from Apache servers (where it's dead easy to send a nightly email) to Windows (where you have options).
Clients have sometimes pushed me towards SQL Mail. It's not terrible. If your web app has a SQL backend, and it's okay to schedule things there, it's capable of sending emails when properly configured.
I don't think this is possible. With an IIS application you'd need something to trigger loading the application (call the web page). This itself would require a scheduled task.
You need to pound some sense into your administrator. Sorry.
I have an ASP.NET web app providing access to a database on the server. What I need is a way to run code in the background on a given schedule that auto-updates the server database from another source.
I know how to do this in a windows app by adding a timer, linking up a function to the timer tick event and starting the timer. I do not know how to do this in a web app.
Is there a start-up event for a web app or somewhere where I can start this background process regardless of whatever any users are doing on the site?
You should not do this in an ASP.NET website - this is a major no-no. You are correct in thinking to use a timer on a background .exe. You should look into creating either a Windows Task (a console .exe executed by the server task timer), or a Windows Service. I would suggest the Windows Service as that is standard practice.
If you have access to the computer hosting your site I would write a little app that was run from the Task Scheduler.
The web server is not meant to handle long-running background tasks. It's the wrong tool.
If you dont have access to the hosting computer then I would suggest building some kind of interface whereby another computer rebuilt the database and uploaded it. I'm using the terms "interface" and "upload" in the loosest, broadest sense - apply your own definition.
I was searching for a solution myself couple of months ago, and even though I haven't found enough time to try it so far, I guess I can share the link with you. Maybe you'll find it helpful.
If yes, please, let me know here.
http://quartznet.sourceforge.net/
How to use Quartz.net with ASP.NET
you can use Windows Service or use Timer Control (In the Ajax Category)
Or
As other answers have stated, doing this full function - updating a database and scheduling it as an ASP.NET app is using the wrong tool for the job.
ASP.NET can be used to update a database - that's perfectly valid. Where it breaks down is in the timer. ASP.NET apps aren't meant to be long-running, which is necessary for the timer to work.
If you can do it, I'd strongly suggest using the approach others have suggested - a Windows Service or a Scheduled Task.
However, if you have no access to the actual server, other than to post ASP.NET code - you can't install a service and you can't set up a Windows app to run on a scheduled basis, here's an out-of-the box idea.
Set up a web service or ASPX page that does the update, and then call that page from a scheduled task on a machine you DO control.
So if this was at http://www.someserver.net/updatedb.aspx, there's no reason you can't set a scheduled task on your own PC to call that URL.
I'd consider this a last-ditch solution to be used only if you can't do one of the other options.
The global.asax.cs file has a method that is fired when your application starts: Application_Start. You can hook up your timer method in that event. Just beware, depending on how IIS configured, your app pool may shutdown. For example, if no one hits the site in 20 minutes for example. Just make sure if you HAVE to have this run every X minutes that you have IIS configured to ALWAYS be running and start your app. This is harder than it sounds. In the end, you may want to go with a regular windows scheduled task.
I am developing a project for college and i need some suggestions over the development. Its a website which shows information from other websites like Links, Images etc.
I have prepared below given model for the website.
A Home.aspx page which shows data from tables (sql server).
I have coded a crawler (in c#) which can crawl (fetch data) required website data.
I want some way through which i can run the crawler at back end for some time interval and it can insert updates in the tables. I want that i can get updated information in my database so that Home.aspx shows updated info. (Its like smaller version of Google News website)
I want to host the wesbite in Shared Hosted Environment (i.e a 3rd party hosting provider company and that may use IIS platform)
I posted simliar situation to different .NET forums and communities and they suggested lot of different things such as
Create a web service (is it really necessary ?)
Use WCF
Create a Console application and run windows task sheduler (is it okay with asp.net (win forms website) and in shared hosted)
Run crawler on local machine and update database accordingly. (No i want everything online) etc etc
Please suggest me a clear way out so that i complete the task. Please suggest elobrated technology and methods which suits my project.
Waiting...
Thanks...
Your shared host constraint really impacts on technologies restrictions.
In theory, the best way to host your crawler would have been a Windows service, since you can take advantage of windows services configuration. A service is always up, can be automatically started at startup, writes errors in event log, can be automatically restarted after failure...
Then, you Home.aspx would have been a regular website in IIS.
If you really stay on a shared host (where you cannot setup a service), I would have make the crawler as a module which is run on your application startup.
Problem is, IIS application pool doesnt live forever if your web site is not in use, and it may stop the crawler. It is configurable, but I dont know how much in a shared host.
In IIS 7.5, think about starting your module at application warm up
Finally if you need to run the crawler at interval times (like every day at midnight), if your shared host does not let you set task scheduling, think about Quartz Framework, which allow you perform task scheduling inside your application (without the intervention of the OS)
Integrate your crawler code into a aspx page
Setup a task scheduler on your host to call that page every X minutes
When the page is called check that localhost has called the page
If localhost called it run the crawl routine and
If localhost hasn't called it throw a 404 eror