.Net Interview Questions

24

Click here to load reader

Transcript of .Net Interview Questions

Page 1: .Net Interview Questions

1) CLR: COMMON LANGUAGE RUNTIME...........................................................................................4

2) PRIVATE ASSEMBLY:...........................................................................................................................4

3) SHARED ASEMBLY:...............................................................................................................................4

4) ENABLE POSTBACK:.............................................................................................................................4

5) SIDE BY SIDE EXECUTION:.................................................................................................................4

6) ASSEMBLIES R TWO TYPES:..............................................................................................................5

7) ISPOSTBACK METHOD:.......................................................................................................................5

8) DIFFERENCE BETWEEN ARRAY AND ARRAYLIST:....................................................................5

9) EVENTHANDLERS:................................................................................................................................5

10) DIFFRENCE BETWEEN DATASET AND DATAREADER............................................................6

11) DATAADAPTER(DA):...........................................................................................................................6

12) DATAGRID(DG):....................................................................................................................................6

13) SQLCOMMAND --------..........................................................................................................................6

14) OVERLOADING(OL) OVERRIDING(OR)............................................7

15) VALIDATION:........................................................................................................................................7

16) DIFFERENCES BETWEEN ASP AND ASP.NET..............................................................................7

17) HOW CAN YOU ISOLATE A PROJECT THAT IS RUNNING ON THE SAAME WEB SERVER AS OTHER PROJECTS. THE PROJECT IS A MUST...........................................................7

18) HOW CAN YOU SAY THAT A CONTROL LIKE CHECKBOX OR ANYTHING WHEN CHECKED THAT IT REFERS TO THAT PARTICULAR FORM OR ID OF EMPLOYEE OR ANYTRHING.................................................................................................................................................8

19) WEBSERVICES DEF.............................................................................................................................8

20) WHEN YOU OVERLOAD METHODS IN WEB SERVICES , IS THERE ANY MECHANISM TO DIFFERENCIATE BETWEEN THEM USING SOAP......................................................................8

21) OTHER GENERAL POSSIBLE QUESTIONS RELATED TO UR RESUME................................8

22) TWO DISADVANTAGES BY CALLING COM COMPONENTS FROM WEB SERVICES.......8

23) WHAT R STATIC CONSTRUCTORS.................................................................................................8

24) WHAT IS THE BEST CLASS TO USE FOR STRING RELATED OPERATIONS IN ASP.NET AND WHAT IS THE DIFFERENCE BETWEEN USING THIS AND OTHER CLASSES.................8

25) WHAT IS STACKALLOC.....................................................................................................................9

26) EXPLAIN WHY WE USE EXCEPTION HANDLING.......................................................................9

27) HOW DO YOU CONFIGURE SECURITY IN ASP.NET..................................................................9

28) CAN YOU IMPORT CODE FROM VB.NET......................................................................................9

29) WHAT IS THE BENEFIT OF IT...........................................................................................................9

30) HOW MANY CLUSTER INDEXED CAN WE HAVE ON A TABLE.............................................9

31) HOW DOES A CLUSTER INDEX STORE KEYS..............................................................................9

1

Page 2: .Net Interview Questions

32) CAN WE MAKE A STORED PROCEDURE RUN EVERYTIME WE CALL IT…LETS SAY IN AN ENV WHERE THE DATA CHAGES ALWAYS...........................................................................9

33) WHAT NAMESPACE DO YOU USE FOR EXCEPTIONS IN ASP.NET.......................................9

34) HOW DO YOU HANDLE EXCEPTION IN ASP................................................................................9

35) CAN WE HAVE MULTIPLE CATCH BLOCKS FOR ONE TRY BLOCK/FLOW OF EXCEPTION BLOCK...................................................................................................................................9

36) HOW MANY AUTHENTICATION TYPES R THERE IN ASP.NET............................................10

37) WHAT IS A USER CONTROL............................................................................................................10

38) CAN YOU STORE INFO ABOUT SERVER CONTROL AND HOW...........................................10

39) DIFFERENCE BETWEEN SERVER.TRANSFER AND SERVER.EXECUTE............................10

40) WHAT IS EXECUTESCALAR AND HOW DOES IT WORK.......................................................10

41) HOW DOES MACHINE.CONFIG DEFER FROM WEB.CONFIG...............................................10

42) WHAT IF THERE IS STATIC DATA AND YOU WANT BETTER PERFORMACE................10

43) WHAT IS IMPERSONATION. WHAT IS THE DEFAULT ACCOUNT THAT IS USED BY IIS........................................................................................................................................................................10

44) WHY DO YOU NEED PASSPORT AUTHENTICATION...............................................................11

45) WHAT IS THE DEFERENCE BETWEEN GENERICPRINCIPAL AND WINDOWSPRINCIPAL.............................................................................................................................11

46) WHAT INFORMATION DOES SATELLITE ASSEMBLIES CONTAIN/HOW DO THEY DEFER FROM MAIN ASSEMBLIES.......................................................................................................11

47) WHAT IS THE TOOL USED TO GIVE STRONG NAME TO ASSEMBLY................................11

48) HOW DO YOU INSTALL ASSEMBLY IN GAC..............................................................................11

49) HOW DO YOU MAKE A METHOD ACCESSIBLE/ TO BE CALLED BY CLIENTS IN WEB SERVICES....................................................................................................................................................11

50) HOW CAN U ACCESS OR MODIFY ANY INFO COMING FROM THE CLIENT IN WEB SERVICES....................................................................................................................................................11

51) HOW DO YOU CREATE CUSTOM EXCEPTION CLASSES IN ASP.NET................................11

52) HOW DOES RUNTIME KNOW WHICH CLASS/OBJECT TO LOAD TO USE........................11

53) HOW MANY PARAMETERS R THERE IN C#...............................................................................11

54) WHAT IS THE DIFFERENCE BETWEEN REF PARAMETER AND OUT PARAMETER.....12

55) HOW DOES CODE BEHIND DEFER FROM .ASPX FILE............................................................12

56) HOW DOES A WEB FORM AND THE CODE BEHIND FILE KNOW TO BIND THE INFO OR CALL THAT PARTICULAR EVENT...............................................................................................12

57) WHAT IS THE DEFERENCE BETWEEN CHECKED AND UNCHECKED KEY WORDS IN C#...................................................................................................................................................................12

58) HOW DO YOU MAKE A METHOD IN CHILD CLASS HIDE PARENT CLASSES SAME METHOD......................................................................................................................................................12

59) WHAT IS THE BENEFIT OF USING NEW KEY WORD TO HIDE METHOD.........................12

60) HOW DO YOU CALL A BASE CLASS METHOD FROM CHILD CLASS.................................12

61) WHAT DOES FIXED KEY WORD DO IN C#..................................................................................12

2

Page 3: .Net Interview Questions

62) ARE THERE POINTERS IN C# AND HOW CAN YOU USE THEM...........................................13

63) HOW CAN YOU MAKE A CLASS SO THAT IT CAN NOT BE INHERITED?.........................13

64) HOW DOES WEB.CONFIG WORK..................................................................................................13

65) HOW DO YOU GET BETTER PERFORMANCE BY USING CLENTSIDE SCRIPTS.............13

66) CAN YOU HAVE CUSTOM AUTHENTICATION CLASSES.......................................................13

67) WHAT R THE KINDS OF LAYOUT YOU CAN HAVE IN HTML/DIFFERENCE OR ASP....13

68) WHAT IS THE DIFFERENCE BETWEEN WINDOWSPRINCIPAL AND GENERICPRINCIPAL...............................................................................................................................13

69) WHERE CAN YOU STORE USER INFO (USERNAME AND PASSWORD KIND OF THINGS).......................................................................................................................................................13

70) CAN YOU HAVE USERNAMES IN SOME OTHER PLACE OTHER THAN WEB.CONFIG. 13

71) HOW MANY DIFFERENT WAYS CAN YOU STORE THE SESSION DATA...........................14

72) WHAT IS AUTHORIZATION............................................................................................................14

73) CAN YOU HAVE YOUR OWN MODULES IN WEB.CONFIG.....................................................14

74) WHEN WILL THE CLIENT SIDE SCRIPTS ARE EXECUTED...................................................14

75) WHAT R OBJECTS THAT YOU WORK WITH WHEN DEALING WITH WEB FORM./ TO GET THE API OR WHATEVER...............................................................................................................14

76) WHAT IS THE DIFFERENCE BETWEEN SESSION OBJECT AND APPLICATION OBJECT........................................................................................................................................................................14

77) WHAT IS SERVER.TRANSFER.........................................................................................................14

78) DIFFERENCE BETWEEN MACHINE.CONFIG AND WEB.CONFIG........................................15

79) EXPLAIN ABOUT THE DIFFERENT KINDS OF AUTHENTICATION....................................15

80) WHERE CAN YOU DO ANY INITIALIZATION IN A WEB APPLICATION/ANY KIND OF INITIALIZATION THAT HAS TO BE DONE WHILE THE APPLICATION START....................15

81) WHAT IS THE SYSTEM.WEB REFER TO IN WEB.CONFIG…MODULE/NAMESPACE.....15

82) WHAT ARE THE DIFFERENT EVENTS THAT OCCUR WHILE WEBFORM PROCESSING........................................................................................................................................................................15

83) WHAT R EVENTS THAT CAN OCCUR ON A PAGE....................................................................16

84) WHAT DOES PRERENDER EVENT DOES.....................................................................................17

85) WHY DO YOU HAVE TO OVERRIDE PRERENDER EVENT....................................................17

86) WHAT IS THE BEST WAY TO DO PAGING IN WEB APPLICATIONS...................................17

87) WHAT R THE DIFFERENT MODULES THAT YOU CAN HAVE IN WEB.CONFIG.............17

88) What is a cookie…why do you use it.......................................................................................................17

3

Page 4: .Net Interview Questions

1) CLR: Common language runtimeUsed for:Type checking----------------------to see if valid operations are being performed)Garbage Collector------------------Automatic memory managementClass loader-----------------------Loads classes into runtimeMSIL to native code compiler-------converts msil to native codeSecurity Engine--------------------enforces securityThread Support---------------------Multithreading supportException Manager------------------has mechanism to handle run time exceptionsDebug Engine-----------------------allows to debug diff applicationsCom Marshaler----------------------Exchange data between .net appliactions and com environment

2) Private Assembly:Installed in the web application folder.Used by only one application.

3) Shared Assembly:Installed in Global Assembly Cache(GAC)----using gacUtil.exeShared by many applicationsTo be installed in GAC the assembly must be strong named------using sn.exe----provides a public and a private key for assemblyThe key file must be specified in Assembly with AssemblyKeyFileAttribute

4) Enable Postback:All server controls have this property--------that is to say that the form should be posted back to the server to process any requestsHtml controls by default don't have this-------but can be made to be posted back by putting "runat=server" with their declaration

5) Side by side execution:Assemblies help in side-by-side execution. Each assembly has1) Assembly metadata-----------------contains info about assembly version (number, build number, revision number, security id, resources required and scope of assembly) which is used by CLR to make a decision of which assembly to run.2) Type Metadata

4

Page 5: .Net Interview Questions

3) MSIL code----------------without assembly metadata msil code cannot be loaded and executed by CLR4) Resources

6) Assemblies r two types:1)Static2)Dynamic

1) Static-------------1) It is contained in a portable executable. (Which can be dll or exe) it contains information about types, interfaces and resources.------------------------2) They r stored on the hard disk------------------------3)It is created when you compile the program using any .net compilers.

2)Dynamic-----------1)No portability.------------------------2) not stored on HD------------------------3) Created during runtime when the application requires types from these assemblies.------------------------4) System.Reflection.Emit namespaces used in the dynamic creation of assemblies.

7) IsPostBack Method:Used for:It is used when you want to know if the form is posted back for the first time or not.

Helpful in:When you have more data and don't want to do some coding or loading of data every time the form is posted back.

8) Difference between Array and ArrayList:Array is used to store only one kind of DataArrayList is used to store Different kinds of data or objects.

9) EventHandlers:These are to handle any events from the web form.Events r to notify some method or object that something has happened.Events use Delegates to send this notification to receiving methods as they don't know which method will receive.Delegate’s r used to store method references in them so that they can call those methods. The methods which r called must have same signature as delegate (Signature--------return type, parametrs type) .

5

Page 6: .Net Interview Questions

Instance methods referred by delegates contain---------Method entry point reference and reference to object.Static methods referred by delegates contain------------Method entry point reference only.

Any event which is posted by the form can be handled both by sever and client.For a server control to handle the client event even before server side code you should add an attribute for it.

10) Difference between Dataset and DataReader1) DataSet is disconnected---only connects to database when updating or getting information from database-------- DataReader-----Connected to a Database all the time.

2) DataSet ----- U can do any updates or any modification to database using dataset DataReader ----- is read only

3) Performance:DataReader is better than DataSetReason:---------DataReader is forward only, fast and read only.Must close the DataReader.

Usage depends on how u wants the data to be

1) For example if u have millions of rows of data and want to use it and it is just static (No change) then u must use DataReader----------as it is just to read dataDataSet can not be used as it loads all the data into memory which is not very efficient in this case.

11) DataAdapter(da):1) When u use da u don't have to open connection to database explicitly.U fills the data into dataset using da.

12) DataGrid (dg):1) For paging (its like when u have more data and it is displayed on multiple pages and u want pages to be displayed) dg is the better option.2) You bind the data to dg.3)You can use BoundColumn property of dg to make any column readonly.---like when u want user to update using dg but don't want him to change any primary key column

13) SqlCommand --------U has to explicitly open the connection to database when u uses command. -Error otherwise

6

Page 7: .Net Interview Questions

s14) Overloading (OL) Overriding (OR)---------------------------------------------------------------------------1) Giving same name to methods but 1) Giving same name to many methods with different signature with same signature(parameters, return type)2)There can be multiple methods of 2)Only one method can be overrided in this type in a single class a class3)Just changing the return typeof method does not mean OL

15) Validation:For example if u have two text boxes with name and password---------and there r two required filed validators on those(to see if user has entered any info) and if u leave the two blank and send click send button then the form will not be posted back.U can put some value in Initial value property of Required field validator to check if user has changed that value or not. When user doesn't change a validation will be raised.

The only validation control for which you don't have to specify any control to validate is Custom validate control.

16) Differences between Asp and Asp.net1)asp--------code was interpretedasp.net------code is compiled so better performance

2)asp--------few server controlsasp.net------server controls like datagrid, validation controls,list boxes

3)asp---used adoasp.net-ado.net

17) How can you isolate a project that is running on the same web server as other projects? The project is a must.

Basically u have three kinds of processing env to run .net applications.1) Within IIS inetinfo.exe------which can effect iis as it is in the same process2)pooled with other applications in dllhost.exe-----default. even if any damage can affect any process but not inetinfo.exe3)separate dllhost.exe---------no affect on any process

Performance wise:

7

Page 8: .Net Interview Questions

1)within---------------better cuz all calls r in process2)pooled---------------not better than 13)isolated-------------very poor since all calls r out of process

u can isolate that project with this or else you have isolate in IIS properties which helps in doing this. When you check this and restart the server it will actually load that project into MTS explorer so MTS takes care of any damages.

18) How can you say that a control like checkbox or anything when checked that it refers to that particular form or id of employee or anythingU can provide the control with id, which in turn can be checked.

19) Webservices def----------------XML Web services are applications that provide the ability to exchange messages in a loosely coupled environment using standard protocols such as HTTP, XML, XSD, SOAP, and WSDL. XML Web service enables the building of modular applications within and across companies in heterogeneous environments making them interoperable with a broad variety of implementations, platforms and devices.

20) When you overload methods in web services, is there any mechanism to differentiate between them using soap.U can specify MessageName attribute, which will be used by soap.

21) Other general possible questions related to ur resume1)What was the project that u worked on recently2)Explain it3)What role did you play in it4)What r the main components that u were working on5)were you there from beginning to the end of project6)what kind of problem did you face during those project development related to the components and techniques u have used7)How did you resolve those problems

22) Two disadvantages by calling COM components from web services1) have to marshal the data between com and .net that is performance degradance.2)

23) what r static constructorsStatic constructors r used in initializing the class itself. They r executed when the class loads for the first time. They cannot have any parameters.

8

Page 9: .Net Interview Questions

24) What is the best class to use for string related operations in Asp.net and what is the difference between using this and other classesU can use StringBuilder for better performance. When u add two strings with +(s1+s2) the actual thing that happens inside is that those two string r destroyed (as string are immutable)and a new string which contains both contents of those string will be created. It is time consuming since there is a creation of object involved where with stringbuilder this is not the case.

25) what is StackallocAllocates a block of memory on the stack. the address of the block is stored in pointer ptr. This memory is not subject to garbage collection and therefore does not have to be pinned (via fixed). The lifetime of the memory block is limited to the lifetime of the method in which it is defined.

26) explain why we use exception handlingTo catch any unknown exception or any exceptions that might cause the program to end abnormally.

27) How do you configure security in asp.netUsing Web.Config authentication section…mode=”forms/windows/passport”

28) Can you import code from vb.netYes

29) what is the benefit of itVb is better for developing UserInterface and besides any previously coded code can be used as both of them have CLS (common language specification)

30) How many cluster indexed can we have on a tableOnly one.

31) How does a cluster index store keysIt actually stores the data physically. It uses BTrees in this process. So if you have clustered indexes then even if you have other non clustered indexes the data will be stored according to clustered index.

32) Can we make a stored procedure run everytime we call it…lets say in an env where the data chages always.Yes, you can…Using With Recompile option in the creation of the stored procedure.

33) What namespace do you use for exceptions in asp.net?System.Exception

34) How do you handle exception in aspUsing AspError object

9

Page 10: .Net Interview Questions

35) Can we have multiple catch blocks for one try block/Flow of Exception blockYes …we can…if you specify a particular catch block which contains info about the exception then that will be executed. If not the most general catch block will be executed. Any how the finally block will be executed all the time. Try…specific exception---if not general exception---finally

36) How many authentication types r there in asp.net3---forms,passport and windows…you specify this info in web.config

37) What is a user controlUser control is something that combines two or more controls to give them a single visual appearance. And it is reusable. So, for example if u need to ask the user to enter address details then u have to put all the controls like name,city,zip and all of those on every form where u need it and code it. But instead what if u have something which will have all this functionality combined in one control and the only thing u have to do then is just to drag it from the toolbox and drop it where it is needed. U r not only combining more controls into one but u r also having the necessary functionality wherever u need.

38) Can you store info about server control and howYes…Using Viewstate u can store info…Viewstate hashes the info, which prevents any corruption to the data, and this data can be retrieved when webform Is posted back to get info about controls.

39) Difference between server.transfer and server.executeServer.Transfer transfers some info to the other web form and beside it gives the executing capability to that webform.Server.Execute doesn’t give executing capability to the other web form.

40) What is ExecuteScalar and how does it workYou can update data in database directly without using DataAdapter using Executescalar, ExecuteNonQuery and ExecuteReader. ExecuteScalar returns a single value such as a count of employees or so. Even if u get multiple values from database it will return only the first row first column value.

41) How does Machine.config defer from Web.configAny changes in Machine.config effect all the applications running on that machine where as any changes to web.config affect only a particular application. However web.config overrides any settings in machine.config.

42) What if there is static data and you want better performance.U can take that info into a cache object and use it.

10

Page 11: .Net Interview Questions

43) What is impersonation? What is the default account that is used by IIS?Providing an unknown user with some kind of identification or account is called impersonation. Default---IUSER_machine

44) Why do you need Passport authentication?When you don’t want user to remember all the user names and password for all the sites that u r hosting u need passport authentication.It will store a profile for the user and helps user in using only one username/password to enter all the sites.

45) What is the deference between GenericPrincipal and WindowsPrincipalGeneric principal contains null info about the role of the userWindowsprincipal contains Windows role of the user.

46) What information does satellite assemblies contain/how do they defer from main assemblies.Satellite assemblies contain only resources where as main assembly contains assembly manifest---version info,security, MSIL code and type metadata.U use al.exe to make assemblies from resource files.

47) What is the tool used to give strong name to assembly?Sn.exe---if u want to delay the key file adding to assembly you can specify –delay in that.

48) How do you install assembly in GAC?Using GacUtil.exe

49) How do you make a method accessible/ to be called by clients in Web servicesUsing WebMethod attribute

50) How can u access or modify any info coming from the client in web servicesU have to create a class which inherits from SoapExtension or implements IHttpHandler to get information from client and you can do like---checking for security in there.But u should however have to create a new object, which references that info.

51) How do you create custom exception classes in asp.netUsing System.ApplicationException…u should inherit from this class to create custom exception classes.

52) How does runtime know which class/object to load to use?It refers to assembly which has assembly manifest---info about the assembly version, type metadata and MSIL code to load the class and the data and to compile the MSIL to native code

11

Page 12: .Net Interview Questions

53) How many parameters r there in C#4 kinds of parameters:1)out--------for output----------change in original value as ref is passed2)value-------for in parameters----no change in original value since value is passed3)ref---------for ref--------change in original value as reference is passed4)params------when u want to send multiple values but to have a single object to hold all of them-----it must be the right most parameter in the parameter list and there should be only one params parameter for a method.

54) What is the difference between ref parameter and out parameterRef parameter should be initialized in the method, which sends it as a parameterOut parameter doesn’t have to initialized. But it must be given some value before leaving the method, which was called.

55) How does code behind defer from .aspx fileCode behind contains business logic where as .aspx contains user interface.Use--------don’t have to change UI every time u change code behind it.

56) How do a web form and the code behind file know to bind the info or call that particular event? In .aspx file there is a page directive which has codebehind attribute that helps in binding info.

57) What is the deference between checked and unchecked key words in c#Both of them r used to control the overflow-checking context for integral-type arithmetic operations and conversions.

Checked--------In a checked context, if an expression produces a value that is outside the range of the destination type, the result depends on whether the expression is constant or non-constant. Constant expressions cause compile time errors, while non-constant expressions are evaluated at run time and raise exceptions.

Unchecked-----In an unchecked context, if an expression produces a value that is outside the range of the destination type, the result is truncated.

58) How do you make a method in child class hide parent classes same methodUsing new keyword in the declaration of the method.

59) What is the benefit of using new key word to hide methodIn versioning it is helpful.

60) How do you call a base class method from child classUsing base.method()

12

Page 13: .Net Interview Questions

61) What does fixed key word do in c#Prevents relocation of a variable by the garbage collector. It is permitted to use this in only unsafe context. The fixed statement sets a pointer to a managed variable and "pins" that variable during the execution of statement. Without fixed, pointers to managed variables would be of little use since garbage collection could relocate the variables unpredictably.

62) Are there pointers in C# and how can you use themYes…But it is unsafe to use pointers as those directly refer to address locations.You need to put unsafe key word around the code that uses pointers to make clear to runtime that it is unsafe to use.

63) How can you make a class so that it cannot be inherited?Use Sealed keyword in the declaration of that class

64) How does web.config workWe define or write the modules in web.config and when the application runs it takes the modules and recognizes the configuration settings for that application.

65) How do you get better performance by using Clentside scriptsAs the client side script is executed before server side code you can actually check some things like validation and so on. Besides client mail, and browser detection help in things like tooltips or performing some operations as the mouse is moved and so on.

66) Can you have custom Authentication classes?Yes. You can. You have to derive from

67) What r the kinds of layout you can have in html/difference or asp.Two kinds. 1)Grid Layout-----Default. Controls are placed exactly where you draw them and they have absolute positions. U can use it where controls are not mixed text. When u actually draw controls with this layout there will be a style attribute which specifies the control position.2)Form Layout----Controls are placed relative to other elements on the page. If you add elements at runtime you can use this. When u draw controls with this layout there won’t be a style attribute defined for this controls.

68) What is the difference between WindowsPrincipal and GenericPrincipalWindowsPrincipal actually encapsulates the WindowsIdentity and it has the information about the WindowsId and it will give the role played by this Id using ‘IsInRole’ method, which returns the if that user, is in that role. U need to set the principal to windows to get WindowsPrincipal object.Where as GenericPrincipal doesn’t actually return anything. This is the default Principal that is created if you don’t set Principal.

69) Where can you store user info (username and password kind of things)

13

Page 14: .Net Interview Questions

Either in web.config or in database.

70) Can you have usernames in some other place other than web.config.Yes…in a DataBase.

71) How many different ways can you store the session dataYou can store it: in process, out of process (stateServer or SqlServer)In process is better as data is available in the same process where as out of process degrades performance but when you have Webfarm (where the web application is run on multiple machines) SqlServer is preferred or in case of security…as in process can make you loose Data when the system crashes.

72) What is Authorization?Authorization is actually giving access of the code to the users.While authentication is just checking, if the user name/login is valid.

73) Can you have your own modules in Web.configYes you can. You use appSettings for this in the web.config or Machine.config.<appSettings><section name><add key=”” value=””/></section name><appSettings>

To get the info from these settings u use ConfigurationSettings[“key”]For example Database connection. When it has to be set only at one place or something of that sort.

74) When will the client side scripts be executed?Even before the server side code. Client side validation is provided by a jscript named WebUiValidation.js, which is downloaded separately to the client if the client browser supports DHtml.

75) What r objects that you work with when dealing with web form./ to get the api or whateverYou have Page, Response, Request, Application, Session and cache objects.

76) What is the difference between Session object and Application objectSession object is used for a single user where as Application object is used for and by the whole application.

77) What is Server.TransferIt helps in transferring some info from one web form to another. It has the form ofServer.Transfer(“webform1.aspx”,true/false)

14

Page 15: .Net Interview Questions

First option is web form name to which you want to go and the second one is whether to take info from this form to next one or not. It works only with .aspx forms. You can’t go to .html or .htm using this. U have Response.Redirect(“webform1.aspx”/webform.html)

78) Difference between Machine.config and Web.configBoth of them are used for configuring the web applications. But machine.config’s setting effect all the web applications on the machine where as web.config effects only one web application and besides it overrides any settings that were set in Machine.config.

79) Explain about the different kinds of authenticationThere are three kinds of authentication…Forms, Windows, and Passport Authentication.

80) Where can you do any initialization in a web application/any kind of initialization that has to be done while the application startIn the Application_OnStart event you can specify any initialization. This event is present in Global.asax. This file has access to session and application objects for a web application. There can only be one Global.asax file for a web application.

81) What is the System.web refer to in web.config…module/namespaceIt is a module.

82) What are the different events that occur while webform is processingASP.NET Page Framework Initialization

The page's Page_Init event is raised, and the page and control view states are restored.

During this event, the ASP.NET page framework restores the control properties and postback data.

User Code Initialization

The page's Page_Load event is raised.

Read and restore values stored previously:

Using the Page.IsPostBack property, check whether this is the first time the page is being processed.

If this is the first time the page is being processed, perform initial data binding.

Otherwise, restore control values.

Read and update control properties.

Validation The Validate method of any validator Web server controls is invoked to perform the control's specified validation.

(There is no user hook at this stage. You can test the outcome of validation in an event handler.)

Event Handling If the page was called in Perform your application-specific

15

Page 16: .Net Interview Questions

response to a form event, the corresponding event handler in the page is called during this stage.

processing: Handle the specific event

raised.

Note   Events are not raised in a particular order, except that cached control events — as specified by the control's AutoPostBack property — are always processed before the posting event.

If the page contains Types of Validation for ASP.NET Server Controls, check the IsValid property for the page and for individual validation controls.

Manually save the state of page variables that you are maintaining yourself.

Check the IsValid property of the page or of individual validation controls.

Manually save the state of controls dynamically added to the page.

Cleanup The Page_Unload event is called because the page has finished rendering and is ready to be discarded.

Perform final cleanup work: Closing files. Closing database connections. Discarding objects.

Note   It is important that expensive resources, such as database connections, be explicitly closed. Otherwise, they will remain open until the next garbage collection occurs. On a heavily loaded server, many open resources can adversely affect performance.

83) What r events that can occur on a page.Page_init(Occurs when the server control is initialized, which is the first step in the its lifecycle.),

16

Page 17: .Net Interview Questions

Page_load,(Occurs when the server control is loaded into the Page object.)

AbortTransaction(Occurs when a user aborts a transaction.)

CommitTransaction(Occurs when a transaction completes.)

Unload(Occurs when the server control is unloaded from memory.)

Disposed(Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested.)

Prerender(Occurs when the server control is about to render to its containing Page object.)

84) What does PreRender event do?Occurs when the server control is about to render to its containing Page object. Use this event to perform any updates before the output the server control is rendered to the page. Any changes in the view state of the server control can be saved during this event. Such changes made in the rendering phase will not be saved.

85) Why do you have to override prerender eventSame as above

86) What is the best way to do paging in web applications?Using DataGrid.

87) What r the different modules that you can have in web.configMany different and we can have our own modules. Like…Authentication, authorization, customErrors, globalization, compilation, debug and many more.

88) What is a cookie…why do you use it?A cookie is a small piece of information stored by the browser. Each cookie is stored in a name=value; Cookie can be used as a signature for the whole client certificate.

17