public void RestartAppPool(string appPool) { try { logger.Info("Restarting app pool: " + appPool); // Recycle app pool using (var manager = new ServerManager()) { var pool = manager.ApplicationPools[appPool]; if (pool != null) { Process process = null; if (pool.WorkerProcesses.Count > 0) { process = Process.GetProcessById(pool.WorkerProcesses[0].ProcessId); } if (pool.State == ObjectState.Stopped) pool.Start(); else pool.Recycle(); // clean up any worker thread created by app pool if (process != null) { while (!process.HasExited) { Thread.Sleep(10); } process.Dispose(); } } } //logger.Info("Successfully restarted app pool: " + appPool); } catch (Exception ex) { // logger.Error("Restart app pool error: " + ex); } }
A expert on system architect with full SDLC and Agile development experience. Skills: , C# C++ Scrum OOA/OOD javascript ASP.Net MVC XML, HTML Web Service, RESTful, WCF, Android and etc. Email me if you need help on development.
Sunday, 13 November 2011
Manage IIS Application Pool from .Net C# code
.Net framework provides a very easy-to-use API wrapper class, ServerManager, to help manage IIS system from any .Net application using either C# or VB.net. Below C# code snippet demonstrates how to restart/recycle a given AppPool in IIS.
Tuesday, 8 November 2011
JQuery extension: numeric only input text
Here is the simply but re-usable approach, IMO: create an jquery numeric extension and then use the numeric extension in your input text box:
// numeric extension jQuery.fn.onlyNumeric = function () { return this.each(function () { $(this).keydown(function (e) { var key = e.which || e.keyCode; if (!e.shiftKey && !e.altKey && !e.ctrlKey && key >= 48 && key <= 57 || key >= 96 && key <= 105 || key == 8 || key == 13 || key == 46 || key == 35 || key == 36 || key == 37 || key == 39) return true; return false; }); }); }; // use it in your input text box $('#input_box').onlyNumeric();
Wednesday, 2 November 2011
HTML meta tags for mobile or regular sites
For mobile site specifically:
<meta content='HandheldFriendly' name='true' />
<meta content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport' />
<meta name="viewport" content="width=device-width" />
<meta content='MobileOptimized' name='width' />
<meta content='HandheldFriendly' name='true' />
<meta name="google-site-verification" content="wYqVbCtxN_YM1tLTZmGkUDbEmNrSjpB7hBNp5_Avsvs" />
General meta tags for all sites:
<meta name="keywords" content="key words of you site" />
<meta name="description" content="description of your site" />
<meta http-equiv="Content-Typ" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta content='HandheldFriendly' name='true' />
<meta content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport' />
<meta name="viewport" content="width=device-width" />
<meta content='MobileOptimized' name='width' />
<meta content='HandheldFriendly' name='true' />
<meta name="google-site-verification" content="wYqVbCtxN_YM1tLTZmGkUDbEmNrSjpB7hBNp5_Avsvs" />
General meta tags for all sites:
<meta name="keywords" content="key words of you site" />
<meta name="description" content="description of your site" />
<meta http-equiv="Content-Typ" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
Subscribe to:
Posts (Atom)