What 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.
Cache types in ASP.Net 1. Page Output caching [Output caching ] 2. Fragment caching [Output caching ] 3. Data Caching Page output caching Before starting Page Output caching we need to know the compilation process of a page, because based on the generation of page we should able to understand why should we used caching . ASPX Page compiled in two stage process. First, the code is compiled into the Microsoft Intermediate Language (MSIL). Then, the MSIL is compiled into native code (by JIT Compiler ) during execution. and entire code in an ASP.NET Web page is compiled into MSIL when we built the sites , but at the time of execution only the portion of MSIL Converted to native code which is need by user or user request, which also improve performance. Now what ever we are getting , if there is some page which change frequently JIT need compile every time. So, We can use Page output for those page which content are relatively static. So rather than generating the page on each user request we can cached the page using Page output caching so that it can be access from cache itself. so, Instead of pages can be generated once and then cached for subsequent fetches.Page output caching allows the entire content of a given page to be stored in the cache. The first request is generated page is been cached and for same page
request page should be retrieve from cache itself rather that regenerating the page. For Output caching , OutputCache directive can be added to any ASP.NET page, specifying the duration (in seconds) that the page should be cached. The code. <%@ Page Language="C#" %> <%@ OutputCache Duration='300' VaryByParam='none' %> <script runat="server"> protected void Page_Load(Object sender, EventArgs e) { lbl_msg.Text = DateTime.Now.ToString(); }
Output Cache example
Page generated on:
void Page_Load(Object sender, EventArgs e) { Response.Cache.SetExpires(DateTime.Now.AddSeconds(360)); Response.Cache.SetCacheability( HttpCacheability.Public); Response.Cache.SetSlidingExpiration(true); _msg.Text = DateTime.Now.ToString(); } <%@ OutputCache Duration="40" VaryByParam="*" %>
All the attributes that we specify in an OutputCache directive are used to populate an instance of the System.Web.HttpCachePolicy class by calling. The complete implementation of cache policies provided by ASP.NET is encapsulated in the HttpCachePolicy class. Following is the another implementation of caching from code behind. Output Caching Location: As I have already mention We can store cached data in different location like client, server or in between client and server , Now I am going to discuss how this is feasible to set location of cached data. If we store the cached data it save the page rendering time by fetching the data from catch. There is another way that we can save cached data on client browser , which reduce the network traffic. OutputCache directive on a page enables all three types of caching—server, client, and proxy—by default. Following Table shown you the Location details . It show the location of cached and what should be the effects on Cache-Control and Expires Header.
For example, if you specified a value of 'Client' for the Location attribute of an OutputCache directive on a page, the page would not be saved in the server cache, but the response would include a Cache-Control header ( Pages can indicate whether they should be cached on a proxy by using the Cache-Control header.) value of private and an Expires header (HTTP
response, indicating the date and time after which the page should be retrieved from the server again ) with a timestamp set to the time indicated by the Duration attribute <%@ OutputCache Duration='120' Location='Client' VaryByParam='none' %>
Fragment Cache ASP.NET provides a mechanism for caching portions of pages, called page fragment caching. To cache a portion of a page, you must first encapsulate the portion of the page you want to cache into a user control. In the user control source file, add an OutputCache directive specifying the Duration and VaryByParam attributes. When that user control is loaded into a page at runtime, it is cached, and all subsequent pages that reference that same user control will retrieve it from the cache. <%@ OutputCache Duration='60' VaryByParam='none' %> <%@ Control Language="'C#'" %> <script runat="server"> protected void Page_Load(Object src, EventArgs e) { _date.Text = "User control generated at " + DateTime.Now.ToString(); }
Here I have user caching on user control, so when ever we used in a page , only partial page will be cached.
Data Cache Data Cache is used to storing frequently used data in the Cache memory. It's much efficient to retrieve data from the data cache instead of database or other sources. We need use System.Web.Caching namespace. The scope of the data caching is within the application domain unlike "session". Every user can able to access this objects.
ASP.NET page lifespan leave a comment » When the browser requests a page from the web server, the browser and the web server make a connection that last long enough to process that particular request. After the web server has rendered a page to the browser, the connection is terminated. A subsequent request to the same web server for the same page is processed as a new request. When the user requests an ASP.NET web page, a new instance of the page is created. The page performs its processing, renders markup to the browser, and is then discarded. If the user clicks a button to perform a postback, a new instance of the page is created, the page performs its processing, and is again discarded. Thus, each postback and round trip results in a new instance of the page.
What is Fragment Caching in ASP.NET? Latest answer: 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............. Read answer
What is partial classess in .net? Latest answer: Partial classes allow us to divide the class definition into multiple files (physically). Logically, all the partial classes are treated as a single file by the compiler............ Read answer Explain how to pass a querystring from an .asp page to aspx page. Latest answer: FromHTMLinasppage:Test Query String From server side code: <%response.redirect "webform1.aspx?id=11"%>...............
Describe how Passport authentication works. ASP.NET application with Passport authentication implemented checks the user’s machine for a current passport authentication cookie. If it is not available, ASP.NET directs the user to a Passport sign-on page. The Passport service authenticates the user, stores an authentication cookie on the user’s computer and direct the user to the requested page. Explain the steps to be followed to use Passport authentication. 1. Install the Passport SDK. 2. Set the application’s authentication mode to Passport in Web.config. 3. Set authorization to deny unauthenticated users. 3. Use the PassportAuthentication_OnAuthenticate event to access the user’s Passport profile to identify and authorize the user. 4. Implement a sign-out procedure to remove Passport cookies from the user’s machine. Explain the advantages of Passport authentication. User doesn’t have to remember separate user names and passwords for various Web sites User can maintain his or her profile information in a single location.
Passport authentication also avail access to various Microsoft services, such as Passport Express Purchase. What is caching? Caching is the technique of storing frequently used items in memory so that they can be accessed more quickly. By caching the response, the request is served from the response already stored in memory. It’s important to choose the items to cache wisely as Caching incurs overhead. A Web form that is frequently used and does not contain data that frequently changes is good for caching. A cached web form freezes form’s server-side content and changes to that content do not appear until the cache is refreshed. Explain the use of duration attribute of @OutputCache page directive. The @OutputCache directive’s Duration attribute determines how long the page is cached. If the duration attribute is set to 60 seconds, the Web form is cached for 60 seconds; the server loads the response in memory and retains that response for 60 seconds. Any requests during that time receive the cached response. Once the cache duration has expired, the next request generates a new response and cached for another 60 seconds.
What is a ViewState? Latest answer: Viewstate is used to maintain or retain values on postback. It helps in preserving a page. Viewstate is internally maintained as a hidden field in encrypted form along with a key...........
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 indicates the status of the page when submitted to the server. The status is defined through a hidden field placed on each page with a