Print Error Number in Exception using c#.net

  try
        {
            string d = Convert.ToString(txtData.Text);
            int f = Convert.ToInt32(d);
            lblResult.Text = Convert.ToString(f);

        }
        catch (Exception ex)
        {

            System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
            var stackFrame = trace.GetFrame(trace.FrameCount - 1);
            var lineNumber = stackFrame.GetFileLineNumber();

            lblResult.Text = Convert.ToString(ex.Message)+Convert.ToString(lineNumber);
        }

Explain About Application pool and Web Garden


Configuring Web Gardens with IIS 6.0 (IIS 6.0)

  Important
This feature of IIS 6.0 is available only when IIS is running in worker process isolation mode.
In IIS 6.0 worker process isolation mode, application pools enhance Web site or application reliability by isolating applications and the worker processes that service those applications. For even greater reliability, you can configure an application pool to be supported by multiple worker processes. An application pool that uses more than one worker process is called a Web garden. The worker processes in a Web garden share the requests that arrive for that particular application pool. If a worker process fails, another worker process can continue to process requests.
  Note
Web gardens are different from Web farms. A Web garden is configured on a single server by specifying multiple worker processes for an application pool. Web farms use multiple servers for a Web site.
Creating a Web garden for an application pool can also enhance performance in the following situations:
Robust processing of requests: When a worker process in an application pool is tied up (for example, when a script engine stops responding), other worker processes can accept and process requests for the application pool.
Reduced contention for resources: When a Web garden reaches a steady state, each new TCP/IP connection is assigned, according to a round-robin scheme, to a worker process in the Web garden. This helps smooth out workloads and reduce contention for resources that are bound to a worker process.

Procedures

Important   You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /user:Administrative_AccountName "mmc %systemroot%\system32\inetsrv\iis.msc".

To configure a Web garden by using IIS Manager

1.In IIS Manager, expand the local computer, expand Application Pools, right-click the application pool, and then click Properties.
2.Click the Performance tab, and under Web garden, in the Maximum number of worker processes box, type the number of worker processes that you want to assign to the application pool. (You must type a number greater than 1 for the application pool to become a Web garden.
3.Click OK.
Optionally, you can configure a Web garden by setting the metabase property MaxProcesses. The MaxProcesses property determines the maximum number of worker processes that an application pool allows to service its requests. A value of zero indicates an unmanaged application pool that is not served by a worker process.
The default value for the MaxProcesses property is 1, which is the default number of worker processes that service an application pool. To configure an application pool so that it is a Web garden, set the MaxProcesses property to a value greater than 1.
Important   You must be a member of the Administrators group on the local computer to run scripts and executables. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run your script or executable as an administrator. At a command prompt, type runas /profile /user:MyComputer\Administrator cmd to open a command window with administrator rights and then type cscript.exeScriptName (include the script's full path and any known parameters).

To configure a Web garden by using Adsutil.vbs

1.In the Run dialog box, type cmd, and then click OK.
2.At the command prompt, type:
cscript %SystemDrive%\Inetpub\AdminScripts\adsutil.vbs set W3SVC/AppPools/ApplicationPoolName/MaxProcesses n
Replace n with the number of worker processes that you want to service the application pool.



The IIS setting you're referring to creates multiple processes, each with its own address space.  If you're using in-process caching of any kind, including in-process session state, it can't be shared between the worker processes.  Having multiple worker processes is similar to have multiple load-balanced servers, and is useful for similar reasons: in case one worker fails, the others can pick up the load.

You don't need to have more than one worker process in order for IIS to be able to use all of your available CPUs.  Multiple threads within a single worker will do that for you.
If your system is slow with one worker process, it's probably because you have long-running synchronous tasks that are causing the worker threads to block.  Assuming you're running IIS 7, you should be able to improve the situation by making the following change to Aspnet.config in C:\Windows\Microsoft.NET\Framework\v2.0.50727:
<configuration>
    . . .
    <system.web>
        <applicationPool maxConcurrentRequestsPerCPU="24"
                         maxConcurrentThreadsPerCPU="0"
                         requestQueueLimit="5000" />
    </system.web>
</configuration>

That tells the runtime to allow 24 concurrent requests per CPU, instead of the default of 12.





Worker processes are a way of segmenting the execution of your website across multiple exe's. You do this for a couple of reasons, one if one of the workers gets clobbered by run time issues it doesn't take the others down. For example, if a html request comes in that causes the process to run off into nothing then only the other requests that are being handled by that one worker processor get killed. Another example is that one request could cause blocking against the other threads handled by the same worker.
As far as how many you need, do some load testing. Hit the app hard and see what happens with only one. Then add some more to it and hit it again. At some point you'll reach a point of truly saturating the machines network, disk, cpu, and ram. That's when you know you have the right balance.
Incidentally, you can control the number of threads used per worker process via the machine.config file. I believe the key is maxWorkerThreads.
Now, beware, if you use session, Session state is not shared between worker processes. I generally recommend avoiding session anyway but it is something to consider.
For all intents and purposes you might consider each worker process as it's own separate web server. Except they are running on the same box.
 
 

What is the difference between Web Farm and Web Garden?


I have been asked this question many times by different readers of my blog. They wanted to know about the fundamentals of Web Farms and Web Garden. In this blog post, I am going to explain the exact difference between web farm and web garden, and the advantages and disadvantages of using them. I have also described how to create web garden in different version of IIS.

Overview

Visual Studio has its own integrated ASP.NET engine which is used to run the ASP.NET Web application from Visual Studio. ASP.NET Development Server is responsible for executing all the requests and responses from the client. Now after the end of development, when you want to host the site on some server to allow other people to access, concept of web servers comes in between. A web server is responsible for providing the response for all the requests that are coming from clients. The below diagram shows the typical deployment structure of an ASP.NET Web application with a single IIS.
2
Clients request for resources and IIS process the request and send back to clients. If you want to know more details on How IIS Processes the request, please read one of my articles about “How IIS Process ASP.NET Request?”.

Web Farm

This is the case where you have only one web server and multiple clients requesting for resources from the same server. But when are is huge amount of incoming traffic for your web sites, one standalone server is not sufficient to process the request. You may need to use multiple servers to host the application and divide the traffic among them. This is called “Web Farm”. So when you are hosting your single web site on multiple web servers over load balancer is called “Web Farm”. The below diagram shows the overall representation of Web Farms.
Web Farms
In general web farm architecture, a single application is hosted on multiple IIS Server and those are connected with the VIP (Virtual IP) with Load Balancer. Load Balancer IPs are exposed to external world to access. So whenever some request will come to server from clients, it will first hit the Load Balancer, then based on the traffic on each server, LB distributes the request to the corresponding web server. These web servers may share the same DB server or may be they can use a replicated server in the back end.
So, in a single statement, when we host a web application over multiple web servers to distribute the load among them, it is called Web Farm.

Web Garden

Now, let’s have a look at what is Web Garden? Both the terms sound the same, but they are totally different from each other. Before starting with Web Garden, I hope you have a fundamental idea of what an Application Pool is and what a Worker Process is. If you have already read the article, “How IIS Processes ASP.NET Request ?”, then I can expect that you now have a good idea about both of them.
Just to recall, when we are talking about requesting processing within IIS, Worker Process (w3wp.exe) takes care of all of these. Worker Process runs the ASP.NET application in IIS. All the ASP.NET functionality inside IIS runs under the scope of worker process. Worker Process is responsible for handling all kinds of request, response, session data, cache data. Application Pool is the container of worker process. Application pool is used to separate sets of IIS worker processes and enables a better security, reliability, and availability for any web application.
apppools
Now, by default, each and every Application pool contains a single worker process. Application which contains the multiple worker process is called “Web Garden”. Below is the typical diagram for a web garden application.
WebGarden Basic
In the above diagram, you can see one of the applications containing the multiple worker processes, which is now a web garden.
So, a Web application hosted on multiple servers and access based on the load on servers is called Web Farms and when a single application pool contains multiple Worker processes, it is called a web garden.

Create Web Garden in IIS 6 and IIS 7

Now, I am going to show how you can change the Number of Worker processes in both IIS 6 and IIS 7. For IIS 6, Right Click on Application Pool > Properties > Goto Performance Tab.
WebGardenIIS6
In the “Performance Tab” section, you would have one option called “Web Garden” where worker process sets to “1”, you can set the number of worker processes that you required.
For IIS 7, Right Click on Application Pool > Go To Advance Settings > In Process Model section, you will have “Maximum Worker Processes”. You can change it more than 1 to make it as a web garden.
WebGardenIIS7
In the above image, you can also check the definition of Web Garden.
You can find one of my previous articles on the basics of the same over here.

Advantages of Web Farm and Web Garden

Now, let’s have a look into the advantages of both the Web Farms and Web Gardens.

Advantages of Web Farm

  • It provides high availability. If any of the servers in the farm goes down, Load balancer can redirect the requests to other servers.
  • Provides high performance response for client requests.
  • Provides better scalability of the web application and reduces the failure of the application.
  • Session and other resources can be stored in a centralized location to access by all the servers.

Advantages of Web Garden

  • Provides better application availability by sharing requests between multiple worker process.
  • Web garden uses processor affinity where application can be swapped out based on preference and tag setting.
  • Less consumption of physical space for web garden configuration.

How to Manage Session in Web Farm Mode?

While using session, requests are distributed among different servers. By default, session mode is set to In Proc where session data is stored inside worker process memory. But, in Web farm mode, we can share the session among all the servers using a single session store location by making it Out proc (State Server or SQL Server Mode). So, if some of the servers go down and request is transferred to the other server by the Load balancer, session data should be available for that request.
sessionWebfarm
In the above diagram, you can see that we can both the IIS server sharing the same session data which is stored in out of worker process. You can read one of my previous articles “Exploring Session in ASP.NET” where I have explained how you can configure session mode for Out Process mode.

How to Manage Session in Web Garden Mode?

When we are using Web garden where request is being taken care of by different worker process, we have to make the session mode as out process session mode as described earlier. For Web Garden, we have to configure the out process within the same server but for different worker process.
webgardenSession2
While using Web garden with your application, you need make a couple of configuration settings in web.config in <process Model> section where you need to set certain properties like cpuMask, RequestLimit, webGarden, ClientConnectCheck, etc.

Summary

When we host a web application over multiple web servers to distribute the load among them, it is called Web Farm and when one application has multiple worker processes, it is called a Web garden.
In this blog post, I have explained the very basics of what a Web Farm is and what a Web Garden is. As this blog post contains the basic information to understand the fundamentals of web farms and web garden concept, I will be posting a separate article with details configuration setting for web garden and web farm. You can read the following articles for more information:
 

select all the checkboxes in a gridview with row wise

<asp:TemplateField> 
 <HeaderTemplate> 
  <asp:CheckBox ID="CheckAllAccept" runat="server" Text="ACCEPT" onclick="checkAll(this, 'CheckAccept');" /> 
 </HeaderTemplate> 
 <ItemTemplate> 
  <asp:CheckBox ID="CheckAccept" runat="server" onclick="Check_Click(this)"/> 
 </ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField> 
 <HeaderTemplate> 
  <asp:CheckBox ID="CheckAllReject" runat="server" Text="ACCEPT" onclick="checkAll(this, 'CheckReject');" /> 
 </HeaderTemplate> 
 <ItemTemplate> 
  <asp:CheckBox ID="CheckReject" runat="server" onclick="Check_Click(this)"/> 
 </ItemTemplate> 
</asp:TemplateField> 
<script type=text/javascript>
<!--
function checkAll(elementRef, checkBoxId)
{
 var gridRef = document.getElementById('<%= GridView1.ClientID %>');
 var inputElementArray = gridRef.getElementsByTagName('input');
 var isChecked = elementRef.checked;
 for (var i=0; i<inputElementArray.length; i++)
 {
  var inputElement = inputElementArray[i];
  if ( (inputElement.type == 'checkbox') && (inputElement.id.indexOf(checkBoxId) >= 0) )
   inputElement.checked = isChecked;
 }
}
// -->
</script>