basic dotnet

1. What is ASP.Net?
It is a framework developed by Microsoft on which we can develop new generation web sites using web forms(aspx), MVC, HTML, Javascript, CSS etc. Its successor of Microsoft Active Server Pages(ASP). Currently there is ASP.NET 4.0, which is used to develop web sites. There are various page extensions provided by Microsoft that are being used for web site development. Eg: aspx, asmx, ascx, ashx, cs, vb, html, XML etc.


2. What's the use of Response.Output.Write()?
We can write formatted output using Response.Output.Write().
3. In which event of page cycle is the ViewState available?
After the Init() and before the Page_Load().

4. What is the difference between Server.Transfer and Response.Redirect?
In Server.Transfer page processing transfers from one page to the other page without making a round-trip back to the client's browser. This provides a faster response with a little less overhead on the server. The clients url history list or current url Server does not update in case of Server.Transfer.
Response.Redirect is used to redirect the user's browser to another page or site. It performs trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address.

5. From which base class all Web Forms are inherited?
Page class.

6. What are the different validators in ASP.NET?
1.     Required field Validator
2.     Range Validator
3.     Compare Validator
4.     Custom Validator
5.     Regular expression Validator
6.     Summary Validator

7. Which validator control you use if you need to make sure the values in two different controls matched?
Compare Validator control.

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

9. 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.

10. How long the items in ViewState exists?
They exist for the life of the current page.


11. 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.

12. How you can add an event handler?
Using the Attributes property of server side control.
e.g.
btnSubmit.Attributes.Add("onMouseOver","JavascriptCode();")

13. 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.

15. 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:
<%@ OutputCache Duration="120" VaryByParam="CategoryID;SelectedID"%>

16. 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

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

18. 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.
System.Web.Mvc

System.Web.Razor

System.ComponentModel.DataAnnotations

19. 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.

20. What is Protected Configuration?
It is a feature used to secure connection string information.

21. Write code to send e-mail from an ASP.NET application?
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.

22. How can we prevent browser from caching an ASPX page?
We can SetNoStore on HttpCachePolicy object exposed by the Response object's Cache property:
Response.Cache.SetNoStore ();
Response.Write (DateTime.Now.ToLongTimeString ());

23. 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.

24. 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

25. Which protocol is used to call a Web service?
HTTP Protocol

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

27. 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.

28. 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.
<AUTHORIZATION>< authorization >
< allow roles="Domain_Name\Administrators" / >   < !-- Allow Administrators in domain. -- >
< deny users="*"  / >                            < !-- Deny anyone else. -- >
< /authorization >

29. 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.

30. 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:
<configuration>

<system.web>

<pages theme="Windows7" />

</system.web>

</configuration>

31. 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.

32. 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.

33. 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

34. 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.

35. 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
36. How do you register JavaScript for webcontrols ?We can register javascript for controls using <CONTROL -name>Attribtues.Add(scriptname,scripttext) method.

37. In which event are the controls fully loaded?
Page load event.

38. 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.

39. 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.

40. 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.

41. List all templates of the Repeater control.
  • ItemTemplate
  • AlternatingltemTemplate
  • SeparatorTemplate
  • HeaderTemplate
  • FooterTemplate
42. List the major built-in objects in ASP.NET?
  • Application
  • Request
  • Response
  • Server
  • Session
  • Context
  • Trace
43. 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:
<em><configuration>
<appSettings>
<add key="ConnectionString" value="server=local; pwd=password; database=default" />
</appSettings></em>

44. Which data type does the RangeValidator control support?
The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date.
45. 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.

46. Which namespaces are necessary to create a localized application?
System.Globalization
System.Resources

47. 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.

48. What is the file extension of web service?
Web services have file extension .asmx..

49. What are the components of ADO.NET?
The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command, connection.

50. 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.

What’s the Difference Between ASP.NET MVC and ASP.NET WebForms?
Web Forms were one of the first ways to create web apps with ASP.NET. They utilize a designer and server controls to make it easy to design a form with a point and click interface like Windows Forms applications.
MVC or the Model View Controller separates a web app into data, display, and actions. Proponents of MVCpoint to its simplicity, reusability, and “less buggy” nature.
In reality, both MVC and Web Forms are tools with different strengths for different applications. By the way, the new ASP.NET Razor Pages is a new framework that is sort of a hybrid of the two.
Explain Briefly the Use of Global.asax.
Global.asax lets us write code that responds to “system level” events like starting up the app, ending a session, or errors, without having to add special, redundant code into each and every page on a website. We use it in Visual Studio by selecting Add > New Item > Global Application Class.
What Are the ASP.NET Session State Modes?
There are several different session state modes in ASP.NET. They provide different ways to store the session state.
1.        InProc mode is the default mode. It stores the session state in the web server memory.
2.        StateServer mode stores session state in a process known as the ASP.NET state service. If the app is restarted, the session state is preserved.
3.        SQLServer mode puts the session state in a SQL database. The session state is preserved if the web app restarts.
4.        Custom mode lets the developer specify a specialized storage provider.
5.        Off mode disables the session state.
6.        Write a Short Script That Sends an Email With ASP.NET.
7.        Ask a prospective employee to perform a simple coding task like the FizzBuzz example mentioned above, or to create a simple script like the one below. This example from ASP.NET Tutorials sends a simple email:
8.  protected void Page_Load(object sender, EventArgs e)
9.  {
10. try
11. {
12. MailMessage mailMessage = new MailMessage();
13. mailMessage.To.Add("your.own@mail-address.com");
14.         mailMessage.From = new MailAddress("another@mail-address.com");
15.         mailMessage.Subject = "ASP.NET e-mail test";
16.         mailMessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
17.         SmtpClient smtpClient = new SmtpClient("smtp.your-isp.com");
18.         smtpClient.Send(mailMessage);
19.         Response.Write("E-mail sent!");
20. }
21. catch(Exception ex)
22. {
23. Response.Write("Could not send the e-mail - error: " + ex.Message);
24. }
25. }

Q. Differentiate authentication with authorization.
Authentication is to identify the right person whereas authorization is process of providing valid access to the resources available.
Only an authentic person can be authorised to use resources.
For Example: Person A is allowed to access File A to view but not edit.
Here, process of identifying whether the person is A or not is authentication, and not providing access to edit the file A to person A is authorization.
Q. What are custom server controls of web page?
Controls that are not available in the ASP library can be created and registered, known as custom server controls.
2) What is Common Language Runtime or CLR ?
CLR handles the compilation and execution of .NET programs. CLR uses JIT and compiles the IL code to machine code and then executes. Below are the list of responsibilities of Common Language Runtime 
·         Garbage Collection
·         Code Verification
·         Code Access Security
·         Intermediate language -to-native translators and optimizer’s

3) What are Assemblies and Namespaces and explain the difference between them ?
Namespaces are the containers for holding the classes. In Object Oriented world, it is possible that programmers will use the same class name. By using namespace along with class name this collision can be removed.
·         An assembly exists as a .DLL or .EXE that contains MSIL code that is executed by CLR.
·         An assembly contains interface and classes and it can also contain other resources like files, bitmaps etc.
5) Explain the application event handlers in ASP.NET ?
Below are the event handlers in sequence of their execution -
·         Application_Start - Fired when the first user visits a page of the application or first resource is requested from the server.
·         Application_End - Fired when there are no more users of the application.
·         Application_BeginRequest - Fired at the beginning of each request to the server.
·         Application_EndRequest - Fired at the end of each request to the server.
·         Session_Start - Fired when any new user visits.
·         Session_End - Fired when the users stop requesting pages and their session times out.
7) What is Global Assembly Cache ?
GAC (Global Assembly Cache) is used to share .NET assemblies. GAC will be used in the below scenarios –
·         If the multiple application wanted to use the same assembly.
·         If the assembly has security requirements. For example, if only administrators have the permission to remove the assembly.
11) What are the State Management options in ASP.NET ?
Client-side state management - This maintains information on the client’s machine using either of the following options –
·         Cookies - Cookie is a small sized text file on the client machine either in the client’s file system or memory of client browser session.
·         View State - Each page and control on the page has View State property. This allows automatic retention of page and control’s state between each trip to server.
·         Query string - Query strings can maintain limited state information. Data has been passed from one page to another with the URL, but you can send limited size of data with the URL.
Server-side state management - This mechanism retains state in the server. Below are the options to achieve it -
·         Application State - The data stored in the application object can be shared by all the sessions of the application.
·         Session State - Session State stores session-specific information and the information is visible within the session only.
12) Explain the garbage collection in .NET ?
Garbage collection is a CLR feature which automatically manages memory. CLR automatically releases objects when they are no longer used and referenced. Following methods are used for garbage collection –
GC.Collect()
Dispose()
Finalize()
13) What is Reflection in .NET?
Reflection is a mechanism through which types defined in the metadata of each module can be accessed. The System. Reflection namespace will have the classes required for reflection.
48) In ASP.NET how many types of cookies are there?

There are two types of cookies -
·         Session cookie - A session cookie goes away when the user shuts the browser down.
·         Persistent cookie - This resides on the hard drive of the user and is retrieved when the user comes back to the Web page.


Comments

Popular posts from this blog

loop example

View vs Partial View MVC