We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, March 20, 2015

Basic interview questions and answers of ASP.NET



1. what is client-side code scripting in asp.net?

Client-side coding is used to do basic operations on the browser. It cannot be used to access the server or database on the server etc.
Client-side coding is done using scripting languages like Javascript, VbScript, JScript, etc. These scripting languages are easy to learn (they are different from vb.net and C#). The scripting languages provide only very minimal functionality.
The main use of client-side scripting is to validate user input before submitting a page to the server. For example, suppose we have a "Registration" page. Once the user enters all data and presses the "submit" button, all the user input will be sent to the server. In the server-side, we may have written vb.net or C# code to validate all user inputs like Name cannot be empty, etc. If the user does not enter a name and press submit, our server-side code will generate an error message and return the page to us.
In this case, the page was sent to the server and came back with an error message. It was an expensive operation. It consumed a lot of resources to send a page to the server and get it back to the browser with an error message.
If we can catch this validation error in the browser itself, instead of sending it to the server and coming back with an error, that will save a lot of time and resources. Users need not wait to send the page to the server and come back.

2. what is server-side scripting code in asp.net?

The code that is executed by the webserver to generate the dynamic page is called "server-side code". It is called "server-side code" because it is executed by the webserver.
When we develop ASP.NET pages, we will use C# or VB.NET (or any other .NET compatible code) code to write the server-side code. The server-side code is used to retrieve and generate content for the dynamic pages. We may be using the code to retrieve the content from a database or something like that.
When a dynamic page is requested, the server-side code is executed on the server and a page is generated. Once the generated page comes to the browser, there is a connection with the server. We cannot do anything from the browser to communicate with the server, then requesting another page or the same page again. So, if you want to access the database or something like that once the page is displayed, it is not possible.

3. What is a Web Server?

When we run our ASP.NET Web Application from visual studio IDE, VS Integrated ASP.NET Engine is responsible to execute all kind of asp.net requests and responses. The process name is "WebDev.WebServer.Exe" which actually take care of all request and response of a web application which is running from Visual Studio IDE.
Now, the name “Web Server” comes into picture when we want to host the application on a centralized location and wanted to access it from many locations. Web server is responsible for handle all the requests that are coming from clients, process them and provide the responses.

4. What is IIS?

IIS (Internet Information Server) is one of the most powerful web servers from Microsoft that is used to host your ASP.NET Web application. IIS has it's own ASP.NET Process Engine to handle the ASP.NET request. So, when a request comes from client to server, IIS takes that request and process it and sends a response back to clients.
Request Processing :
I hope, till now it’s clear to you that what is Web server and IIS is and what is the use of them. Now let’s have a look at how they do things internally. Before we move ahead, you have to know about two main concepts
1. Worker Process
2. Application Pool
Worker Process: Worker Process (w3wp.exe) runs the ASP.Net application in IIS. This process is responsible to manage all the requests and responses that are coming from the client system. All the ASP.Net functionality runs under the scope of the worker process. When a request comes to the server from a client worker process is responsible to generate the request and response. In a single word, we can say the worker process is the heart of ASP.NET Web Application which runs on IIS.
Application Pool: Application pool is the container of the worker process. Application pools are used to separate sets of IIS worker processes that share the same configuration. Application pools enable better security, reliability, and availability for any web application. The worker process serves as the process boundary that separates each application pool so that when one worker process or application is having an issue or recycles, other applications or worker processes are not affected. This makes sure that a particular web application doesn't impact other web applications as they are configured into different application pools.
Application Pool with multiple worker processes is called “Web Garden”.
Now, I have covered all the basic stuff like Web server, Application Pool, Worker process. Now let’s have look at how IIS process the request when a new request comes up from the client.
If we look into the IIS 6.0 Architecture, we can divide them into Two Layer
1. Kernel Mode
2. User Mode
Now, Kernel mode is introduced with IIS 6.0, which contains the HTTP.SYS. So whenever a request comes from Client to Server, it will hit HTTP.SYS First.

Now, HTTP.SYS is Responsible to pass the request to a particular Application pool. Now here is one question, How HTTP.SYS comes to know where to send the request? This is not a random pickup. Whenever we create a new Application Pool, the ID of the Application Pool is being generated and it’s registered with the HTTP.SYS. So whenever HTTP.SYS Received the request from any web application, it checks for the Application Pool and based on the application pool it sends the request.

5.what is a virtual directory in asp net?

Virtual directory a directory that is created in the IIS to host a local application or target a certain physical folder available on the server or where the virtual directory is being created.
For example: On our development machine, if we want to host our application, we will need to create a virtual directory and specify the physical path.
We can create the virtual directory by right-clicking the IIS and selecting from the context menu.

6. Can you explain the benefits and limitations of using Hidden frames?

Benefits of hidden frames:
Using hidden frames you can cache more than one data field.
The ability to cache and access data items stored in different hidden forms.
Limitations of hidden frames
They are not supported on all browsers.
The data can tamper.

7. Explain about Query String and its benefits and limitations.

It is information sent to the server appended to the end of a page URL.
Benefits of a query string:
No server resources are required.
The query string containing in the HTTP requests for a specific URL.
All browsers support query strings.
Following are limitations of the query string
Query string data is directly visible to the user thus leading to security problems.-
Most browsers and client devices impose a 255-character limit on URL length

8. What is a Page Directive?

Basically, Page Directives are commanded. These commands are used by the compiler when the page is compiled.

9. How to use the directives in an ASP.NET page?

It is not difficult to add a directive to an ASP.NET page. It is simple to add directives to an ASP.NET page. We can write directives in the following format:
<%@[Directive][Attributes]%>
See the directive format, it starts with "<%@" and ends with "%>". The best way is to put the directive at the top of our page. But we can put a directive anywhere in a page. One more thing, we can put more than one attribute in a single directive.
Here is the full list of directives:
|
@Page
@Master
@Control
@Import
@Implements
@Register
@Assembly
@MasterType
@Output Cache
@PreviousPageType
@Reference
Let's discuss something about each directive.
|
@Page
When we want to specify the attributes for an ASP.NET page then we need to use the @Page Directive. As we know, an ASP.NET page is a very important part of ASP.NET, so this directive is commonly used in ASP.NET.
Example:
<%@Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"%>
|
@Master
Now we have some information about @Page Directives. The @Master Directive is quite similar to the @Page Directive. The only difference is that the @master directive is for Master pages. You need to note that, while using the @Master Directive we define the template page's property. Then any content page can inherit all the properties defined in Master Page. But there are some properties that are only available in a Master Page.
Example
<%@Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage1.master.cs" Inherits="MasterPage"%>
|
@Control
@Control builds ASP.NET user controls. When we use the directive we define the properties to be inherited by the user controls and theses values are assigned to the user controls
|
Example:
<%@Control Language="C#" Explicit="True" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
|
@Import
As we know, we need to define namespaces in our .cs class before using a C# or VB class. So the @Import Directive imports namespaces. This directive supports just a single attribute "namespace" and this attribute takes a string value that specifies the namespace to be imported. One thing we need to note is that the @Import Directive cannot contain more than one attribute/value pair. But we can use multiple lines.
|
Example:
<%@Import Namespace="System.Data"%>
|
@Implements
The @Implements Directive gets the ASP.NET pages to implement .Net framework interfaces. This directive only supports a single attribute interface.
|
Example:
<%@Implements Interface="System.Web.UI.IValidator"%>
|
@Register
When we create a user control and we drag that user control onto our page then we will see the @Register directive. This directive registers our user control on the page so that the control can be accessed by the page.
|
Example:
<%@ Register TagPrefix="MayTag Namespace="MyName.MyNameSpace" Assembly="MyAssembly"%>
|
@Assembly
The @Assembly Directive attaches assemblies to the page or an ASP.NET user control thereby all the assembly classes and interfaces are available to the class. This directive supports the two attributes Name and src. The Name attribute defines the assembly name and the src attribute defines the source of the assembly.
|
Example:
<%@Assembly Name="MyAssembly"%>
<%@Assembly src="MYAssembly.cs">
|
@MasterType
The @MasterType Directive connects a class name to the ASP.NET page for getting strongly typed references or members contained in the specified Master Page. This directive supports the two attributes Typename and virtual path. Type name sets the name of the derived class from which to get the strongly typed or reference members and the virtual path sets the location of the page from which these are retrieved.
|
Example:
<%@MasterType VirtualPath="/MasterPage1.master"%>
|
@output cache
It controls the output caching policies of an ASP.NET page.
|
Example:
<%@ OutputCache Duration ="180" VaryByParam="None"%>
|
@Previouspagetype
This directive specifies the page from which any cross-page posting originates.
|
@Reference
This directive declares that another page or user control shout be complied with along with the active page or control. This directive supports the single attribute virtual path. It sets the location of the page or user control from which the active page will be referenced.
|
Example:
<%@Reference VirtualPayh="~/MyControl.ascx"%>

10. What is an assembly?

An Assembly is a logical unit of code.
Assembly physically exists as DLLs or EXEs.
One assembly can contain one or more files.
The constituent files can include any file types like image files, text files, etc. along with DLLs or EXEs.
When we compile our source code by default the exe/dll generated is actually an assembly.
Unless our code is bundled as assembly it can not be used in any other application.
When we talk about the version of a component we are actually talking about a version of the assembly to which the component belongs.
Every assembly file contains information about itself. This information is called as Assembly Manifest.

11. What is the assembly manifest?

Assembly manifest is a data structure that stores information about an assembly.
This information is stored within the assembly file (DLL/EXE) itself.
The information includes version information, a list of constituent files, etc.

12. What is a private and shared assembly?

private assembly
The assembly which is used only by a single application is called as a private assembly. Suppose we created a DLL which encapsulates our business logic. This DLL will be used by our client application only and not by any other application. In order to run the application properly, our DLL must reside in the same folder in which the client application is installed.
shared assembly
Thus the assembly is private to our application.
Suppose that we are creating a general-purpose DLL that provides functionality which will be used by a variety of applications. Now, instead of each client application having its own copy of DLL we can place the DLL in 'global assembly cache'. Such assemblies are called as shared assemblies.

13. What is Global Assembly Cache?

Global assembly cache is nothing but a special disk folder where all the shared assemblies will be kept. It is located under the \WinNT\Assembly folder.

14. How assemblies avoid DLL Hell?

As stated earlier most of the assemblies are private. Hence each client application refers assemblies from its own installation folder. So, even though there are multiple versions of the same assembly they will not conflict with each other. Consider the following example :
We created assembly Assembly1
We also created a client application which uses Assembly1 say Client1
We installed the client in C:\MyApp1 and also placed Assembly1 in this folder
After some days we changed Assembly1
We now created another application Client2 which uses this changed Assembly1
We installed Client2 in C:\MyApp2 and also placed changed Assembly1 in this folder
Since both the clients are referring to their own versions of Assembly1 everything goes on smoothly
Now consider the case when we develop assembly that is shared one. In this case, it is important to know how assemblies are versioned. All assemblies have a version number in the form:
major.minor.build.revision
If we change the original assembly the changed version will be considered compatible with the existing one if the major and minor versions of both the assemblies match.
When the client application requests assembly the requested version number is matched against available versions and the version matching major and minor version numbers and having latest build and revision number is supplied.

15. How do I create shared assemblies?

Following steps are involved in creating shared assemblies :
Create our DLL/EXE source code.
Generate a unique assembly name using SN utility.
Sign our DLL/EXE with the private key by modifying AssemblyInfo file
Compile your DLL/EXE.
Place the resultant DLL/EXE in global assembly cache using AL utility.

16. How do I create a unique assembly name?

Microsoft now uses a public-private key pair to uniquely identify an assembly. These keys are generated using a utility called SN.exe (SN stands for the shared name). The most common syntax is :
sn -k mykeyfile.key
Where k represents that we want to generate a key and the file name followed is the file in which the keys will be stored.

17. How do I sign my DLL/EXE?

Before placing the assembly into shared cache we need to sign it using the keys we just generated. We mention the signing information in a special file called AssemblyInfo. Open the file from VS.NET solution explorer and change it to include the following lines :
[assembly:AssemblyKeyFile("file_path")]
Now recompile the project and the assembly will be signed for us.
Note: We can also supply the key file information during command-line compilation via /a.keyfile switch.

18. How do I place the assembly in a shared cache?

Microsoft has provided a utility called AL.exe to actually place our assembly in the shared cache.
AL /i:my_dll.dll
Now our dll will be placed at a proper location by the utility.

19. What is Cache Callback in Cache?

The cache object is dependent on its dependencies example file-based, time-based, etc...Cache items
remove the object when cache dependencies change.ASP.NET provides the capability to execute a
callback method when that item is removed from the cache.

20. What is scavenging?

It is the process of deleting items from the cache when memory is scarce.
Items are removed from cache depending on cache item priority.
Cache item priority is set when we add the item to the cache.
The items scavenging are removed according to priority.

21. Explain different types of remote object creation mode in .NET.

Different ways in which an object can be created using Remoting are
SAO (Server Activated Objects) also called a Well-Known call mode.
CAO (Client Activated Objects)
SAO has two modes “Single Call” and “Singleton”
With Single Call object, the object is stateless as the object is created with every method call.
The object is created once and the object is shared with all clients with Singleton.
CAO is stateful as compared to SAO.
The creation request is sent from the client-side.
The client holds a proxy to the server object created on the server.

22. Benefits and Limitations of using Viewstate for state management.

Benefits of using Viewstate
With Viewstate states are retained automatically
It is simple to use and implement
No server resources are required because the state is in a structure in the page code
From a security point of view, it is safer than hidden fields as values in view state are hashed, compressed, and encoded
Since the data is cached on the client View, the state is good for caching data in Web frame configurations.
Limitation of Viewstate
Performance is affected when large values are stored because the view state is stored in the page.
Despite the state stores data in a hashed format, it can still tamper because it is stored in a hidden field on the page.

23. Machine config and web config. Can you explain to them?

Machine config sets the base configuration for all the .net assemblies running on the server.
Web config sets the base config for all the web app and overrides settings in machine configuration.

24. Difference between an EXE and a DLL.

An EXE is portable and executable with an entry point
A dll is not portable and executable since it has no entry point.

25. Explain the concept of strong names?

-Strong Name is same as GUID in COM components
-Strong Names helps GAC to differentiate between two versions
-It is required when we deploy assembly in GAC.
-Strong Names use public and private key concepts.

26. What are the different kinds of marshaling?

Marshal-by-value
Marshal-by-reference

27. Which class does the remote object has to inherit?

System.MarchalByRefObject.

28. What is a reflection?

-Reflection is used to browse through the metadata information.
-Using reflection we can dynamically invoke methods using system.Type.Invokemember.

29. What are the different types of JIT?

-Pre-JIT, Econo-JIT, Normal-JIT

30. How can we perform transactions in .NET?

-Open a database connection using the open method of the connection object.
-Begin a transaction using the Begin Transaction method of the connection object.
-Execute the SQL commands using the command object.
-Commit or roll back the transaction using the commit or rollback method of the transaction object.
-Close the database connection.

31. Name the validation controls in ASP.NET.

RequiredFieldValidator
RangeValidator
CompareValidator
RegularExpressionValidator
CustomValidator
ValidationSummary

32. How to assign page specific attributes?

By using the @Page directive

33. Where is ViewState information stored?

HTML hidden fields

34. What are the ways to maintain state?

Hidden fields, ViewState, hidden frames, cookies, query string

35. What are the modes of storing the ASP.NET session?

-InProc
-StateServer
-SQLServer
-Custom

36. How to find how the code was executed?

Session.abandan

37. What are different IIS isolation levels?

LOW (IIS process)
Medium (Pooled)
High (Isolated)

38. How to format data inside DataGrid?

By using DataFormatString property

39. Tell which method to customize columns in DataGrid?

Template column

40. How do we force validation control to run?

Page.Validate

41. Can we disable client side script in validation?

Yes, set EnableClient script to false

42. How to find how to code was executed.

Tracing

43. Explain the difference between dataset and DataReader.

-DataReader provides forward-only and read-only access to data
-Dataset objects can hold more than one table from the same data sources as well as the relationships between them.
-Dataset is a disconnected architecture
-Dataset cab persist contents while DataReader cannot persist contents

44. What are the ways of authentication technique in ASP.NET?

Windows authentication
Passport authentication
Forms authentication

45. Can you explain how to sign out in forms authentication?

FormsAuthentication.SignOut()

46. Explain Automatic Memory Management in .NET.

Automatic memory management in .Net is through garbage collector which is incredibly efficient in releasing resources when no longer in use.

47. What is CAS?

CAS is a very important part of .Net security system which verifies if a particular piece of code is allowed to run. It also determines if a piece of code has access rights to run a particular resource. .NET security system applies these features using code groups and permissions. Each assembly of an application is the part of the code group with associated permissions.

48. Define Globalization and Localization.

Globalization is the process of creating multilingual applications by defining culture-specific features like currency, date and time format, calendar and other issues. Localization is the process of accommodating cultural differences in an application

49. Define Resource Files.

Resource files contain non-executable data like strings, images, etc that are used by an application and deployed along with it. We can change these data without recompiling the whole application.

50. Explain Managed code an Un-managed code.

Managed code runs under the safe supervision of common language runtime. Managed code carries metadata that is used by common language runtime to offer services like memory management, code access security, and cross-language accessibility.
Unmanaged code doesn't follow CLR conventions and thus, can't take advantage of. Framework.

51. Explain in what order a destructor is called.

Destructors are called in reverse order of constructors. The destructor of the most derived class is called followed by its parent's destructor and so on till the topmost class in the hierarchy.

52. What is the side-by-side execution?

This means multiple versions of the same assembly to run on the same computer. This feature enables us to deploy multiple versions of the component.

53. What is the break mode? What are the options to step through code?

Break mode lets us observe code line to line in order to locate the error. VS.NET provides the following option to step through code.
Step Into
Step Over
Step Out
Run To Cursor
Set Next Statement

54. Explain Session state management options in ASP.NET.

ASP.NET provides In-Process and Out-of-Process state management. In-Process stores the session in memory on the webserver. Out-of-Process Session state management stores data in an external data source such as SQL Server or a State Server service. Out-of-Process state management requires that all objects stored in the session are serializable.

55. How to turn off cookies for a page?

Cookie. Discard Property when true, instructs the client application not to save the Cookie on the user's hard disk when a session ends.

56. How can you ensure a permanent cookie?

Setting Expires property to MinValue and restricts cookie to get expired.

57. What is AutoPostback?

AutoPostBack automatically posts the page back to the server when the state of the control is changed.

58. Explain login control and form authentication.

Login controls encapsulate all the features offered by Forms authentication. Login controls internally use FormsAuthentication class to implement security by prompting for user credentials validating them.

59. Response.Redirect vs Server.Transfer.?

Server.Transfer is only applicable for aspx files. It transfers page processing to another page without making round-trip back to the client's browser. Since no round trips, it offers a faster response and doesn't update the client URL history list.
Response.Redirect is used to redirect to another page or site. This performs a trip back to the client where the client’s browser is redirected to the new page.

60. Define View State.

ASP.NET preserves data between postback events using view state. You can save a lot of coding using a view state in the web form. ViewState serializes the state of objects and store in a hidden field on the page. It retains the state of server-side objects between postbacks. It represents the status of the page when submitted to the server. By default, view state is maintained for each page. If you do not want to 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. ViewState exists for the life of the current page.

61. What is the application domain?

It is the process space within which ASP.NET application runs. Every application has its own process space which isolates it from other application. If one of the application domains throws error it does not affect the other application domains.

62. List down the sequence of methods called during the page load.

Init() - Initializes the page.
Load() - Loads the page in the server memory.
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - runs just after page finishes loading.

63. Define the secured sockets layer.

Secured Socket Layer (SSL) ensures a secured web application by encrypting the data sent over the internet. When an application is using the SSL facility, the server generates an encryption key for the session and the page is encrypted before it sent. The client browser uses this encryption key to decrypt the requested Web page.

64. Define Tracing.

Tracing is the way to maintain events in an application. It is useful while the application is in debugging or in the testing phase. The trace class in the code is used to diagnose the problem. We can use trace messages to our project to monitor events in the released version of the application. The trace class is found in the System. Diagnostics namespace. ASP.NET introduces tracing that enables us to write debug statements in our code, which still remain in the code even after when it is deployed to production servers.
overwrite them. When the components are no longer in use, they are removed safely from the server using the Merge modules facility.

65. Explain Exception handling in .Net.

Exceptions or errors are unusual occurrences that happen within the logic of an application. The CLR has provided a structured way to deal with exceptions using Try/Catch block. ASP.NET supports some facilities for handling exceptions using events suck as Page_Error and Application_Error.

66. What is impersonation?

Impersonation means delegating one user identity to another user. In ASP.NET, the anonymous users impersonate the ASPNET user account by default. We can use the element of web.config file to impersonate a user. E.g.

67. What is a managed code in .Net?

The code that runs under the guidance of common language runtime (CLR) is called managed code. The versioning and registration problem which are formally handled by the windows programming are solved in .Net with the introduction of managed code. The managed code contains all the versioning and type information that the CLR uses to run the application.

68. What are Merge modules?

Merge modules are the deployment projects for the shared components. If the components are already installed, the modules merge the changes rather than unnecessarily

69. Define the steps to set up validation control.

Following are the steps to set up validation control
Drag a validation control on a web form.
Set the ControlToValidate property to the control to be validated.
If we are using CompareValidator, we have to specify the ControlToCompare property.
Specify the error message we want to display using ErrorMessage property.
We can use ValidationSummary control to show errors at one place.

70. What are the navigation ways between pages available in ASP.NET?

Ways to navigate between pages are:
Hyperlink control
Response.Redirect method
Server.Transfer method
Server.Execute method
Window.Open script method

71. How do you open a page in a new window?

To open a page in a new window, you have to use the client script using onclick="window.open()" attribute of HTML control

72. What are the validation controls available in ASP.NET?

ASP.NET validation controls are:
RequiredFieldValidator: This validates controls if controls contain data.
CompareValidator: This allows checking if data of one control match with other control.
RangeValidator: This verifies if entered data is between two values.
RegularExpressionValidator: This checks if entered data matches a specific format.
CustomValidator: Validate the data entered using a client-side script or a server-side code.
ValidationSummary: This allows the developer to display errors in one place.

74. Describe state management in ASP.NET.

State management is a technique to manage a state of an object on different request.
The HTTP protocol is the fundamental protocol of the World Wide Web. HTTP is a stateless protocol that means every request is from a new user with respect to a web server. The HTTP protocol does not provide us with any method of determining whether any two requests are made by the same person.
Maintaining state is important in any web application. There are two types of state management system in ASP.NET.
- Client-side state management
- Server-side state management

75. Explain the client-side state management system.

ASP.NET provides several techniques for storing state information on the client. These include the following:
- view state ASP.NET uses view state to track values in controls between page requests. It works within the page only. We cannot use view state value in the next page.
- Control state: We can persist in information about a control that is not part of the view state. If the view state is disabled for a control or the page, the control state will still work.
- Hidden fields: It stores data without displaying that control and data to the user’s browser. This data is presented back to the server and is available when the form is processed. Hidden fields data is available within the page only (page-scoped data).
- Cookies: Cookies are a small piece of information that the server creates on the browser. Cookies store a value in the user’s browser that the browser sends with every page request to the webserver.
- Query strings: In query strings, values are stored at the end of the URL. These values are visible to the user through his or her browser’s address bar. Query strings are not secure. We should not send secret information through the query string.

76. Explain the server side state management system.

The following objects are used to store the information on the server:
- Application State:
This object stores the data that is accessible to all pages in a given Web application. The Application object contains global variables for your ASP.NET application.
- Cache Object: Caching is the process of storing data that is used frequently by the user. Caching increases our application’s performance, scalability, and availability. We can catch the data on the server or client.
- Session State: Session object stores user-specific data between individual requests. This object is the same as the application object but it stores the data about a particular user.

77. Explain cookies with examples.

A cookie is a small amount of data that the server creates on the client. When a web server creates a cookie, an additional HTTP header is sent to the browser when a page is served to the browser. The HTTP header looks like this:
Set-Cookie: message=Hello. After a cookie has been created on a browser, whenever the browser requests a page from the same application in the future, the browser sends a header that looks like this:
Cookie: message=Hello
A cookie is a little bit of text information. We can store only string values when using a cookie. There are two types of cookies:
- Session cookies
- Persistent cookies.
A session cookie exists only in memory. If a user closes the web browser, the session cookie deletes permanently.
A persistent cookie, on the other hand, can available for months or even years. When we create a persistent cookie, the cookie is stored permanently by the user’s browser on the user’s computer.
Creating cookie
protected void btnAdd_Click(object sender, EventArgs e)
{
Response.Cookies[“message”].Value = txtMsgCookie.Text;
}

// Here txtMsgCookie is the ID of TextBox.
// cookie names are case sensitive. Cookie named message is different from setting a cookie named Message.
The above example creates a session cookie. The cookie disappears when we close our web browser. If we want to create a persistent cookie, then we need to specify an expiration date for the cookie.
Response.Cookies[“message”].Expires = DateTime.Now.AddYears(1);
Reading Cookies
void Page_Load()
{
if (Request.Cookies[“message”] != null)
lblCookieValue.Text = Request.Cookies[“message”].Value;
}
// Here lblCookieValue is the ID of Label Control.

79. Describe the disadvantage of cookies.

- Cookie can store only string value.
- Cookies are browser dependent.
- Cookies are not secure.
- Cookies can store small amount of data.

80. What is Session object? Describe in detail.

HTTP is a stateless protocol; it can't hold the user information on a web page. If the user inserts some information, and move to the next page, that data will be lost and the user would not able to retrieve the information. For accessing that information we have to store information. The session provides that facility to store information on server memory. It can support any type of object to store. For every user Session data store separately means the session is user-specific.
Storing the data in the Session object.
Session [“message”] = “Hello World!”;
Retrieving the data from the Session object.
Label1.Text = Session[“message”].ToString();

81. What are the Advantages and Disadvantages of Session?

Following are the basic advantages and disadvantages of using session.
Advantages:
- It stores user states and data to all over the application.
- Easy mechanism to implement and we can store any kind of object.
- Stores every user data separately.
- The session is secure and transparent from the user because the session object is stored on the server.
Disadvantages:
- Performance overhead in case of a large number of users, because of session data stored in server memory.
- Overhead involved in serializing and De-Serializing session Data. Because In the case of StateServer and SQLServer session mode we need to serialize the object before the store.

82. Describe Master Page.

Master pages in ASP.NET work as a template that we can reference this page in all other content pages. Master pages enable us to define the look and feel of all the pages in our site in a single location. If we have done changes in the master page, then the changes will reflect in all the web pages that reference master pages. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.
ContentPlaceHolder control is available only on the master page. You can use more than one ContentPlaceHolder control in the master page. To create regions that content pages can fill in, you need to define ContentPlaceHolder controls in master page as follows:


The page-specific content is then put inside a Content control that points to the relevant
ContentPlaceHolder:


Note that the ContentPlaceHolderID attribute of the Content control points to the ContentPlaceHolder that is defined in the master page.
The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .aspx pages.
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="CareerRide.master.cs" Inherits="CareerRide" %>

83. How you can access the Properties and Controls of Master Pages from content pages?

We can access the Properties and Controls of Master Pages from content pages. In many situations, we need User’s Name in different content pages. We can set this value inside the master page and then make it available to content pages as a property of the master page.
We will follow the following steps to reference the properties of the master page from content pages.
Step: 1
Create a property in the master page code-behind file.
public String UserName
{
get {
return (String)Session["Name"];
}
set {
Session ["Name"] = value;
}
}
Step: 2
Add the @ MasterTypedeclaration to the .aspx content page to reference master properties in a content page. This declaration is added just below the @ Page declaration as follows:
<%@ Page Title=" TEST" Language="C#" MasterPageFile="~/CareerRide.master" AutoEventWireup="true" CodeFile="CareerRideWelcome.aspx.cs" Inherits="CareerRideWelcome" %>
<%@ MasterTypeVirtualPath="~/CareerRide.master" %>
Step: 3
Once we add the @ MasterType declaration, you can reference properties in the master page using the Master class. For example take a label control that id is ID="Label1"
Label1.Text= Master.UserName ;
For referencing controls in the Master Page we will write the following code.
Content Page Code.
protected void Button1_Click(object sender, EventArgs e)
{
TextBox txtName= (TextBox)Master.FindControl("TextBox1");
Label1.Text=txtName.Text;
}
To reference controls in a master page, call Master.FindControl from the content page.

85. What are the different method of navigation in ASP.NET?

Page navigation means moving from one page to another page in your web site and another. There are many ways to navigate from one page to another in ASP.NET.
- Client-side navigation
- Cross-page posting
- Client-side browser redirect
- Client-Side Navigation
Client-side navigation:
Client-side navigation allows the user to navigate from one page to another by using client-side code or HTML. It requests a new Web page in response to a client-side event, such as clicking a hyperlink or executing JavaScript as part of a button click.
Example:
Drag a HyperLink control on the form and set the NavigateUrl property to the desired destination page.
HyperLinkControl: Source
Take a test from CareerRide
Suppose that, this control is placed on a Web page called CareerRide.aspx, and the HyperLink control is clicked, the browser simply requests the Welcome.aspx page.
The second method of client-side navigation is through JavaScript.
Example:
Take an HTML button control on the web page. The following is the HTML code for the input button.

When the Button1 is clicked, the client-side method, Button1_onclick will be called. The JavaScript source for the Button1_onclick method is as follows:

Cross-page posting:
Example:
Suppose that we have two pages, the first page is FirstPage.aspx and Second page is SecondPage.aspx. The First Page has a Button and TextBox control and its ID is Button1 and TextBox1 respectively. A Button control has its PostBackUrl property. Set this property to “~/SecondPage.aspx”. When the user clicks on Button, the data will send to SecondPage for processing. The code for SecondPage is as follows:
protected void Page_Load(object sender, EventArgs e)
{
if(Page.PreviousPage == null)
{
Label1.Text = "No previous page in post";
}
else
{
Label1.Text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
}
}
The second page contains a Label control and its ID is Label1.
The page that receives the PostBack receives the posted data from the firstpage for processing. We can consider this page as the processing page. The processing page often needs to access data that was contained inside the initial page that collected the data and delivered the PostBack. The previous page’s data is available inside the Page.PreviousPage property. This property is only set if a cross-page post occurs.
Client-side browser redirect:
The Page.Response object contains the Redirect method that can be used in your server-side code to instruct the browser to initiate a request for another Web page. The redirect is not a PostBack. It is similar to the user clicking a hyperlink on a Web page.
Example:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect ("Welcome.aspx");
}
In client-side browser redirect method an extra round trip to the server is happened.
Server-side transfer:
In this technique Server.Transfer method is used. The Transfer method transfers the entire context of a Web page over to another page. The page that receives the transfer generates the response back to the user’s browser. In this mechanism, the user’s Internet address in his browser does not show the result of the transfer. The user’s address bar still reflects the name of the originally requested page.
protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("MyPage.aspx", false);
}
The Transfer method has an overload that accepts a Boolean parameter called preserve-Form. You set this parameter to indicate if you want to keep the form and query string data.

86. What does the Orientation property do in a Menu control?

Orientation property of the Menu control sets the display of the menu on a Web page to vertical or horizontal.
Originally the orientation is set to vertical.

87. Differentiate between client-side and server-side validations in Web pages.

- Client-side validations happends at the client's side with the help of JavaScript and VBScript. This happens before the Web page is sent to the server.
- Server-side validations occur place at the server-side.

88. Differentiate between Authentication and authorization.

- Authentication is the process of verifying the identity of a user using some credentials like username and password while authorization determines the parts of the system to which a particular identity has access.
- Authentication is required before authorization.
For e.g., If an employee authenticates himself with his credentials on a system, the authorization will determine if he has the control over just publishing the content or also editing it.

89. What does the WebPart file do?

It explains the settings of a Web Parts control that can be included to a specified zone on a Web page.

90. How would you enable impersonation in the web.config file?

In order to enable the impersonation in the web.confing file, take the following steps:
- Include the element in the web.config file.
- Set the impersonate attribute to true as shown below:

91. Differentiate between File-based dependency and key-based dependency.

- In file-based dependency, the dependency is on a file saved in a disk while in key-based dependency, you depend on another cached item.

92. File-based dependency and key-based dependency. Globalization and localization.

- Globalization is a technique to identify the part of a Web application that is different for different languages and separate it out from the web application while in localization you try to configure a Web application so that it can be supported for a specific language or locale.

93. Differentiate between a page theme and a global theme?

- Page theme applies to particular web pages of the project. It is stored inside a subfolder of the App_Themes folder.
- Global theme applies to all the web applications on the webserver. It is stored inside the Themes folder on a Web server.

94. Differentiate between a HyperLink control and a LinkButton control.

- A HyperLink control does not have the Click and Command events while the LinkButton control has them, which can be handled in the code-behind file of the Web page.

95. How do Cookies work? Give an example of their abuse.

- The server directs the browser to put some files in a cookie. All the cookies are then sent for the domain in each request.
- An example of cookie abuse could be a case where a large cookie is stored affecting the network traffic.

96. What are Custom User Controls in ASP.NET?

- These are the controls defined by developers and work similar to other web server controls.
- They are a mixture of custom behavior and predefined behavior.

97. What is Role-based security?

- Used in almost all organization, the Role-based security assign certain privileges to each role.
- Each user is assigned a particular role from the list.
- Privileges as per role restrict the user's actions on the system and ensure that a user is able to do only what he is permitted to do on the system.

98. What are the HTML server controls in ASP.NET?

- HTML server controls are similar to the standard HTML elements like those used in HTML pages.
- They expose properties and events for programmatic use.
- To make these controls programmatically accessible, we specify that the HTML controls act as a server control by adding the runat="server" attribute.

99. What are the various types of cookies in ASP.NET?

There exist two types of cookies in ASP.NET
- Session Cookie - It resides on the machine of the client for a single session and works until the user logs out of the session.
- Persistent Cookie - It resides on the machine of a user for a specified period. This period can be set up manually by the user.

100. How would you turn off cookies on one page of your website?

- This can be done by using the Cookie.Discard property.
- It Gets or sets the discard flag set by the server.
- When set to true, this property instructs the client application not to save the Cookie on the hard disk of the user at the end of the session.

101. How would you create a permanent cookie?

- Permanent cookies are stored on the hard disk and are available until a specified expiration date is reached.
- To create a cookie that never expires set its Expires property equal to DateTime.maxValue.

102. Explain Culture and UICulture values.

- Culture value determines the functions like Date and Currency used to format data and numbers on a Web page.
- UICulture value determines the resources like strings or images loaded in a Web application for a Web page.

103. The following list describes the available session state modes:

In-Process stores the session in memory on the webserver and this is the default.

Out-of-Process Session state management stores data in an external data source.
There are two types of Out-of-Process
1)State Server:- stored in the server side.
2)SQL Server:- stored in a database.

StateServer mode: which stores session state in a separate process called the ASP.NET state service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

SQLServer mode: which stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

Custom mode: This enables you to specify a custom storage provider.

Off mode: which disables the session state.

No comments: