cookieChoices = {};

Wednesday, 20 August 2014

Important ASP DOTNET Interview Questions

What is ASP?

ASP or Active(X) Server Pages is a Microsoft CGI-like technology that allows you to create dynamically genereated web pages from the server side using a scripting language such as VBScript or JavaScript.
It has certain built-in 'objects' that can be used to store and retrieve variables, get information from user submitted forms, get information about the server itself and, of course, write HTML based on this information.
ASP also allows you to run objects on the server which provide access to ODBC compliant databases through ActiveX Data Objects or custom components which provide any function or service that can be programmed in Windows.

What servers support ASP?

Natively, Microsoft's Internet Information Server and the latest Peer Web Server support ASP (which is free with the NT option pack - you can d/l and install a version for Win 95/98 as well).
However a company called chilisoft (www.chilisoft.com) has a product called Chilisoft ASP which provides support to a wide variety of web servers, including Apache, Lotus, Netscape, O'Reilly, Sun Solaris and IBM AIX with a constantly growing list.

How Does ASP Differ from HTML?
Ø  When a browser requests an HTML file, the server returns the file
Ø  When a browser requests an ASP file, IIS passes the request to the ASP engine. The ASP engine reads the ASP file, line by line, and executes the scripts in the file. Finally, the ASP file is returned to the browser as plain HTML

What can ASP do for you?
Ø  Dynamically edit, change or add any content of a Web page
Ø  Respond to user queries or data submitted from HTML forms
Ø  Access any data or databases and return the results to a browser
Ø  Customize a Web page to make it more useful for individual users
Ø  The advantages of using ASP instead of CGI and Perl, are those of simplicity and speed
Ø  Provides security since your ASP code can not be viewed from the browser
Ø  Since ASP files are returned as plain HTML, they can be viewed in any browser
Ø  Clever ASP programming can minimize the network traffic

Lifetime of Variables

Ø  A variable declared outside a procedure can be accessed and changed by any script in the ASP file.
Ø  A variable declared inside a procedure is created and destroyed every time the procedure is executed. No scripts outside the procedure can access or change the variable.
Ø  To declare variables accessible to more than one ASP file, declare them as session variables or application variables.

Session Variables

Session variables are used to store information about ONE single user, and are available to all pages in one application. Typically information stored in session variables are name, id, and preferences.

Application Variables

Application variables are also available to all pages in one application. Application variables are used to store information about ALL users in a specific application.



 

 

ASP Forms

                The Request.QueryString and Request.Form commands may be used to retrieve information from forms, like user input.

          Request.QueryString
The Request.QueryString command is used to collect values in a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.
      Request.Form
The Request.Form command is used to collect values in a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

 

 

ASP objects


                1. Response Object - used to send output to the user from the server.
          2. Request Object - used to get information from the user.     
          3. Application Object
The Application object is used to store and access variables from any page, just like the Session object. The difference is that ALL users share one Application object, while with Sessions there is one Session object for EACH user.
The Application object should hold information that will be used by many pages in the application (like database connection information). This means that you can access the information from any page. It also means that you can change the information in one place and the changes will automatically be reflected on all pages.
          4.Session Object
The Session object is used to store information about, or change settings for a user session. Variables stored in the Session object hold information about one single user, and are available to all pages in one application.
The server creates a new Session object for each new user, and destroys the Session object when the session expires.
          5.Server Object
The ASP Server object is used to access properties and methods on the server.
          6.Error Object
The ASPError object is used to display detailed information of any error that occurs in scripts in an ASP page. The ASPError object is implemented in ASP 3.0 and it is only available in IIS5.

      The FileSystemObject Object
The FileSystemObject object is used to access the file system on the server. This object can manipulate files, folders, and directory paths. It is also possible to retrieve file system information with this object.
      The TextStream Object
The TextStream object is used to access the contents of text files.
The Drive Object
The Drive object is used to return information about a local disk drive or a network share. The Drive object can return information about a drive's type of file system, free space, serial number, volume name, and more.
You cannot return information about a drive's content with the Drive object. For this purpose you will have to use the Folder object.

To work with the properties of the Drive object, you will have to create an instance of the Drive object through the FileSystemObject object. First; create a FileSystemObject object and then instantiate the Drive object through the GetDrive method or the Drives property of the FileSystemObject object.
         
          File Object - used to return information about a specified file.
Folder Object  -The Folder Object is used to return information about a specified folder.
Dictionary Object
The Dictionary object is used to store information in name/value pairs  (referred to as key and item)
         
Comparing Dictionaries and Arrays:
·         Keys are used to identify the items in a Dictionary object
·         You do not have to call ReDim to change the size of the Dictionary object
·         When deleting an item from a Dictionary, the remaining items will automatically shift up
·         Dictionaries cannot be multidimensional, Arrays can
·         Dictionaries have more built-in functions than Arrays
·         Dictionaries work better than arrays on accessing random elements frequently
·         Dictionaries work better than arrays on locating items by their content

How do u get the IP address of the person visiting web site?

<%
' RETURNS THE REQUESTER IP TO anyVariable
anyVariable = Request.ServerVariables("REMOTE_ADDR")
%>

What is the adovbs.inc file used for?

The adovbs.inc file which you often see in ASP is the VBScript constants definition include file for ActiveX Data Objects. All this file does is give more meaningful names to certain constants that exist when accessing databases.

Why does RecordSet.RecordCount give me -1 as a return value?

          The RecordCount property is a read-only property available only to recordsets opened with one of two kinds of cursortypes.
Will return actual RecordCount: adOpenKeyset adOpenStatic
Will return -1: adOpenForwardOnly (the default value) adOpenDynamic


What is Remote Scripting, and how do I use it?
                Remote scripting is a Microsoft technology that allows you to establish a kind-of client-server connection through an ASP page with a Java Applet.
This allows you to make calls to the server without changing the state of your HTML page (re-writing it). It makes for nicer looking web pages and also allows asyncronous calls of functions. So it's a very handy way to run long scripts without making the client wait for the page to load.



         


How do I prevent my ASP pages from caching?

At the top of the page:
<%
Response.ExpiresAbsolute = #2000-01-01#
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, must-revalidate"
%>
If you find that you're still getting the old page, after clearing your browser's page and even deleting the file from the server, then IIS has it cached. You can clear this by going into the IIS Admin interface and unchecking "Cache ISAPI Applications", hitting apply, uploading the new file, and turning the setting back on. You can also do this by issuing an iisreset call or unloading your application, at the cost of interrupted service.

How do I execute a DOS command / batch file / exe from ASP?

          If you have Windows Script Host installed and enabled, you can do this (sorry, I've only had the time to test .bat files):

<%
set wshell = server.createobject("wscript.shell")
wshell.run "c:\file.bat"
set wshell = nothing
%>

Where c:\file.bat is something like:

net stop iisadmin /y
net start w3svc

If you do not have the ability to use WSH, you can use ASPExec or DynuExec.



What are session cookies?
Session cookies are almost the same as normal cookies but are deleted from your computer within about 20 minutes of leaving the site or as soon as you close your web browser.

To check that you have cookies and session cookies enabled in IE go to 'Tools' at the top of the screen and select 'Internet Options'. Under the 'Security Settings' you have a button for 'Custom Level...' in here you can check to see if you have cookies and session cookies enabled.



1. How do you register a component?
Expected answer:
Compiling the component, running REGSVR32 MyDLL.dll
2. Name and explain the different compatibility types when creating a COM component.
Expected answer:
No Compatibility ? New GUID created, references from other components will not work
Project Compatibility ? Default for a new component <Not as critical to mention this one>
Binary Compatibility ? GUID does not change, references from other components will work
3. Why is it important to use source control software for source code?
Expected answer:
Modification history.
Code ownership: Multiple people can not modify the same code at the same time.
4. What two methods are called from the ObjectContext object to inform MTS that the transaction was successful or unsuccessful?
Expected answer:
SetComplete and SetAbort.

5. What is the tool used to configure the port range and protocols for DCOM communications?
Expected answer:
DCOMCONFIG.EXE
6. What does Option Explicit refer to?
Expected answer:
All variables must be declared before use. Their type is not required.
7. What are the different ways to Declare and Instantiate an object in Visual Basic 6?
Expected answer:
Dim obj as OBJ.CLASS with either
Set obj = New OBJ.CLASS or
Set obj = CreateObject(?OBJ.CLASS?) or
Set obj = GetObject( ,? OBJ.CLASS?)
or
Dim obj as New OBJ.CLASS
8. Name the four different cursor types in ADO and describe them briefly.
Expected Answer:
The cursor types are listed from least to most resource intensive.
Forward Only ? Fastest, can only move forward in recordset
Static ? Can move to any record in the recordset. Data is static and never changes.
KeySet ? Changes are detectable, records that are deleted by other users are unavailable, and records created by other users are not detected
Dynamic ? All changes are visible.
9. Name the four different locking type in ADO and describe them briefly.
Expected Answer:
LockPessimistic ? Locks the row once after any edits occur.
LockOptimistic ? Locks the row only when Update is called.
LockBatchOptimistic ? Allows Batch Updates.
LockReadOnly ? Read only. Can not alter the data.
10. Describe Database Connection pooling (relative to MTS )
Expected Answer:
This allows MTS to reuse database connections. Database connections are put to ?sleep? as opposed to being created and destroyed and are activated upon request.
11. What are the ADO objects? Explain them. Provide a scenario using three of them to return data from a database.
Expected Answer:
Connection ? Connects to a data source; contains the Errors collection
Command ? Executes commands to the data source. Is the only object that can accept parameters for a stored procedure.
Recordset ? The set of data returned from the database.
Scenario: There are many possibilities. The most likely is as follows:
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Cmd As ADODB.Command
conn.ConnectionString = ?CONNECTION STRING?
conn.Open
Set Cmd.ActiveConnection = conn
Cmd.CommandText = ?SQL STATEMENT?
Set rs = Cmd.Execute
Set rs.ActiveConnection = Nothing
conn.Close
12. Under the ADO Command Object, what collection is responsible for input to stored procedures?
Expected answer:
The Parameters collection.
13. What are some benefits of using MTS?
Expected answer:
Database Pooling, Transactional operations, Deployment, Security, Remote Execution.
14. What is the benefit of wrapping database calls into MTS transactions?
Expected answer:
If database calls are made within the context of a transaction, aborting the transaction will undo and changes that occur within that transaction. This removes the possibility of stranded, or partial data.
15. Describe and In Process vs. Out of Process component. Which is faster?
Expected answer:
An in-process component is implemented as a DLL, and runs in the same process space as its client app, enabling the most efficient communication between client and component.Each client app that uses the component starts a new instance of it.
An out of process component is implemented as an EXE, and unlike a dll, runs in its own process space. As a result, exe's are slower then dll's because communications between client and component must be marshalled across process boundaries. A single instance of an out of process component can service many clients.
15. What are the main components of the ADO object model? How are they used?
Expected answer:
Connection: Used to make a connection between your app and an external data source, ie, sql server.
Command: Used to build queries, including user-specific parameters, to access records from a data source (which are returned in a Recordset)
Recordset:Used to access records returned from an SQL query. With a recordset, you can navigate returned records. You can also add, modify or delete records.

How do I pass Query Strings with spaces in them? Microsoft Active Server Pages (ASP) seems to return values only up to the spaces.
You should use Server.UrlEncode to encode the values before you pass them as query strings.

On what operating systems does ASP run?

          The "native" operating system for ASP is the Windows (95, 98, NT). The option pack you download from Microsoft can be installed on Windows only.

However, there are third-party tools/add-ons that enable us to run ASP on non-Windows platforms too. Two of such software are:

Which is easier to learn, VBScript or JavaScript? How do I decide which one to learn?

Depends on who you ask. If you have Visual Basic programming experience,

VBScript is easier to pick up. On the other hand, a Java programmer will find learning JavaScript easier.

Several factors before you choose a scripting language:
VBScript is similar to Visual Basic language. So, if you are familiar with VB, VBScript is easier to pick up. Also VBScript has good error handling capabilities, while JavaScript (currently) has none. So, if you are developing a lot of database applications, VBScript maybe the way to go.
JavaScript is more universal client-side scripting language than VBScript. If you are using a lot of client-side validations etc., JavaScript maybe better as you have to learn just one language for both server and client side.


Can Active Server Pages use Java?
Yes. Active Server Pages supports ActiveX server components written in any language, including Java. In addition, ASP includes the Microsoft Windows reference standard Java Virtual Machine.


How does ASP work?


 The process of running an ASP file:

A user enters the Internet address of an ASP in the location bar.

The browser sends a request for the ASP page to IIS.

The web server receives the request and recognizes that the request is for an ASP file because of the extension '.asp'.

The web server retrieves the proper ASP file from disk or memory.

The web server sends the file to a special program called 'ASP.dll'.

The ASP file is processed from top to bottom and any encountered commands are executed. The result of this process is a standard HTML file.

The HTML file is sent back to the browser.

The HTML file is interpreted by the person's Web browser and the results are displayed in the browser window.



Why should I choose ASP as opposed to CGI or other scripting methods?


          There are three main reasons to use ASP:

 Performance — With CGI, each script is run as an executable in its own process. As a result, each time a script is requested the server must: create new process, run the script, kill the (just created) process. This is inefficient and can severely impact the performance of the Web server. The Active Server Pages host is not re-launched with every script access and is therefore much more efficient.
Session management — Because HTTP is stateless, keeping track of data between page accesses by a user is a tough problem. ASP provides built-in session management functionality that allows developers to persist data and also COM component instances (like database connections) for the duration of a session.
Easy integration of COM components — ASP is designed to rely heavily on COM components for its extensibility. As a result, it is very easy to instantiate and use any COM component from within an ASP script.

Can I send e-mail from an ASP script?


Yes. If you're using ASP on a server with the NT 4.0 Option Pack installed and Microsoft SMTP Service (from the Option Pack) running then you can use the CDONTS component to easily send Internet e-mail from your ASP script. There are also a number of custom components available from third-party sources that provide more configuration options and do not require Microsoft's SMTP service or the Option Pack. The most popular of these components is ASPMail.




No comments:

Post a Comment