Pages

Ads 468x60px

For New Update Use this Link http://dotnethubs.blogspot.in/

Monday, 18 February 2013

Basic Asp.net and C# interview Question And Answer


1. What is ASP?

Active Server Pages (ASP), also known as Classic ASP, is a Microsoft's server-side technology, which helps in creating dynamic and user-friendly Web pages. It uses different scripting languages to create dynamic Web pages, which can be run on any type of browser. The Web pages are built by using either VBScript or JavaScript and these Web pages have access to the same services as Windows application, including ADO (ActiveX Data Objects) for database access, SMTP (Simple Mail Transfer Protocol) for e-mail, and the entire COM (Component Object Model) structure used in the Windows environment. ASP is implemented through a dynamic-link library (asp.dll) that is called by the IIS server when a Web page is requested from the server.

2. What is ASP.NET?

ASP.NET is a server side scripting technology that enables scripts (embedded in web pages) to be executed by an Internet server. ASP.NET provides increased performance by running compiled code.

3. What is the basic difference between ASP and ASP.NET?

The basic difference between ASP and ASP.NET is that ASP is interpreted; whereas, ASP.NET is compiled. This implies that since ASP uses VBScript; therefore, when an ASP page is executed, it is interpreted. On the other hand, ASP.NET uses .NET languages, such as C# and VB.NET, which are compiled to Microsoft Intermediate Language (MSIL).

4. In which event are the controls fully loaded?

Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init events but you will see that view state is not fully loaded during this event

5. How can we identify that the Page is Post Back?

Page object has an "IsPostBack" property, which can be checked to know that is the page posted back.

6. What is the lifespan for items stored in ViewState?

PThe items stored in ViewState live until the lifetime of the current page expires including the postbacks to the same page.

7. How information about the user's locale can be accessed?

The information regarding a user's locale can be accessed by using the System.Web.UI.Page.Culture property.

8. What is the difference between SQL notification and SQL invalidation?

The SQL cache notification generates notifications when the data of a database changes, on which your cache item depends. The SQL cache invalidation makes a cached item invalid when the data stored in a SQL server database changes.

9. Which is the parent class of the Web server control?

class is the parent class for all Web server controls.

10. Can you set which type of comparison you want to perform by the control?

Yes, by setting the Operator property of the CompareValidator control. 11. What is the behavior of a Web browser when it receives an invalid element? The behavior of a Web browser when it receives an invalid element depends on the browser that you use to browse your application. Most of the browsers ignore the invalid element; whereas, some of them display the invalid elements on the page.

12. What are the advantages of the code-behind feature?

The code-behind feature of ASP.NET offers a number of advantages: * Makes code easy to understand and debug by separating application logic from HTML tags * Provides the isolation of effort between graphic designers and software engineers * Removes the problems of browser incompatibility by providing code files to exist on the Web server and supporting Web pages to be compiled on demand.

13. How do you sign out from forms authentication?

The FormsAuthentication.Signout() method is used to sign out from the forms authentication.

14. What is AutoPostBack?

If you want a control to postback automatically when an event is raised, you need to set the AutoPostBack property of the control to True.

15. What is the function of the ViewState property?

The ASP.NET 4.0 introduced a new property called ViewStateMode for the Control class. Now you can enable the view state to an individual control even if the view state for an ASP.NET page is disabled.

16. Why do you use the App_Code folder in ASP.NET?

The App_Code folder is automatically present in the project. It stores the files, such as classes, typed data set, text files, and reports. If this folder is not available in the application, you can add this folder. One of the important features of the App_Code folder is that only one dll is created for the complete folder, irrespective of how many files it contains.

17. Define a multilingual Web site ?

A multilingual Web site serves content in a number of languages. It contains multiple copies for its content and other resources, such as date and time, in different languages.

18. What is an ASP.NET Web Form?

ASP.NET Web forms are designed to use controls and features that are almost as powerful as the ones used with Windows forms, and so they are called as Web forms. The Web form uses a server-side object model that allows you to create functional controls, which are executed on the server and are rendered as HTML on the client. The attribute, runat="server", associated with a server control indicates that the Web form must be processed on the server.

19. What is the difference between Classic ASP and ASP.Net?

ASP is Interpreted language based on scripting languages like Jscript or VBScript. 1) ASP has Mixed HTML and coding logic. 2) Limited development and debugging tools available. 3) Limited OOPS support. 4) Limited session and application state management. ASP.Net is supported by compiler and has compiled language support. 5) Separate code and design logic possible. 6) Variety of compilers and tools available including the Visual studio.Net. 7) Completely Object Oriented. 8) Complete session and application state management. 9) Full XML Support for easy data exchange.

20. What is Difference between Namespace and Assembly?

amespace is a logical design-time naming convenience, whereas an assembly establishes the name scope for types at run time.

21.What is the difference between early binding and late binding?

Calling a non-virtual method, decided at a compile time is known as early binding. Calling a virtual method (Pure Polymorphism), decided at a runtime is known as late binding.

22. What is the difference between ASP Session and ASP.NET Session?

Asp.net session supports cookie less session & it can span across multiple servers.

23. How many languages .NET is supporting now?

When .NET was introduced it came with several languages. VB.NET, C#, COBOL and Perl, etc. 44 languages are supported.

24.Can ASP pages and ASP.Net pages share session variables.
 
No. Both support session variables, but the session variables are not shared across the two platforms.

25. What is the process-flow for ASP.Net?
 
1. User requests an ASPx page in their browser

2. An HTTP requests is sent to IIS

3. The xspisapi.dll isapi filter intercepts the request and passes the request on to the XSP worker process (xspwp.exe)

4. Xspwp takes care of handing the request to the appropriate HTTPModules and finally an HTTPHandler as defined in the configuration files.

5. The ASPX page is read from the HD or cache and server code is loaded into memory and executed.

6. The server side code outputs normal HTML which is handed back through the chain of modules and eventually to IIS, which sends the response back to the client’s browser.

7. If the user clicks or otherwise acts on an HTML element (say, a textbox) that has a server side event handler, the form is posted back to the server with hidden form fields containing information as to what control and event occurred.  Some controls do not automatically post by default, but wait for a button_click event to post.  This is configurable by the developer.

8. The ASPx page is again loaded into memory using the same sequence of events as before, but this time ASP.net reads in the hidden form field data and automagically triggers the appropriate _OnChange, OnClick and other appropriate event handlers.

9. Resulting HTML is sent to the browser

10. The process continues in a continual "Post Back" cycle.

26 . Definition of HTTP Modules:


HTTP modules are a logical replacement for ISAPI filters.  Modules are a class that can participate in every web request.  This is appropriate for code that should run on every request, such as caching, authentication or state management

27. Definition of HTTP Handlers:


HTTP Handlers provide the end point in the processing of a web request and are equivalent to ISAPI Extensions today.  For example, many handlers can be involved in the request for an ASPX page, but only 1 handler is invoked.  The handler runs after the HTTP modules have run.  Which handler is invoked is determined by configuration settings in the config.web file.  Handlers are assigned to handle requests based on the extension of the page requested.

28. What is ViewState:

ViewState is used to retain the state of server-side objects between page post backs.

29. In which event of page cycle is the ViewState available?


After the Init() and before the Page_Load().

30. From which base class all Web Forms are inherited?

Page class.

31. How long the items in ViewState exists?

They exist for the life of the current page.

32. Where the viewstate is stored after the page postback?


ViewState is stored in a hidden field on the page at client side. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.

33 . What are the different Session state management options available in ASP.NET?


  1. In-Process
  2. Out-of-Process.
In-Process stores the session in memory on the web server.
Out-of-Process Session state management stores data in an external server.  The external server may be either a SQL Server or a State Server.  All objects stored in session are required to be serializable for Out-of-Process state management.

33 . How you can add an event handler?

 Using the Attributes property of server side control.
e.g.
?
1
btnSubmit.Attributes.Add("onMouseOver","JavascriptCode();")

35 . What is caching?

Caching is a technique used to increase performance by keeping frequently accessed data or files in memory. The request for a cached file/data will be accessed from cache instead of actual location of that file.
14. What are the different types of caching?
ASP.NET has 3 kinds of caching :
  1. Output Caching,
  2. Fragment Caching,
  3. Data Caching.

36. Which type if caching will be used if we want to cache the portion of a page instead of whole page?

Fragment Caching: It caches the portion of the page generated by the request. For that, we can create user controls with the below code:
?
1
<%@ OutputCache Duration="120" VaryByParam="CategoryID;SelectedID"%>

37. List the events in page life cycle.

  1) Page_PreInit
2) Page_Init
3) Page_InitComplete
4) Page_PreLoad
5) Page_Load
6) Page_LoadComplete
7) Page_PreRender
8)Render

38. Can we have a web application running without web.Config file?

  Yes

39. Is it possible to create web application with both webforms and mvc?

Yes. We have to include below mvc assembly references in the web forms application to create hybrid application.

1
2
3
 System.Web.Mvc
 System.Web.Razor
 System.ComponentModel.DataAnnotations

40. Can we add code files of different languages in App_Code folder?

  No. The code files must be in same language to be kept in App_code folder.

41. What is Protected Configuration?

It is a feature used to secure connection string information.

42. Write code to send e-mail from an ASP.NET application?

1
2
3
4
5
6
7
        MailMessage mailMess = new MailMessage ();
        mailMess.From = "abc@gmail.com";
        mailMess.To = "xyz@gmail.com";
        mailMess.Subject = "Test email";
        mailMess.Body = "Hi This is a test mail.";
        SmtpMail.SmtpServer = "localhost";
        SmtpMail.Send (mailMess);
MailMessage and SmtpMail are classes defined System.Web.Mail namespace.

 43. How can we prevent browser from caching an ASPX page?

  We can SetNoStore on HttpCachePolicy object exposed by the Response object’s Cache property:
1
2
Response.Cache.SetNoStore ();
 Response.Write (DateTime.Now.ToLongTimeString ());  

44. What is the good practice to implement validations in aspx page?

Client-side validation is the best way to validate data of a web page. It reduces the network traffic and saves server resources.

45. What are the event handlers that we can have in Global.asax file?


Application Events: Application_Start , Application_End, Application_AcquireRequestState, Application_AuthenticateRequest, Application_AuthorizeRequest, Application_BeginRequest, Application_Disposed,  Application_EndRequest, Application_Error, Application_PostRequestHandlerExecute, Application_PreRequestHandlerExecute,
Application_PreSendRequestContent, Application_PreSendRequestHeaders, Application_ReleaseRequestState, Application_ResolveRequestCache, Application_UpdateRequestCache
Session Events: Session_Start,Session_End

46. Which protocol is used to call a Web service?

HTTP Protocol

47. Can we have multiple web config files for an asp.net application?

Yes.

48. What is the difference between web config and machine config?

Web config file is specific to a web application where as machine config is specific to a machine or server. There can be multiple web config files into an application where as we can have only one machine config file on a server.

49.  Explain role based security ?

  Role Based Security used to implement security based on roles assigned to user groups in the organization.
Then we can allow or deny users based on their role in the organization. Windows defines several built-in groups, including Administrators, Users, and Guests.
?
1
2
3
4
<AUTHORIZATION>< authorization >
    < allow roles="Domain_Name\Administrators" / >   < !-- Allow Administrators in domain. -- >
    < deny users="*"  / >                            < !-- Deny anyone else. -- >
 < /authorization >

50. What is Cross Page Posting?

When we click submit button on a web page, the page post the data to the same page. The technique in which we post the data to different pages is called Cross Page posting. This can be achieved by setting POSTBACKURL property of  the button that causes the postback. Findcontrol method of PreviousPage can be used to get the posted values on the page to which the page has been posted.

51. How can we apply Themes to an asp.net application?

We can specify the theme in web.config file. Below is the code example to apply theme:
?
1
2
3
4
5
6
7
8
9
<configuration>
<system.web>
<pages theme="Windows7" />
</system.web>
</configuration>

52: What is RedirectPermanent in ASP.Net?

  RedirectPermanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns 301 Moved Permanently responses.

53: What is MVC?

MVC is a framework used to create web applications. The web application base builds on  Model-View-Controller pattern which separates the application logic from UI, and the input and events from the user will be controlled by the Controller.

54. Explain the working of passport authentication.

First of all it checks passport authentication cookie. If the cookie is not available then the application redirects the user to Passport Sign on page. Passport service authenticates the user details on sign on page and if valid then stores the authenticated cookie on client machine and then redirect the user to requested page

55. What are the advantages of Passport authentication?

All the websites can be accessed using single login credentials. So no need to remember login credentials for each web site.
Users can maintain his/ her information in a single location.

56. What are the asp.net Security Controls?

  • <asp:Login>: Provides a standard login capability that allows the users to enter their credentials
  • <asp:LoginName>: Allows you to display the name of the logged-in user
  • <asp:LoginStatus>: Displays whether the user is authenticated or not
  • <asp:LoginView>: Provides various login views depending on the selected template
  • <asp:PasswordRecovery>:  email the users their lost password

57: How do you register JavaScript for webcontrols ?

We can register javascript for controls using <CONTROL -name>Attribtues.Add(scriptname,scripttext) method.

58. In which event are the controls fully loaded?

Page load event.

59: what is boxing and unboxing?

Boxing is assigning a value type to reference type variable.
Unboxing is reverse of boxing ie. Assigning reference type variable to value type variable.

60. Differentiate strong typing and weak typing

In strong typing, the data types of variable are checked at compile time. On the other hand, in case of weak typing the variable data types are checked at runtime. In case of strong typing, there is no chance of compilation error. Scripts use weak typing and hence issues arises at runtime.

61. How we can force all the validation controls to run?

The Page.Validate() method is used to force all the validation controls to run and to perform validation.

62. List all templates of the Repeater control.

  • ItemTemplate
  • AlternatingltemTemplate
  • SeparatorTemplate
  • HeaderTemplate
  • FooterTemplate

63. List the major built-in objects in ASP.NET? 

  • Application
  • Request
  • Response
  • Server
  • Session
  • Context
  • Trace

64. What is the appSettings Section in the web.config file?

The appSettings block in web config file sets the user-defined values for the whole application.
For example, in the following code snippet, the specified ConnectionString section is used throughout the project for database connection:
?
1
2
3
4
<em><configuration>
<appSettings>
<add key="ConnectionString" value="server=local; pwd=password; database=default" />
</appSettings></em>

65.  Which data type does the RangeValidator control support?

The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date.

66. What is the difference between an HtmlInputCheckBox control and an HtmlInputRadioButton control?

In HtmlInputCheckBoxcontrol, multiple item selection is possible whereas in HtmlInputRadioButton controls, we can select only single item from the group of items.

67. Which namespaces are necessary to create a localized application?

System.Globalization
System.Resources

68. What are the different types of cookies in ASP.NET?

Session Cookie – Resides on the client machine for a single session until the user does not log out.
Persistent Cookie – Resides on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.

69. What is the file extension of web service?

Web services have file extension .asmx..

70. What are the components of ADO.NET?

The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command, connection.

71. What is the difference between ExecuteScalar and ExecuteNonQuery?

ExecuteScalar returns output value where as ExecuteNonQuery does not return any value but the number of rows affected by the query. ExecuteScalar used for fetching a single value and ExecuteNonQuery used to execute Insert and Update statements.

Next Part

1 comment:

 

..

New Updates

Related Posts Plugin for WordPress, Blogger... View My Stats

Related Result