ASP.NET uses MTA threading model.
2. What is the use of <%@ page aspcompat=true %> attribute?
This attribute works like a compatibility option. As mentioned before ASP worked in STA model and ASP.NET works in MTA model, but what if your ASP.NET application is using a VB COM component. In order that VB COM runs properly in ASP.NET threading model we have to set attribute. After defining the ASPCOMPAT directive attribute ASP.NET pages runs in STA model thus building the compatibility between ASP.NET and old COM components that does not support MTA model.
3. If cookies are not enabled at browser end does form Authentication work?
No, it does not work.
4. What is the difference between “Web farms” and “Web garden”?
“Web farms” are used to have some redundancy to minimize failures. It consists of two or more web server of the same configuration and they stream the same kind of contents. When any request comes there is switching / routing logic which decides which web server from the farm handles the request. For instance we have two servers “Server1” and “Server2” which have the same configuration and content. So there is a special switch which stands in between these two servers and the users and routes the request accordingly.
A router in between which takes a request and sees which one of the server is least loaded and forwards the request to that server. So for request1 it route’s server1, for request2 it routes server2, for request3 it routes to server3 and final request4 is routed to server4. So you can see because we have web farm at place server1 and server2 are loaded with two request each rather than one server loading to full. One more advantage of using this kind of architecture is if one of the servers goes down we can still run with the other server thus having 24×7 uptime.
The routing logic can be a number of different options:
- Round-robin: Each node gets a request sent to it “in turn”. So, server1 gets a request, then server2 again, then server1, then server2 again.
- Least Active Whichever node show to have the lowest number of current connects gets new connects sent to it. This is good to help keep the load balanced between the server nodes
- Fastest Reply Whichever node replies faster is the one that gets new requests. This is also a good option – especially if there are nodes that might not be “equal” in performance. If one performs better than the other, then send more requests there rather than which is moving slowly?
All requests to IIS are routed to “aspnet_wp.exe” for IIS 5.0 and “w3wp.exe” for IIS 6.0. In normal case i.e. without web garden we have one worker process instance (“aspnet_wp.exe” / “w3wp.exe”) across all requests. This one instance of worker process uses the CPU processor as directed by the operating system.
But when we enable web garden for a web server it creates different instances of the worker process and each of these worker process runs on different CPU. You can see in the below diagram we have different worker process instances created which run on different CPU’s.
In short we can define a model in which multiple processes run on multiple CPUs in a single server machine are known as a Web garden.
5. How do we configure “WebGarden”?
“Web garden” can be configured by using process model settings in “machine.config” or “Web.config” file. The configuration section is named <processModel> and is shown in the following example. The process model is enabled by default enable=”true”). Below is the snippet from config file.
<processModel enable="true" timeout="infinite" idleTimeout="infinite" shutdownTimeout="0:00:05" requestLimit="infinite" requestQueueLimit="5000" memoryLimit="80" webGarden="false" cpuMask="12" userName="" password="" logLevel="errors" clientConnectedCheck=”0:00:05" />
From the above processModel section for web garden we are concerned with only two attributes “webgarden” and “cpuMask”.
webGarden : Controls CPU affinity. True indicates that processes should be affinitized to the corresponding CPU. The default is False.
cpuMask : Specifies which processors on a multiprocessor server are eligible to run ASP.NET processes. The cpuMask value specifies a bit pattern that indicates the CPUs eligible to run ASP.NET threads. ASP.NET launches one worker process for each eligible CPU. If webGarden is set to false, cpuMask is ignored and only one worker process will run regardless of the number of processors in the machine. If webGarden is set to true, ASP.NET launches one worker process for each CPU that corresponds to a set bit in cpuMask. The default value of cpuMask is 0xffffffff.
Use 1 for the processor that you want to use for ASP.NET. Use 0 for the processor that you do not want to use for ASP.NET. For example, if you want to use the first two processors for ASP.NET of a four-processor computer, type 1100.
6. What is the main difference between Gridlayout and FlowLayout ?
GridLayout provides absolute positioning for controls placed on the page. Developers that have their roots in rich-client development environments like Visual Basic will find it easier to develop their pages using absolute positioning, because they can place items exactly where they want them. On the other hand, FlowLayout positions items down the page like traditional HTML. Experienced Web developers favor this approach because it results in pages that are compatible with a wider range of browsers.
If you look in to the HTML code created by absolute positioning you can notice lot of DIV tags. While in Flow layout you can see more of using HTML table to position elements which is compatible with wide range of browsers.
7. What’s the difference between trace and debug in ASP.NET?
A. The system.Diagnostics namespace contains the Debug and
Trace classes that include shared methods.
The diffetrnce between these two classes is in the way
Trace and Debug statements are treated at the of creating a
Trace statements are included by default when the program
is compiled in to release build,where as debug statements
are not.The Debug class is used for debugging,however, the
Trace class is used for testing and optimization even after
an application is compiled and released.
8. How do you enable tracing in on an ASP.NET page?
A. Instead of enabling tracing for individual pages, you can enable it for your entire application. In that case, every page in your application displays trace information. Application tracing is useful when you are developing an application because you can easily enable it and disable it without editing individual pages. When your application is complete, you can turn off tracing for all pages at once.
When you enable tracing for an application, ASP.NET collects trace information for each request to the application, up to the maximum number of requests you specify. The default number of requests is 10. You can view trace information with the trace viewer.
By default, when the trace viewer reaches its request limit, the application stops storing trace requests. However, you can configure application-level tracing to always store the most recent tracing data, discarding the oldest data when the maximum number of requests is reached.
To enable tracing for an application
Open your Web site’s Web.config file. If no Web.config file exists, create a new file in the root folder and copy the following into it:
<?xml version="1.0"?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.web> </system.web> </configuration>
Add a trace element as a child of the system.web element.
In the trace element, set the enabled attribute to true.
If you want trace information to appear at the end of the page that it is associated with, set the trace element’s pageOutput attribute to true. If you want tracing information to be displayed only in the trace viewer, set the pageOutput attribute to false.
For example, the following application trace configuration collects trace information for up to 40 requests and allows browsers on computers other than the server of origin to display the trace viewer. Trace information is not displayed in individual pages.
<configuration> <system.web> <trace enabled="true" pageOutput="false" requestLimit="40" localOnly="false"/> </system.web> </configuration>
You can control whether tracing is enabled or disabled for individual pages. If tracing is enabled, when the page is requested, ASP.NET appends to the page a series of tables containing execution details about the page request. Tracing is disabled by default.
To enable tracing for a page
Include an @ Page directive at the top of your .aspx file.
Add a Trace attribute and set its value to true, as shown in the following example:
<%@ Page Trace="true" %>
Optionally, include the TraceMode attribute to specify the order in which you want your trace messages to appear:
Set TraceMode to SortByTime to sort trace messages in the order in which they are processed.
Set TraceMode to SortByCategory to sort trace messages by the categories that you specified in the TraceContext.Warnand TraceContext.Writemethod calls in your page or server control code.
The following example shows how to enable tracing in a page and to sort trace messages by category.
<%@ Page Language="VB" Trace="True" TraceMode="SortByCategory" %>
9. Which namespace is needed to implement debug and trace ?
A. System.diagnostic() namespace.
10. What are trace switches?
A. Trace switches helps us to control and govern the tracing behavior of a project. There are two types of trace switches ‘BooleanSwitch’ and ‘TraceSwitch’. BooleanSwitch, as the name says, is a kind of on/off switch which can be either enabled (true) or disabled (false).
‘TraceSwitch’ on the other hand offers more options rather than simple true/false like ‘BooleanSwitch’. Tracing is enabled for a TraceSwitch object using the Level property. When we set the Level property of a switch to a particular level, it includes all levels from the indicated level down. For example, if you set a TraceSwitch’s Level property to TraceLevel.Info, then all the lower levels, from TraceLevel.Error to TraceLevel.Warning, will be taken in to account. Below are the various levels in ‘TraceSwitch’ object.
Off a Outputs no messages to Trace Listeners
Error a Outputs only error messages to Trace Listeners
Warning a Outputs error and warning messages to Trace Listeners
Info a Outputs informational, warning and error messages to Trace Listeners
Verbose a Outputs all messages to Trace Listeners
TraceSwitch objSwitch = new TraceSwitch(“TraceWarningandError”, “Error in trace”) ;
objSwitch.Level = TraceLevel.Warning ;