Home ASP.NET Interview Question CategoriesWhat is the difference between login controls and Forms authentication? * Forms authentication can be easily implemented using login controls without writing any code.
* Login control performs functions like prompting for user credentials, validating them and issuing authentication just as the FormsAuthentication class.
* However, all that’s needs to be dne is to drag and drop the use control from the tool box to have these checks performed implicitly.
* The FormsAuthentication class is used in the background for the authentication ticket and ASP.NET membership is used to validate the user credentials.
What is Fragment Caching in ASP.NET? * Fragment caching refers to the caching of individual user controls within a Web Form.
* Each user control can have independent cache durations and implementations of how the caching behavior is to be applied.
* Fragment caching is useful when you need to cache only a subset of a page.
* Navigation bars, header, and footers are good candidates for fragment caching.
What is partial classess in .net?When there is a need to keep the business logic separate from the User Interface or when there is some class which is big enough to have multiple number of developers implement the methods in it, the class can be separated and written in different files as partial class.
The keyword partial must appear in each class.
//syntax for C#
Public partial class MyPartialClass1
{
//code
}
// this code could be in file1
Public partial class MyPartialClass1
{
//code
}
// this code could be in file2
Explain how to pass a querystring from an .asp page to aspx page.Consider the following URL:
http:// localhost/form.aspx?param1=career¶m2=ride
This html addresses use QueryString property to pass values between pages.
From the URL above the information obtained is:
form.aspx: which is the destination page for your browser.
Param1 is the first parameter, the value of which is set to career
Param2 is the first parameter, the value of which is set to ride
The ‘?’ marks the beginning of the QueryString
‘&’ is used as a separator between parameters.
private void formButtonSubmit_Click(object sender, System.EventArgs e)
{
Response.Redirect("form.aspx?Param1=" +
this.formTextfieldParam1.Text + "&Param2=" +
this. formTextfieldParam2.Text);
}
The above code is a submit button event handler and it sends the values of the query string to the second page.
The following code demonstrates how to retrieve these valus on the second page:
private void Page_Load(object sender, System.EventArgs e)
{
this.form2TextField1.Text = Request.QueryString["Param1"];
this. form2TextField2.Text = Request.QueryString["Param2"];
}
You can also use the following method to retrieve the parameters in the string:
for (int i =0;i < Request.QueryString.Count;i++)
{
Response.Write(Request.QueryString[i]);
}
What is a ViewState? * If a site happens to not maintain a ViewState, then if a user has entered some information in a large form with many input fields and the page is refreshes, then the values filled up in the form are lost.
* The same situation can also occur on submitting the form. If the validations return an error, the user has to refill the form.
* Thus, submitting a form clears up all form values as the site does not maintain any state called ViewState.
* In ASP .NET, the ViewState of a form is maintained with a built-in state management technique keeps the state of the controls during subsequent postbacks by a particular user.
* The ViewState option can be disabled by including the directive <%@ Page EnableViewState="false"%> at the top of an .aspx page
* If a ViewState of a certain control has to be disabled, then set EnableViewState="false"
Advantages:
i) No server resources.
ii) Viewstate ensures security because it stores the data in encrypted format.
iii) Viewstates are simple. They are used by enabling or disabling the viewstate properties.
iv) It is based on the wish of developer that they want to implement it at the page level or at control level.
Disadvantages:
i) If large amount of data is stored on the page, then page load might cause a problem.
ii) Does not track across pages. Viewstate information does not automatically transfer from page to page.
Difference between src and Code-Behind?With the ‘src’ attribute, the source code files are deployed and are compiled by the JIT as needed.
Though the code is available to everyone with an access to the server (NOT anyone on the web), this method is preferred as it does away with the compilation of the DLLs.
‘CodeBehind’ attribute just has the VS.NET associate the code file with the aspx file. This is necessary since VS.NET automates the pre-compiling that is harder by hand.
Due to this the ‘Src’ attribute is done away with having only a DLL to be deployed enhancing the protection level even though it can be decompiled.
What is the Pre-Compilation feature of ASP.NET 2.0?Previously, in ASP.NET, the pages and the code used to be compiled dynamically and then cached so as to make the requests to access the page extremely efficient. In ASP.NET 2.0, the pre-compilation feature is used with which an entire site is precompiled before it is made available to users.
There is a pre-defined folder structure for enabling the pre-compilation feature:
* App_Code: stores classes
* App_Themes: stores CSS files, Images, etc.
* App_Data: stores XML files, Text Files, etc.
* App_GlobalResources: stores all the resources at global level E.g. resx files, etc
* App_LocalResources: stores all the resources at local/Page level
ASP.NET - What is the Pre-Compilation feature of ASP.NET 2.0? It is a process where things that can be handled before compilation are prepared in order to reduce the deployment time, response time, increase safety. It’s main aim to boost performance.
It also helps in informing about the compilation failures.
During development, it allows you to make changes to the web pages and reuse it using the same web browser to validate the changes without compiling the entire website.
During deployment, it generates the entire website folder structure in the destination. All the static files are copied to the folder and bin directory would later on contain the compiled dll.
How can we create custom controls in ASP.NET?Custom controls are user defined controls. They can be created by grouping existing controls, by deriving the control from System.Web.UI.WebControls.WebControl or by enhancing the functionality of any other custom control. Custom controls are complied into DLL’s and thus can be referenced by as any other web server control.
Basic steps to create a Custom control:
1. Create Control Library
2. Write the appropriate code
3. Compile the control library
4. Copy to the DLL of the control library to the project where this control needs to be used
5. The custom control can then be registered on the webpage as any user control through the @Register tag.
Explain the steps to create a web services and consume it?Steps to create and consume a webservice
Creation:
* a. Create a new website by selecting "ASP.NET Web Site" and giving it a suitable name.
* b. service.cs file appears inside the solution with a default webmethod named as "HelloWorld()"
* c. Right click on the webservice project and add a web reference instead of adding a normal reference.
* d. A window appears that displays a list of webservices knows to the solution.
* e. Click on "Webservices in this solution"
* f. a search progress bar appears and
* g. Select the service that appears in the list
* h. progress bar appears once again.
* i. web method appears on the screen
* j. Click on "Add reference" button. This would add localhost
* k. solution would have App_WebReference folder
Consumption or Usage:
* a. Add a UI (.aspx) to the webservice project
* b. Add a button and a label to the form
* c. Double click the button to see the click event of the button
* d. Create an object of type service localhost.serviceName
* e. Write code to display the value returned by the webmethod on the label
* f. Execute the solution by setting the added aspx as the startpage.
* g. click on the button and the message "Hello World" would be displayed on the label
What is Cache Callback in Cache?The cache object has dependencies e.g. relationships to the file it stores. Cache items remove the object when these dependencies change. As a work around we would need to simply execute a callback method whenever items are removed from the cache to add the items back in cache.
e.g.: We have a string variable string var="hello" and store it in cache. This item would be removed from the cache if value is changed from "hello" to "bye". In such a case we need to simply right a callback function which would add updated var back in cache as it’s been removed as a result of its dependencies changing.
Explain the types of Caching using Cache object of ASP.NET? * Page output: Is used to fetch information or data at page level. It is best used when the site is mainly static. Used by declaring the output page directive
* Page fragment: Is used to cache the structure level information. It is used when parts of pages change. For example: user control
* Programmatic or data: Is used to fetch the information of an application quickly based on the requirements.
What is SQL Cache Dependency in ASP.NET?SQL Cache Dependency in ASP.NET: It is the mechanism where the cache object gets invalidated when the related data or the related resource is modified. It is a feature in SQL Server 2005 and SQL Server 2000.
3 types of SQL-cache dependencies exist:
a. Other cache items.
b. Files/folders.
c. Dependencies on a database query.
Home ASP.NET Interview Question Categories