20 August 2013

ASP.NET Interview Questions

1. Describe the role of inetinfo.exe, aspnet_isapi.dll and aspnet_wp.exe in the page loading process.
-inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension),the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe. 


2. What’s the difference between Response.Write() and Response.Output.Write()?


Resopnse.Output.Write..
1.Formatted output will be displayed.
2.It gives String.Format-style formatted output.
3.It writes the HTTP Output Stream.
4.As per specified options it formats the string and then write to web page.
eg: Response.Write("Welcome to asp.net")

Response.Write..
1.unformatted output will be displayed.
2.It never gives like that.
3.It writes the text stream
4.It just output a string to web page
eg: Response.Output.Write("< h2>Once again running as {0}</h2>",WindowsIdentity.GetCurrent().Name);

3. What methods are fired during the page load? 
-Init() - when the pageis instantiated,
-Load() - when the page is loaded into server memory,
-PreRender() - the brief moment before the page is displayed to the user asHTML,
-Unload() - when page finishes loading. 

4. Where does the Web page belong in the .NET Framework class hierarchy?
-System.Web.UI.Page 
5. Where do you store the information about the user’s locale? 
-System.Web.UI.Page.Culture

6. What’s the difference between Codebehind="MyCode.aspx.cs" and src="MyCode.aspx.cs"? 
-CodeBehind is relevant to Visual Studio.NET only.

Code All build Assembly is placed inside the bin folder
Src the source cs file/vb fiel is placed in the source
folder and the source file is complied and assembly is
placed inside bin folder during runtime of the aspx page

7. What’s a bubbled event? 
-When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.

8. Suppose you want a certain ASP.NET function executed on MouseOver overa certain button. Where do you add an event handler? 
-It’s the Attributesproperty, the Add function inside that property. So btnSubmit.Attributes.Add("onMouseOver","someClientCode();");

9. What data type does the RangeValidator control support? 
-Integer,String and Date.

10. Explain the differences between Server-side and Client-side code? 
-Server side code get executed on the web server in the response of request for any aspx page 
where client-side code get executed on the client browser (e.g validation of controls, dynamically hidding and displaying some of controls or there values etc)

11. What type of code (server or client) is found in a Code-Behind class? 
-Server side code is found in the code behind file (you can output a string of code that will get printed on web browser like java script , which will get executed on client browser. but only line of code that can get executed on server i.e included in code behind file)

12. Should validation (did the user enter a real date) occur server-side or client-side? Why? 
-Client-side. This reduces an additional request to the server to validate the users input.

13. What does the "EnableViewState" property do? Why would I want it on or off?
-EnableViewState property - holds the state of the web control. View state holds the proprty details as a group of a particular web control. And can be sent via HTTPEnable view state must eb enableed for transfering throught he HTTP requests.If the webserver control is using the database request then it is advisable to make the Enable viewState = false to improve the processor performance cause the database will overide the state.

14. What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other? 
-Server.transfer transfer the page processing from one page to another page without making a round trip back to the client where as response.redirect redirect to another URL and it make a round trip back to the client.

Server.transfer can not transfer page processing from one page to another if the transferred page is in separate application.

15. Can you explain the difference between an ADO.NET Dataset and an ADO Recordset? 

• A DataSet can represent an entire relational database in memory, complete with tables, relations, and views. 
• A DataSet is designed to work without any continuing connection to the original data source. 
• Data in a DataSet is bulk-loaded, rather than being loaded on demand. 
• There's no concept of cursor types in a DataSet. 
• DataSets have no current record pointer You can use For Each loops to move through the data. 
• You can store many edits in a DataSet, and write them to the original data source in a single operation. 
• Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources. 

16. Can you give an example of what might be best suited to place in the Application_Start and Session_Start subroutines? 
-Application Start - We can place code to initialize variables once during application start. (e.g db connection string)

Session Start - We can place code to initialize variables specific to the session (e.g USER ID and other specific info related to this session) 

17. If I’m developing an application that must accommodate multiple security levels though secure login and my ASP.NET web application is spanned across three web-servers (using round-robin load balancing) what would be the best approach to maintain login-in state for the users? 
-Maintain the login state security through a database.

18. Can you explain what inheritance is and an example of when you might use it?
-In Inheritance we can use one class property into another 
class..
using System;
class sample
{
public void display()
{
Console.WriteLine("C#");
}
}
class sample1:sample 
//(Inheriting the property of class sample in class sample1)
{
public void disp()
{
Console.WriteLine("C++");
}
}
class Test
{
public static void Main()
{
sample1 sm=new sample1(); //creating a object of sample1 
sm.display(); //accessing function of sample class
sm.disp();
}

19. Whats an assembly? 
-Assembly's are building blocks of .Net framework application. It contains single or multiple executable files.

20. Describe the difference between inline and code behind.
-Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.

21. Explain what a diffgram is, and a good use for one? 

1.Its an XML format.
2.Current and original versions of Data elements can be identified through Diffgram.
3.Here, loading of contents can be done through dataset.
4.It serialize its contents for transport across a network connection.
5.The column values from both the Original and Current row versions, row error information, and row order will be included.
6.Its a format intended for network data exchange and .NET remoting.

22. Whats MSIL, and why should my developers need an appreciation of it if at all? 
-MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL.

23. Which method do you invoke on the DataAdapter control to load your generated dataset with data? 
-Fill() method of DataAdapter

SqlDataAdapter da=new SqlDataAdapter();
DataSet ds=new DataSet();
da.Fill(ds);

24. Can you edit data in the Repeater control?
-No, it just reads the information from its data source

25. Which template must you provide, in order to display data in a Repeater control? 
-ItemTemplate.To display data in the ItemTemplate declare one or more Web server controls and set their data-binding expressions to evaluate to a field in the Repeater control's (that is the container control's) DataSource.

26. How can you provide an alternating color scheme in a Repeater control? 
-Using AlternateItemTemplate and setting the color in Rowstyle or in the HTML control you have used.

27. What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control? 
-You must set the DataSource property and call the DataBind
method.

28. What base class do all Web Forms inherit from? 
-System.Web.UI.Page

29. Name two properties common in every validation control? 
-ControlToValidate property and Text property.

30. What tags do you need to add within the asp:datagrid tags to bind columns manually? 
-Set AutoGenerateColumns Property to false on the datagrid tag

31. What tag do you use to add a hyperlink column to the DataGrid? 
- < asp:HyperLinkColumn>

32. What is the transport protocol you use to call a Web service? 
-SOAP(Simple Object Access Protocol). Transport Protocols: It is essential for the acceptance of Web Services that they are based on established Internet infrastructure. This in fact imposes the usage of of the HTTP, SMTP and FTP protocols based on the TCP/IP family of transports. Messaging Protocol: The format of messages exchanged between Web Services clients and Web Services should be vendor neutral and should not carry details about the technology used to implement the service. Also, the message format should allow for extensions and different bindings to specific transport protocols. SOAP and ebXML Transport are specifications which fulfill these requirements. We expect that the W3C XML Protocol Working Group defines a successor standard. 

33. True or False: A Web service can only be written in .NET? 
-False. A web service is based on SOAP (Simple Object Access Protocol). So any technology which is able to implement SOAP should be able to create a web service. For example we can create web service in .NET and Java. 

34. What does WSDL stand for? 
-WSDL stands for Web Services Description Language. It is an XML representation of the web service interface.

There are two types of the operations specified in the WSDL file as represented by theattribute of the file.

1. Document oriented operations -- are the ones which contain XML documents as input and output
2. Result oriented operations -- are the ones which contain input parameters as the input message and result as the output message

35. Where on the Internet would you look for Web services? 
-(http://www.uddi.org)
-UDDI - Universal description discovery and integration

- UDDI registry will act as a search engine for web services

36. Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box? 
-DataTextField property 

37. Which control would you use if you needed to make sure the values in two different controls matched?
-CompareValidator Control

38. True or False: To test a Web service you must create a windows application or Web application to consume this service?
-False, the webservice comes with a test page and it provides HTTP-GET method to test.

39. How many classes can a single .NET DLL contain? 
-A single Dll can contain one or many solutions as u want. 
Reason being all the classes that you are creating will be 
a part of the Project that u r working on. Once compiled 
this project will turn into a single Dll.

40. Explain how server form post-back works (perhaps ask about view state as well).
-Post Back:

The process in which a Web page sends data back to the same page on the server.

View State:

ViewState is the mechanism ASP.NET uses to keep track of server control state values that don't otherwise post back as part of the HTTP form.

ViewState Maintains the UI State of a Page
ViewState is base64-encoded.
It is not encrypted but it can be encrypted by setting EnableViewStatMAC= true & setting the machineKey validation type to 3DES.
If you want to NOT maintain the ViewState include the directive < @ Page EnableViewState= false > at the top of an .aspx page or add the attribute EnableViewState= false to any control.

41. What is the difference between a namespace and assembly name?
-A namespace is a logical naming scheme for types in which a simple type name, such as MyType, is preceded with a dot-separated hierarchical name. Such a naming scheme is completely under control of the developer. For example, types MyCompany.FileAccess.A and MyCompany.FileAccess.B might be logically expected to have functionally related to file access. The .NET Framework uses a hierarchical naming scheme for grouping types into logical categories of related functionality, such as the ASP.NET application framework, or remoting functionality. Design tools can make use of namespaces to make it easier for developers to browse and reference types in their code.
The concept of a namespace is not related to that of an assembly. A single assembly may contain types whose hierarchical names have different namespace roots, and a logical namespace root may span multiple assemblies. In the .NET Framework, a namespace is a logical design-time naming convenience, whereas an assembly establishes the name scope for types at run time. 

42. What is GAC?
-GAC stands for Global Assembly Cache. It is used for storing shared assemblies. It stores all versions of a particular assembly so that on updating an assembly the existing applications which use the earlier version do not break.

For storing an assembly into the GAC you need to sign the assembly with a strong name. For this purpose follow these steps:

1. Use sn.exe command line utility to generate a key pair
2. Add the key file name to the assembly as value for AssemblyKeyFileAttribute.
3. Build the assembly.
4. Use gacutil.exe -i command on the command prompt to install it in the cache.

43. What is Reflection?
-It extends the benefits of metadata by allowing developers to inspect and use it at runtime. For example, dynamically determine all the classes contained in a given assembly and invoke their methods.
Reflection provides objects that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object. You can then invoke the type's methods or access its fields and properties.
Namespace: System.Reflection

44. What is Delegation?
-A delegate acts like a strongly type function pointer. Delegates can invoke the methods that they reference without making explicit calls to those methods.
Delegate is an entity that is entrusted with the task of representation, assign or passing on information. In code sense, it means a Delegate is entrusted with a Method to report information back to it when a certain task (which the Method expects) is accomplished outside the Method's class.

45. Where does session maintains? How it Maintains?
-session will be maintained in serverside insted of in web server we can use SQL Server to store the session for this we have to change session state mode.session state modes are 4 types
1. InProc ( For Local WebServer)
2.OutProc (To store session in diffrent web server)
3.Sql State (Storing session in sql server)
4.Off (off)

46. What is the purpose of Execute scalar method of Command object ?
-ExecuteScalar method is used to retrieve a single value (EX: aggregate value such as Count etc) from a database

47. How to create a permanent cookie? 
-Setting a permanent cookie is similar to Session cookie except give the cookie an expiration date too. It is very common that you don't specify any arbitrary expiration date but instead expire the cookie relative to the current date using the DateAdd() function.
Response.Cookies( Name ) = myCookie;
Response.Cookies( Name ).Expires = DateAdd( m 1 Now());

48. What is caching? What are different ways of caching in ASP.NET? 
-Caching is a technique of persisting the data in memory for immediate access to requesting program calls. This is considered as the best way to enhance the performance of the application.

Caching is of 3 types:
Output Caching - Caches the whole page.
Fragment Caching - Caches a part of the page
Data Caching - Caches the data 

49. What is meant by 3-tier architecture.?
-We generally split our application into 3-Layers
1)Presentation Layer ( Where we keep all web forms Master Pages and User Controls).
2)Business Layer (Where we keep business logic). e.g Code related to manipulating data Custom Exception classes Custom Control classes Login related code if any etc. etc.
3)Data Access Layer (Where we keep code used to interact with DB). e.g. We can have the methods which are using SQL Helper (Application Block).

No comments:

Post a Comment