ASP and ASP.NET questions
- Explain the life cycle of an ASP .NET page.
Life cycle of ASP.Net Web Form
Page Request >> Start >> Page Init >> Page Load >> Validation >> PostBack Event Handling >> Page Rendering >> Page Unload
Page Request - When the page is requested ASP.Net determines whether the page is to be parsed and compiled or a cached verion of the page is to be sent without running the page.
Start - Page propertied REQUEST and RESPONSE are SET, if the page is pastback request then the IsPostBack property is SET and in addition to this UICulture property is also SET.
Page Initilization - In this the UniqueID of each property is SET. If the request was postback the data is not yet loaded from the viewstate.
Page Load - If it was a postback request then the data gets loaded in the control from the ViewState and control property are set.
Validation - If any control validation present, they are performed and IsValid property is SET for each control.
PostBack Event Handling - If it was a postback request then any event handlers are called.
Page Rendering - Before this the viewstate is saved from the page and RENDER method of each page is called.
Page Unload - Page is fully rendered and sent to the client(Browser) and is discarded. Page property RESPONSE and REQUEST are unloaded.
- Explain the .NET architecture.
Net architecture
The order starting from the bottom
1. Physical Hardware Machine (Intel Pentium, apple machntosh)
2. Operating System (Microsoft Windows, Linux etc)
3. Common Language Runtime (CLR)
4. Framework Class Library (FCL)
5. ADO.Net and XML Library
6. WinForm, Web Application, Web Serivces (Managed Application)
- What are object-oriented concepts?
Class: The formal definition of an object. The class acts as the template from which an instance of an object is created at run time. The class defines the properties of the object and the methods used to control the object’s behaviour.
Object: An object is an instance of a class.
Encapsulation: hides detailed internal specification of an object, and publishes only its external interfaces. Thus, users of an object only need to adhere to these interfaces. By encapsulation, the internal data and methods of an object can be changed without changing the way of how to use the object.
Inheritance: A class that derives from another class - known as the base class - inherits the same methods and properties. This promotes reuse and maintainability.
Abstraction: the describing of objects by defining their unique and relevant characteristics (properties). Whilst an object may have 100s of properties normally only those properties of importance to the situation are described. (eg life policies premiums are normally important; whereas the time of day a policy was purchased is not usually of value).
Polymorphism: Allows objects to be represented in multiple forms. Even though classes are derived or inherited from the same parent class, each derived class will have its own behavior. (Overriding and hiding methods)
- How do you create multiple inheritance in c# and .NET?
public class MyTest: IPaidInterface, ISoldInterface
- When is web.config called?
Web.config is an xml configuration file. It is never directly called unless we need to retrieve a configurations setting.
- How many weg.configs can an application have?
There can only be 1 web.config in an application.
@Param, Each directory can have a web.config file. but, the settings like httpmodules, authentication can resides in root directory’s web.config file.
- How do you set language in weg.config?
defaultLanguage=”vb”: This specifies the default code language.
debug=”true”: This specifies that the application should be run in debug mode
- What does connection string consist of?
The connection string consists of the following parts:
In general:
Server: Whether local or remote.
Uid: User Id (sa-in sql server)
Password: The required password to be filled-in here
Database: The database name.
And some fields to indicate whether the connection is trusted or not.
- Where do you store connection string?
The connection string can be stored in the WEB.Config file under element appsettings
- What is abstract class?
Abstract class connot be instantiated instead it has to be inherited. The methods in abstract class can be overridetn in the child class.
- What is difference between interface inhertance and class inheritance?
Interface inheritance -
1. The accessibility modifier in Interface is public by defalut.
2. All the methods defined in the interface class should be oveririden in the child class.
Class Inheritance -
1. There is not restriction on the acessibility modifier in a class.
2. Only the method that are defined virtual should be overriden.
- What are the collection classes?
Queue, Stack, BitArray, HashTable, LinkedList, ArrayList, NameValueCollection, Array, SortedList , HybridDictionary, ListDictionary, StringCollection, StringDictionary
- What are the types of threading models?
Single Threading: This is the simplest and most common threading model where a single thread corresponds to your entire application’s process.
Apartment Threading (STA): This allows multiple threads to exist in a single application. In single threading apartment (STA), each thread is isolated in it’s own apartment. The process may contain multiple threads (apartments) however when an object is created in a thread (i.e. apartment) it stays within that
apartment. If any communication needs to occur between different threads (i.e. different apartments) then we must marshal the first thread object to the second thread.
Free Threading: The most complex threading model. Unlike STA, threads are not confined to their own apartments. Multiple treads can make calls to the same methods and same components at the same time.
- What inheritance does VB.NET support?
Single inheritance using classes or multiple inheritance using interfaces.
- What is a runtime host?
The runtime host is the environment in which the CLR is started and managed.
- Describe the techniques for optimizing your application?
. Avoid round-trips to server. Perform validation on client.
. Save viewstate only when necessary.
. Employ caching.
. Leave buffering on unless there is a dire need to disable it.
. Use connection pooling.
. Use stored procedures instead of in-line SQL or dynamic SQL.
- Differences between application and session
The application level variable hold value at the application level and their instances are destroyed when the no more client access that application, whereas session corresspond to a individual user accessing the application.
- What is web application virtual directory?
Virtual directory is the physical location of the application on the machine.
By defalut it’s - inetpub/wwwroot
- If cookies is disabled in client browser, will session tracking work?
No, maintaning value in cokkie woont be possible. In that case you have to make use of other ways to maintain state of the data on page.
you can check whether client support cookies or not by using
Request.Browser.Cookies property.
- Will the following code execute successfully: response.write(’value of i=’+i);
Yes.
- What is a Process, Sesion and Cookie?
Process - Instance of the application
Session - Instance of the user accessing the application
Cookie - Used for storing small amount of data on client machine.
- How is Polymorphism supports in .NET?
Polymorphism supports to objects to be represent in different forms..
- What are the 2 types of polymorphism supports in .NET?
Overriding and overloading
- ASP.NET OBJECTS?
Application,Request,Responce,server and session
- What is side by side execution?
Asynchronous execution in which application keeps on running instead of waiting for the result of previous stage execution.
- Explain serialization?
Serialization is a process of converting an object into a stream of bytes.
.Net has 2 serializers namely XMLSerializer and SOAP/BINARY Serializer.
Serialization is maily used in the concept of .Net Remoting.
- Explain a class access specifiers and method acess specifiers.
1) Public : available throughout application.
2) Private : available for class and its inherited class.
3) Protected : restricted to that class only.
4) Internal : available throughout that assembly.
- What is the difference between overloading and overriding ? how can this be .NET
Very simple way to remember the diff between them.
Overriding - Method has the same signature as the parent class method.
Overloading - Method having diff parameters list or type or the return type may be different.
- Explain virtual function and its usage.
Virtual function is that which is get override by the derived class to implement polymorphism.
- How do you implement inhetance in .NET?
In C# we implement using the following signature
:
In VB.Net we implemets using the following signature
Inherits
- If I want to override a method 1 of class A and this class B then how do you declared
answer :public virtual void method1(){ }………..In class A. public override void method1(){}…………..In class B.
- Explain friend and protected friend.
Friend/Internal - Method, Properties in that class can be accessed by all the classes within that particular assembly.
Protected Friend/Protected Internal - Methods, Properties can be accessed by the child classes of that particular class in that particular assembly.
- Explain multiple and multi_level inheritance in .NET?
Multiple Inheritance: ex. Public void Employee : Persons, Iemployee. Means a class can be inherited by more than one interface OR inherited by one class and
more than one interfaces.
Multi level inheritance: ex. Public void Person () {}, Public void Customer : person {} , Public void employee : customer{}.
- What is isPostback property?
This property is used to check whether the page is being loaded and accessed for the first time or whether the page is loaded in response to the client postback.
Example:
Consider two combo boxes
In one lets have a list of countries
In the other, the states.
Upon selection of the first, the subsequent one should be populated in accordance. So this requires postback property in combo boxes to be true.
- What is dictionary base class?
Answer: Provides the abstract base class for a strongly typed collection of key/value pairs.
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
- What are indexes .NET?
Answer: Indexes are set up as a subset of data from the column it is created in an index table and a set of pointers to the physical table itself. The index tables are updated when data is inserted, updated or deleted. This can actually have negative performance impact if indexes are unnecessarily created. The overuse of indexes can become as much as burden to the application as not having indexes.
- How can indexes be implemented in .NET?
What is maximum length of VARCHAR in SQL-SERVER?
ANS.:
VARCHAR[(n)]
Null-terminated Unicode character string of length n,
with a maximum of 255 characters. If n is not supplied, then 1 is assumed.
29. How to find the SQL server version from Query Analyser
To determine which version of Microsoft SQL Server 2005 is running, connect to SQL Server 2005 by using SQL Server Management Studio, and then run the following Transact-SQL statement:
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)
The results are:
• The product version (for example, “9.00.1399.06″).
• The product level (for example, “RTM”).
• The edition (for example, “Enterprise Edition”).
For example, the result looks similar to:
9.00.1399.06 RTM Enterprise Edition
How to determine which version of SQL Server 2000 is running
To determine which version of SQL Server 2000 is running, connect to SQL Server 2000 by using Query Analyzer, and then run the following code:
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)
The results are:
• The product version (for example, 8.00.534).
• The product level (for example, “RTM” or “SP2″).
• The edition (for example, “Standard Edition”). For example, the result looks similar to:
2. How many classes can a single.NET DLL contain?
Ans. One or more
3. What are good ADO.NET object(s) to replace the
Ans. The differences includes
In
In ADO.net, it is the dataset
A recordset looks like a single table in
In contrast, a dataset is a collection of one or more tables in ADO.net
ADO.net the disconnected access to the database is used
In
In ADO.NET you communicate with the database through a data adapter (an
OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object), which makes calls to an OLE DB provider or the APIs provided by the underlying data source.
In
ADO.NET the data adapter allows you to control how the changes to the dataset are transmitted to the database.
60)What is Active Directory? What is the namespace used to access the Microsoft Active Directories?
Ans:
Active Directory is simply a hierarchical, object-orientated database that represents all of your network resources. At the top there’s typically the Organization (O), beneath that Organizational Units (OU) as containers, and finally objects that consist of your actual resources.
AD provides the ability to control who has access to what resource and when. This includes devices such as printers, files, and any other local network resource or item on the distributed network.
Within the .NET Framework we are provided with the System.DirectoryServices namespace, which in turns uses Active Directory Services Interfaces (ADSI).
66)How will you register COM+ services?
Ans: You register the component dynamically when the first instance is created.
Or, you can manually register the component with Regsvcs.exe.
To use Regsvcs.exe, follow these steps:
Click Start, point to Programs, point to Microsoft Visual Studio .NET, and
then click Visual Studio .NET Tools to open a .NET command prompt.
At a .NET command prompt, type regsvcs servicedcom.dll.
what is different between BCL and FCL in dot net?
The Base Class Library (BCL), sometimes incorrectly referred to as the Framework Class Library (FCL) (which is a superset including the Microsoft.* namespaces), is a library of types available to all languages using the .NET Framework. The BCL provides classes which encapsulate a number of common functions such as file reading and writing, graphic rendering, database interaction, XML document manipulation, and so forth. The BCL is much larger than other libraries, but has much more functionality in one package.
What is difference between web.config and machine.config?
Web config file gives the configuration setting s of a particular application and machine .config contains the configuration setting of a particular machine.the web.config settings of a particular application overwrites the machine.config
What is delegate?
Delegate encapsulates a reference to a method.
It has two types,
1.Simple delegate
At a time Only one method can be invoked by single call.
e.g:
delname()//To call that method
2.multicast delegate
At a time two or more methods can be invoked by single call.
What is virtual polymorphism?
Polymorphism means ability to take more than one form.
It likes same name but different meanings.
virtual polymorphism means method name is same for base class and derived class. It is used for instead of “override” keyword.
.NET WebDev and Web services questions
- How does ASP page work?
An ASP page is an HTML page that contains server-side scripts written on VBScript or Jscript or Perl that are processed by the Web server before being sent to the user’s browser. ASP can be combined with HTML, XML and COM to create Web sites.
Server-side scripts run when a browser requests an .asp file from the Web server. ASP is called by the Web server, which processes the requested file and executes script commands. It then formats a standard Web page and sends it to the browser.
Web Forms pages are built with ASP.NET technology. ASP.NET is built on the .NET Framework, so the entire framework is available to any ASP.NET application. Your applications can be written in any language compatible with the common language runtime, including Microsoft Visual Basic, Visual C#, and JScript .NET.
The ASP.NET page framework is a programming framework that runs on a Web server to dynamically produce and manage Web Forms pages.
Web Forms pages run on any browser or client device.
- What are the contents of cookie?
Cookie is a small amount of data and it contains page-specific information(usually user ID) the server sends to the client along with page output. Cookies can contain only strings.
- How do you create a permanent cookie?
Dim oCookie As New HttpCookie(“permanentCookie”,”Bonjour!”)
oCookie.Expires=#12/01/2006#
Response.Cookies.Add(oCookie)
- What is ViewState? What does the “EnableViewState” property do? Whay would I want it on or off?
View state is a property of Web Forms page and each control of the page to save their values so it can be used between round trips to the server.
When the page is processed, the current state of the page and controls is inserted into a string and saved in the page as a hidden field. When the page is posted back to the server, the page parses the view state string at page initialization and restores property information in the page.
EnableViewState indicates whether the page maintains its view state, and the view state of any server controls it contains, when the current page request ends.
The benefits of using ViewState are it automatically store values between multiple requests for the same page, it is saved as a hidden field of the page and no server resources required.
It is better to disable ViewState if a control or a page contain large amount of data. Saving such an amount can affect the form load. Because the view state is stored in the page itself, storing large values can cause the page to slow down when users display it and when they post it.
- Give an example of what might be best suited to place in the Application_Start and Session_Start subroutines?
In Application_Start you can initialize the variables, upload data from database table and store in ViewState or in Cache.
In Session_Start you can count the number of active sessions, automatically redirect users to the certain Web page at the beginning of the session.
- Describe the role of global.asax?
The Global.asax file is an optional file that contains code for responding to application-level events raised by ASP.NET or by HttpModules and initializing global application objects. The Global.asax file resides in the root directory of an ASP.NET-based application.
- How can you debug your.NET application?
You can debug .NET application using Visual Studio .NET.
If Visual Studio .NET is not installed you can use Systems.Diagnostics classes, Runtime Debugger (Cordbg.exe), or Microsoft Common Language Runtime Debugger (DbgCLR.exe)
System.Diagnostics includes the Trace and Debug classes for tracing execution flow, and the Process, EventLog, and PerformanceCounter classes for profiling code.
The Cordbg.exe command-line debugger can be used to debug managed code from the command-line interpreter.
DbgCLR.exe is a debugger with the Windows interface for debugging managed code.
To create ASP.NET Web applications, you use a standard deployment model: your project is compiled and the resulting files are deployed. The Web Forms code-behind class file (.aspx.vb, or .aspx.cs) is compiled into a project .dll file along with all other class files included in your project. This single project .dll file is then deployed to the server, without any source code. When a request for the page is received, the project .dll file is instantiated and executed.
You can store Connection String in Web.config file:
create a new add key in the appSettings element.
Or in the Registry
add new subkeys to the SOFTWARE key in the HKEY_LOCAL_MACHINE
ASP.NET, in conjunction with Microsoft Internet Information Services (IIS), can authenticate user credentials such as names and passwords using any of the following authentication methods:
• Windows: Basic, digest, or Integrated Windows Authentication. If the user making the request has already been authenticated in a Windows-based network, IIS can pass the user’s credentials through when requesting access to a resource.
• Microsoft Passport authentication
Passport authentication allows implementing single sign-in for multiple applications or websites that want to authenticate users. The user is expected to use only one username and password to access all the sites.
• Forms authentication
generally refers to a system in which unauthenticated requests are redirected to a registration form. The user provides credentials and submits the form. If the application authenticates the request, the system issues a cookie that contains the credentials or a key for reacquiring the identity.
• Client Certificate authentication
IIS supports the use of digital certificates and the secure sockets layer (SSL). In this scenario, either the server or the client has a certificate — a digital identification — that they have obtained from a third-party source. The certification is passed to your application with requests. It can be mapped to a Windows user account and granted appropriate permissions.
Authentication modes are: Windows, Forms, Passport, or None.
ASP.NET uses Windows authentication in conjunction with IIS authentication. It authenticates the identity using basic, digest, or Integrated Windows authentication, or some combination of them.
All users are authenticated as soon as they log on to Windows.
Passport authentication is centralized authentication service provided by Microsoft that offers a single log on and core profile services for member sites.
Form authentication generally refers to a system in which unauthenticated requests are redirected to a registration form. The user provides credentials and submits the form. If the application authenticates the request, the system issues a cookie that contains the credentials or a key for reacquiring the identity.
None authentication is used when you want to apply anonymous authentication or a custom authentication scheme.
- How.NET has implemented security for web applications?
To secure Web application, .NET uses two functions: Authentication and Authorization.
Authentication is the process of obtaining identification credentials such as name and password from a user and validating those credentials against some authority.
Authorization limits access rights by granting or denying specific permissions to an authenticated identity.
You need to create an entry in Web.Config
authentication mode=”Forms”
forms
name=”.TheCookie”
loginUrl=”/login/login.aspx”
protection=”All”
timeout=”70″
path=”/”/
/authentication
- Explain authentication levels in.NET?
Authentication can be declared only at the machine, site, or application level.
- Explain authorization levels in.NET?
Authorization controls client access to URL resources. It can be declared at any level: machine, site, application, subdirectory, or page.
- How can you debug an ASP page, without touching the code?
You can debug ASP page using either the Microsoft Script Debugger or Visual InterDev
You can handle Exceptions using Try Catch Finally block.
Also in Global.asax you can create an application-wide error handler Application_Error or create a handler in a page for the Page_Error event. Application_Error and Page_Error methods are called if an unhandled exception occurs anywhere in your page or application.
You can also use the Page class property ErrorPage that gets or sets the error page to which the requesting browser is redirected in the event of an unhandled page exception.
It works only when customErrors mode is on in Web.Config or Machine.Config.
The sub-element error of customErrors element in Web.Config can be used to define one custom error redirect associated with an HTTP status code and
defaultRedirect attribute is used to specify the default URL to direct a browser to if an error occurs. When defaultRedirect is not specified, a generic error is displayed instead.
Unmanaged code can include both C++-style SEH Exceptions and COM-based HRESULTS.
COM handles errors through HRESULT. If an exception occurs in unmanaged code, the COM HRESULT is mapped to the appropriate exception class, which is returned to .NET, where it can be handled like any other exception.
User-defined exception classes can specify whatever HRESULT is appropriate. These exception classes can dynamically change the HRESULT to be returned when the exception is generated by setting the HResult field on the exception object. Additional information about the exception is provided to the client through the IErrorInfo interface, which is implemented on the .NET object in the unmanaged process.
- What are the Page level transaction and class level transaction?
ASP.NET transaction support allows pages to participate in ongoing Microsoft .NET Framework transactions. Transaction support is exposed via an @Transaction directive that indicates the desired level of support: Required, RequiresNew, Supported, NotSupported, Disabled.
The Transaction attribute is applied at the class level too to indicate that all class methods should be run in the context of a transaction. If an unhandled exception is thrown during the execution of a class method, the transaction is aborted. Otherwise, the transaction is committed.
using System.EnterpriseServices;
[Transaction]
public class TransactionAttribute_Cl : ServicedComponent
{
}
- What are different transaction options?
Required - Shares a transaction, if one exists, and creates a new transaction, if necessary.
RequiresNew- Creates the component with a new transaction, regardless of the state of the current context.
Supported- Shares a transaction, if one exists.
NotSupported- Indicates that the object does not run within the scope of transactions. When a request is processed, its object context is created without a transaction, regardless of whether there is a transaction active.
Disabled - Ignores any transaction in the current context.
- What is the namespace for encryption?
Ans: System.Security.cryptography;
- What is the difference between application and cache variables?
ASP.NET allows you to save values using application state (an instance of the HttpApplicationState class) for each active Web application. Application state is a global storage mechanism accessible from all pages in the Web application and is thus useful for storing information that needs to be maintained between server round trips and between pages.
The memory occupied by variables stored in application state is not released until the value is either removed or replaced.
Application state is a key-value dictionary structure created during each request to a specific URL. You can add your application-specific information to this structure to store it between page requests.
Once you add your application-specific information to application state, the server manages it.
Cache data can persist for a long time, but not across application restarts. It can hold both large and small amounts of data effectively. Also, data can expire based on time set by the application code or other dependencies; this feature is not available in the Application object.
- What is the difference between control and component?
Components implement the System.ComponentModel.IComponent interface by deriving from the SystemComponent.Model.Component base class. Component is generally used for an object that is reusable and can interact with other objects. A .NET Framework component additionally provides features such as control over external resources and design-time support.
A control is a component that provides user-interface capabilities. Controls draw themselves and shown in the visual area.
The .NET Framework provides two base classes for controls: one for client-side Windows Forms controls and the other for ASP.NET server controls. These are System.Windows.Forms.Control and System.Web.UI.Control. System.Windows.Forms.Control derives from Component base class and itself provides UI capabilities.
System.Web.UI.Control implements IComponent and provides the infrastructure on which it is easy to add UI functionality.
- You have defined one page_load event in ASPx page and same page_load event in code behind, how will program run?
- Where would you use an IHttpModule, and what are the limitations of any approach you might take in implementing one?
- Can you edit data in the Repeater control? Which template must you provide, in order to display data in Repeater control? How can you provide an alternating color scheme in a repeater control? What property must you set, and what method must you call in your code, in order to bind the data from some source to the repeater?
- What is validXML document?
An XML document that references a DTD in a DOCTYPE statement
- What is well formedXML document?
An XML document that does not reference a DTD(document type definition)
Comments