Asp.Net Interview Questions (Part-1)
What are the types of ASP Objects?
You can create various type of object in ASP
- Response Object
- Application Object
- Request Object
- Session Object
- Server Object
- Error Object
- FileSystem Object
- File Object
- ADO Object
- Drive Object
List all different types of directives in Asp.Net?
- @ Assembly
- @ Control
- @ Implements
- @ Import
- @ Master
- @ MasterType
- @ OutputCache
- @ Page
- @ PreviousPageType
- @ Reference
- @ Register
What's the use of Response.Output.Write()?
Response.output.write() is used to display the formatted text.
Can you programmatically access IIS configuration settings?
Yes. ASP or scripting provides a powerful means to develop customized applications for remotely managing an IIS server. Using technologies such as Active Directory Service Interfaces (ADSI), Windows Management Instrumentation (WMI), or Component Object Model (COM) interfaces, developers can programmatically configure IIS, offering a comprehensive range of administrative capabilities. This approach empowers administrators to automate and streamline server management tasks, enhancing efficiency and flexibility in the administration of IIS.
Can you have a web application running without web.Config file?
Yes. It is indeed possible to run an ASP.NET application without a web.config file. In the absence of specific configurations in the web.config file, the application will rely on the default settings defined in the machine.config file. However, it is important to note that debugging capabilities may be restricted when running the application in debug mode, even without a web.config file.
Which namespace is used to implement debug and trace methods?
The Systems.Diagnostics namespace includes Trace and Debug classes.
Which namespaces are used for data access?
The System.Data namespaces contain classes for accessing and managing data from diverse sources.
How can I configure ASP.NET that are running on a remote machine?
To enable remote debugging in Visual Studio, you can utilize the Visual Studio remote debugger feature. This involves installing the necessary remote debugging components on the target computer and launching the Remote Debugging Monitor (msvsmon.exe) when initiating the debugging process. By configuring the remote debugging environment in this manner, developers gain the capability to debug and diagnose issues on remote machines, facilitating efficient troubleshooting and enhancing the debugging experience.
Where the assembly is stored in asp.net?
Private assemblies are specifically designed to be utilized within a single project and are typically stored in the project's bin folder. These assemblies serve as internal dependencies for the project, providing the necessary functionality and resources required by that specific project. On the other hand, public or shared assemblies are intended for broader usage across multiple projects and are stored in the GAC (Global Assembly Cache). By placing these assemblies in the GAC, they become globally accessible, enabling seamless integration and utilization by any project within the environment. This clear separation allows for efficient management and distribution of assemblies, ensuring that private assemblies are confined to their respective projects while public assemblies are readily available to facilitate reusability and interoperability across the entire application landscape.
What is the size of the session ID?
The ASP.NET session identifier is a randomly generated number encoded into a 24-character string consisting of lowercase characters from a to z and numbers from 0 to 5.
How to access session variables from any class in ASP.NET?
Access the Session via the threads HttpContext:
What are the different Session state modes available in ASP.NET?
- InProc mode - which stores session state in memory on the Web server. This is the default.
- StateServer mode - which stores session state in a separate process called the ASP.NET state service
- SQLServer mode - stores session state in a SQL Server database.
- Custom mode - which enables you to specify a custom storage provider.
- Off mode - which disables session state.
How long the items in ViewState exists?
ViewState exists till your current page exists. This includes postbacks. Viewstate become nothing once it redirects or transfer to another page.
Does viewstate expire?
No. ViewState persists throughout the PostBack process and does not have an inherent expiration mechanism. As part of the form submission, ViewState is transmitted and can be reconstructed whenever needed. However, it is crucial to understand that ViewState is stored within the Session. Consequently, if the Session expires or is otherwise terminated, the ViewState associated with it will also be lost. Care should be taken to ensure that appropriate measures are in place to handle session expiration and preserve ViewState integrity, especially when maintaining important data or state information within the ViewState.
Which object encapsulates state or data of the client?
Where is the ViewState information stored?
ViewState is a mechanism in ASP.NET that enables the preservation of state information on a web page. It is stored directly on the page itself, in an encoded format. To store data specific to a particular page, a hidden variable can be employed. This hidden variable serves as a container for data that is intended for use solely within that page. The View State Data, which includes the state information, is encoded using the Base64 string format. This encoding ensures the security and integrity of the View State Data while being transmitted between the server and the client.
In which event of page cycle is the ViewState available?
ViewState is loaded into memory between init and load. In Page Init, only Partially gets loaded. In Page load,viewstate complete. So whole loading is available in Page load only.
Which is the only event provided by Cache object?
CacheItemRemoved event is the only event provided by Cache object.
Which delegate can be used to notify the application when items are removed from the cache?
onRemoveCallback is used to notify the application when items are removed from the cache.
How can we prevent browser from caching an ASPX page?
What is the difference between page-level caching and fragment caching?
Page-level caching refers to the cache an entire page and the Fragment caching refers to the portion of a webpage such as caching User Controls
How to open a page in a new window?
What is the default timeout for a Cookie?
By default, the Expires value for a cookie is not set to a specific static time but rather creates a Session cookie. This means that the cookie remains active until the user closes their browser or clears their cookies. This behavior is achieved by setting the Expires property to MinValue, which designates it as a session cookie and represents its default value. However, if necessary, you have the flexibility to override this behavior and specify a different expiration time for the cookie based on your specific requirements.
How to turn off cookies for a page?
You don't have to change anything in your ASP.NET application to enable cookieless sessions, except the following configuration setting in web.config file
How to turn off cookies for a page?
You don't have to change anything in your ASP.NET application to enable cookieless sessions, except the following configuration setting in web.config file.
How would you create a permanent cookie?
Set its Expires property equal to DateTime.maxValue , that means cookies never Expires.
How to turn off cookies for a page?
Cookie.Discard Property when set true will instruct the client application not to save the Cookie on the user's hard disk when a session ends.
What are ASP.NET Page Life Cycle Events?
- Control events
How can you 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 to server or not.
Which method is used to post a Web page to another Web page?
The Respose.Redirect method is used to post a page to another page.
What is the difference between a page theme and a global theme?
In an ASP.NET project, the concept of page themes allows for the application of a specific theme to individual web pages. These page-specific themes are stored within a subfolder of the App_Themes folder, providing a convenient organization and accessibility for the project's themes. On the other hand, a global theme extends its influence beyond a single web application and applies to all web applications hosted on the web server. These global themes are stored within the Themes folder on the web server, ensuring their availability and applicability across multiple web applications. This clear distinction between page themes and global themes enables developers to tailor the visual appearance and layout at both the page and application levels, ensuring a consistent and cohesive user experience throughout the web environment.
How do we assign page specific attributes?
Page attributes are specified using the @Page directive.
What events will occur when a page is loaded?
What is Role-based security?
Role-based security allows you to partition your web site according to the "role" of the user.
Which method do you use to kill explicitly a user session?
- Session.Remove() - It will kill session for the specific user.
- Session.Clear() - To remove all keys with the session as well as you can also use it to remove specific keys from the session.
Is it possible to create web application with both webforms and mvc?
Yes. You have to include below mvc assembly references in the web forms application to create hybrid application.
What is RedirectPermanent in ASP.Net?
The Response.RedirectPermanent() method serves the purpose of executing a permanent redirection from a requested URL to a designated URL. This method is particularly useful when a resource has been relocated permanently and is no longer available at its previous location. By employing RedirectPermanent, the browser is notified about this permanent move, leading to automatic caching of this response. Consequently, subsequent requests for the original resource will be redirected to the new location without re-requesting the resource from its previous address. This caching behavior ensures an efficient and streamlined user experience while maintaining the integrity of the website's URL structure.
What are the advantages of Passport authentication?
Passport authentication offers several noteworthy advantages, including the elimination of the need for users to remember multiple usernames and passwords for different websites. This centralized authentication system allows users to maintain their profile information in a single location, simplifying the management of their personal data across various online platforms. Importantly, Passport authentication does not require real-time, server-to-server communication between participating websites and the central .NET Passport servers, minimizing potential bottlenecks and enhancing performance. This streamlined approach to authentication enhances user convenience, reduces the cognitive burden of managing multiple credentials, and ensures efficient and secure access to online services.