| Swaps's profileSwaps BlogPhotosBlog | Help |
|
|
August 11 Make your web application run fasterFolks,
Make your web application run faster
A .NET DLL that may be used to cut response time for your app It is easy to develop your own ASP.NET web application. But making it do some useful things for your users while keeping the design simple and elegant is not so easy. If you are lucky, your web application will be used by more than a handful of users, in that case, performance can become important. For some of the web applications I worked on, performance is vital: the company will lose money if users get frustrated with the slow response.
There are many factors that can result in bad performance, the number of users is just one of them. As a developer in a big corporation, you usually don't have a chance to mess with real production servers. However, I think it is very helpful for developers to take a look at the servers that are hosting their applications. http://www.codeproject.com/aspnet/PEDLL.asp Swapnil (swaps) http://swapsnet.spaces.live.com/
Data Access Tutorials ASP.NET 2.0Folks,
Data Access Tutorials ASP.NET 2.0
Find below link which contains, a series of tutorials that will explore techniques for implementing these common data access patterns in ASP.NET 2.0. These tutorials are geared to be concise and provide step-by-step instructions with plenty of screen shots to walk you through the process visually. Each tutorial is available in Visual Basic and Visual C# versions and includes a download of the complete code used.
Swapnil (swaps)
New Public Properties of the Page ClassNew Public Properties of the Page Class The following public properties are new in ASP.NET 2.0.
AppRelativeTemplateSourceDirectory - Returns the application-relative path to the page or control. For example, for a page located at http://app/folder/page.aspx, the property returns ~/folder/.
AppRelativeVirtualPath - Returns the relative virtual directory path to the page or control. For example for a page located at http://app/folder/page.aspx, the property returns ~/folder/page.aspx.
AsyncTimeout - Gets or sets the timeout used for asynchronous page handling. (Asynchronous pages will be covered later in this module.)
ClientQueryString - A read-only property that returns the query string portion of the requested URL. This value is URL encoded. You can use the UrlDecode method of the HttpServerUtility class to decode it.
ClientScript - This property returns a ClientScriptManager object that can be used to manage ASP.NETs emission of client-side script. (The ClientScriptManager class is covered later in this module.)
EnableEventValidation - This property controls whether or not event validation is enabled for postback and callback events. When enabled, arguments to postback or callback events are verified to ensure that they originated from the server control that originally rendered them.
EnableTheming - This property gets or sets a Boolean that specifies whether or not an ASP.NET 2.0 theme applies to the page.
Form - This property returns the HTML form on the ASPX page as an HtmlForm object.
Header - This property returns a reference to an HtmlHead object that contains the page header. You can use the returned HtmlHead object to get/set style sheets, Meta tags, etc.
IdSeparator - This read-only property gets the character that is used to separate control identifiers when ASP.NET is building a unique ID for controls on a page. It is not intended to be used directly from your code.
IsAsync - This property allows for asynchronous pages. Asynchronous pages are discussed later in this module.
IsCallback - This read-only property returns true if the page is the result of a call back. Call backs are discussed later in this module.
IsCrossPagePostBack - This read-only property returns true if the page is part of a cross-page postback. Cross-page postbacks are covered later in this module.
Items - Returns a reference to an IDictionary instance that contains all objects stored in the pages context. You can add items to this IDictionary object and they will be available to you throughout the lifetime of the context.
MaintainScrollPositionOnPostBack - This property controls whether or not ASP.NET emits JavaScript that maintains the pages scroll position in the browser after a postback occurs. (Details of this property were discussed earlier in this module.)
Master - This read-only property returns a reference to the MasterPage instance for a page to which a master page has been applied.
MasterPageFile - Gets or sets the master page filename for the page. This property can only be set in the PreInit method.
MaxPageStateFieldLength - This property gets or sets the maximum length for the pages state in bytes. If the property is set to a positive number, the pages view state will be broken up into multiple hidden fields so that it doesnt exceed the number of bytes specified. If the property is a negative number, the view state will not be broken into chunks.
PageAdapter - Returns a reference to the PageAdapter object that modifies the page for the requesting browser.
PreviousPage - Returns a reference to the previous page in cases of a Server.Transfer or a cross-page postback.
SkinID - Specifies the ASP.NET 2.0 skin to apply to the page.
StyleSheetTheme - This property gets or sets the style sheet that is applied to a page.
TemplateControl - Returns a reference to the containing control for the page.
Theme - Gets or sets the name of the ASP.NET 2.0 theme applied to the page. This value must be set prior to the PreInit method.
Title - This property gets or sets the title for the page as obtained from the pages header.
ViewStateEncryptionMode - Gets or sets the ViewStateEncryptionMode of the page. See a detailed discussion of this property earlier in this module.
New Protected Properties of the Page Class
The following are the new protected properties of the Page class in ASP.NET 2.0.
Adapter - Returns a reference to the ControlAdapter that renders the page on the device that requested it.
AsyncMode - This property indicates whether or not the page is processed asynchronously. It is intended for use by the runtime and not directly in code.
ClientIDSeparator - This property returns the character used as a separator when creating unique client IDs for controls. It is intended for use by the runtime and not directly in code.
PageStatePersister - This property returns the PageStatePersister object for the page. This property is primarily used by ASP.NET control developers.
UniqueFilePathSuffix - This property returns a unique suffic that is appended to the file path for caching browsers. The default value is __ufps= and a 6-digit number.
New Public Methods for the Page Class
The following public methods are new to the Page class in ASP.NET 2.0.
AddOnPreRenderCompleteAsync - This method registers event handler delegates for asynchronous page execution. Asynchronous pages are discussed later in this module.
ApplyStyleSheetSkin - Applies the properties in a pages style sheet to the page.
ExecuteRegisteredAsyncTasks - This method beings an asynchronous task.
GetValidators - Returns a collection of validators for the specified validation group or the default validation group if none is specified.
RegisterAsyncTask - This method registers a new async task. Asynchronous pages are covered later in this module.
RegisterRequiresControlState - This method tells ASP.NET that the pages control state must be persisted.
RegisterRequiresViewStateEncryption - This method tells ASP.NET that the pages viewstate requires encryption.
ResolveClientUrl - Returns a relative URL that can be used for client requests for images, etc.
SetFocus - This method will set the focus to the control that is specified when the page is initially loaded.
UnregisterRequiresControlState - This method will unregister the control that is passed to it as no longer requiring control state persistence.
Swapnil (swaps)
August 06 New @ Page Directive AttributesNew @ Page Directive Attributes
ASP.NET 2.0 adds many new attributes to the @ Page directive. The following attributes are new in ASP.NET 2.0.
Async - The Async attribute allows you to configure page to be executed asynchronously.
AsyncTimeout - Specified the timeout for asynchronous pages. The default is 45 seconds.
CodeFile - The CodeFile attribute is the replacement for the CodeBehind attribute in Visual Studio 2002/2003.
CodeFileBaseClass - The CodeFileBaseClass attribute is used in cases where you want multiple pages to derive from a single base class. Because of the implementation of partial classes in ASP.NET, without this attribute, a base class that uses shared common fields to reference controls declared in an ASPX page would not work properly because ASP.NETs compilation engine will automatically create new members based on controls in the page. Therefore, if you want a common base class for two or more pages in ASP.NET, you will need to define specify your base class in the CodeFileBaseClass attribute and then derive each pages class from that base class. The CodeFile attribute is also required when this attribute is used.
CompilationMode - This attribute allows you to set the CompilationMode property of the ASPX page. The CompilationMode property is an enumeration containing the values Always, Auto, and Never. The default is Always. The Auto setting will prevent ASP.NET from dynamically compiling the page if possible. Excluding pages from dynamic compilation increases performance. However, if a page that is excluded contains that code that must be compiled, an error will be thrown when the page is browsed.
EnableEventValidation - This attribute specifies whether or not postback and callback events are validated. When this is enabled, arguments to postback or callback events are checked to ensure that they originated from the server control that originally rendered them.
EnableTheming - This attribute specifies whether or not ASP.NET themes are used on a page. The default is false.
LinePragmas - This attribute specifies whether line pragmas should be added during compilation. Line pragmas are options used by debuggers to mark specific sections of code.
MaintainScrollPositionOnPostback - This attribute specifies whether or not JavaScript is injected into the page in order to maintain scroll position between postbacks. This attribute is false by default. When this attribute is true, ASP.NET will add a <script> block on postback that looks like this:
Note that the src for this script block is WebResource.axd. This resource is not a physical path. When this script is requested, ASP.NET dynamically builds the script.
MasterPageFile - This attribute specifies the master page file for the current page. The path can be relative or absolute.
StyleSheetTheme - This attribute allows you to override user-interface appearance properties defined by an ASP.NET 2.0 theme. Specifies the theme for the page. If a value is not specified for the StyleSheetTheme attribute, the Theme attribute overrides all styles applied to controls on the page.
Title - Sets the title for the page. The value specified here will appear in the <title> element of the rendered page.
ViewStateEncryptionMode - Sets the value for the ViewStateEncryptionMode enumeration. The available values are Always, Auto, and Never. The default value is Auto. When this attribute is set to a value of Auto, viewstate is encrypted is a control requests it by calling the RegisterRequiresViewStateEncryption method.
Setting Public Property Values via the @ Page Directive
Another new capability of the @ Page directive in ASP.NET 2.0 is the ability to set the initial value of public properties of a base class. Suppose, for example, that you have a public property called SomeText in your base class and you’d like it to be initialized to Hello when a page is loaded. You can accomplish this by simply setting the value in the @ Page directive like so:
The SomeText attribute of the @ Page directive sets the initial value of the SomeText property in the base class to Hello!.
Swapnil (Swaps) http://swapsnet.spaces.live.com/
ASP.NET AJAX DocumentationFolks,
Jus back from small vacation.
If you're looking out to start on AJAX and find out some base documentation along with the working samples this is the link to donwload from.
When you download the documentation, be sure that you open the Readme.htm file for setup instructions. The Download includes working samples to help you get most out of ASP.NET AJAX
Swapnil (Swaps)
July 31 VS2008, .NET 3.5, Silverlight and ASP.NET FuturesFolks,
VS2008, .NET 3.5, Silverlight and ASP.NET Futures
Check out the explore the features & Downloads of VS 2008, .NET Framework 3.5, Silverlight.
Swapnil (Swaps)
Upgrading ASP.NET AJAX 1.0 Websites and Web Applications to .NET Framework 3.5Folks,
Upgrading ASP.NET AJAX 1.0 Websites and Web Applications to .NET Framework 3.5
Microsoft Visual Studio 2008 Beta 2 is finally released, and with it comes a bunch of great new features for writing and maintaining ASP.NET AJAX applications. Additionally, a new version of ASP.NET AJAX is included in the .NET Framework 3.5, which includes improvements over the current ASP.NET AJAX 1.0 release. This article walks you through the steps you’ll need to follow to upgrade your existing ASP.NET AJAX 1.0 Websites and Web Application Projects to use the AJAX support in .NET Framework 3.5 and Visual Studio 2008 Beta 2.
Check out this link
Swapnil (swaps) http://swapsnet.spaces.live.com/
Load user data once with an HttpModuleLoad user data once with an HttpModule
Instead of creating a new object with user data every time you need it, go back to the well and avoid having to write caching code.
These days’ systems provide a level of abstraction that makes sense in terms of data storage, but you still have to do a fair amount of work in your providers to make sure you aren't pounding the data store. That means caching, of course, but you still might be creating objects in several places (handlers, the page, user controls, etc.), and each time you're going to the well, whether it be by way of the caching mechanism you create or going to the data store.
So why cache at all? Why not get the data once, early in the request cycle, and go back to it when you need it? Oddly enough, it was good old fashioned FormsAuth that made me think of this, where in ASP.NET v1.x we would look up the user and roles, probably in an HttpModule, and access that data from where ever.
Yes, you can do this today with a well-written Membership provider, but it's more complicated than it needs to be. Not only is the interface fairly large, but then you have to create the various objects during the page lifecycle which in turn call the various pieces of the provider. It just seems like a lot of work. It means that in every piece, you have to call something like Membership.GetUser(User.Identity.Name), invoking the provider methods. What if you did something a little more simple. Heck, use the Membership API if you want to, but do it once. Create an HttpModule that goes something like this:
public class UserContext : IHttpModule { public void Init(HttpApplication application) { application.AuthenticateRequest += new EventHandler(application_AuthenticateRequest); } private void application_AuthenticateRequest(object sender, EventArgs e) { HttpContext context = HttpContext.Current; MembershipUser user = Membership.GetUser(context.User.Identity.Name); context.Items.Add("membershipUser", user); } public static MembershipUser Current { get { return (MembershipUser)HttpContext.Current.Items["membershipUser"]; } } public void Dispose() { } }
Then all you need is to call UserContext.Current from your code and you've got access to all that your user object has to offer. I used Membership here, but you could roll your own too. In fact, you could make this an abstract class and leave the implementation of AuthenticateRequest to a derived class, specific to your app. At first glance, this seems like a very small win, but how much do you use user objects around your page? Furthermore, how much plumbing have you written to implement caching? When you eliminate all of that, suddenly your code gets a lot more simple, and a lot easier to manage. If I had a half-dozen user controls on the page that all had to access my user, and maybe manipulate it, at least it only has to read once from the data store, and I'm free to not write a bunch of caching code for subsequent object creation. One caveat here is that you do need to keep thread safety in mind. If you don't use asynchronous page or handler methods, you're OK, but keep that in mind.
Swapnil (swaps) http://swapsnet.spaces.live.com/
July 28 Cracking the Mysteries of .NET 2.0 ConfigurationCracking the Mysteries of .NET 2.0 ConfigurationIntroductionOne of the wonderful features of .NET has been its XML configuration features. In the days of .NET 1.x, common application settings, database connection strings, ASP.NET web server configuration, and basic custom configuration data could be stored in a .config file. Custom configuration sections could use a few basic but custom structures, allowing a small variety of information to be stored in a .config file. More complex configuration, however, was most often accomplished with custom XML structures and custom parsing code. Such code could become quite complex, though, and there are a variety of ways of differing performance to accomplish the same thing. With .NET 2.0, the days of writing your own (probably complicated, poorly-performing and tedious) code to manage custom XML configuration structures are over. The custom configuration capabilities of the built-in XML configuration subsystem in .NET 2.0 have been greatly revamped, boasting some extremely useful and time saving features. With relative ease, just about any XML configuration structure you might need is possible with a relatively minimal amount of work. In addition, deserialization of the XML in a .config file can always be overridden. This allows any XML structure necessary to be supported without losing the other advanced features of .NET 2.0 configuration. Check out this link which has detailed level of Information on ASP.NET 2.0 Configuration. http://www.codeproject.com/csharp/mysteriesofconfiguration3.asp Swapnil (Swaps) http://swapsnet.spaces.live.com/
July 24 Intro to AJAX - ASP.NET 2.0Web applications lack the rich user interface provided by Desktop applications. They tend to be less responsive compared to Desktop products. Web applications employ inherit request/response cycle to build pages which in turn creates less natural and not so dynamic/responsive pages. It was always been a challenge for web developer to built slick, rich and dynamic web applications. We can feel lag... But it's no more now. Try Google Maps. Use the cursor to zoom in/out. Don't you feel the difference? Do you think it does post back for each request? Observe, everything happens instantly with out a page refresh. Wondered! AJAX does it all. o AJAX, an acronym for Asynchronous JavaScript And XML is a group of technologies like Java Script, XML, CSS, DOM, HTML and DHTML. o AJAX attempts to bridge the gap between the functionality and interactivity of a desktop application and the always-updated Web application. o You can build dynamic user interfaces and fancier controls like you'd find on a desktop application through AJAX implementation. Basic technologies involved in Ajax applications o HTML is used to build Web forms and identify fields and controls for use in the rest of your application. o JavaScript code is the core element running AJAX applications and it coordinates communication with server applications. o DHTML, or Dynamic HTML, helps you update your forms dynamically. You'll use div, span, and other dynamic HTML elements to mark up your HTML. o DOM, the Document Object Model, will be used (through JavaScript code) to work with both the structure of your HTML and (in some cases) XML returned from the server. Power of AJAX o With AJAX, when a user clicks a button, you can use JavaScript and DHTML to immediately update the UI, and spawn an asynchronous request to the server to fetch results. o When the response is generated, you can then use JavaScript and CSS to update your UI accordingly without refreshing the entire page. While this is happening, the form on the users screen doesn't flash, blink, disappear, or stall. o The power of AJAX lies in its ability to communicate with the server asynchronously, using XMLHttpRequest object with out requiring a browser refresh. o Ajax essentially puts JavaScript technology and the XMLHttpRequest object between your Web form and the server. Everything happens behind the scene a mini request/response cycle with out knowledge of the user. Finally, Jesse James Garrett who coined term AJAX defined AJAX as follows: Ajax isn't a technology. It's really several technologies, each flourishing in its own right, coming together in powerful new ways. Ajax incorporates: o Standards-based presentation using XHTML and CSS o Dynamic display and interaction using the Document Object Model o Asynchronous server communication using XMLHttpRequest o JavaScript binding everything together Advantages of AJAX based applications · Improved application performance by reducing amount of data downloaded from the server · Rich, responsive and Slick UI with no page flickers · Eliminates frequent page refresh which usually happens in a typical request/response model(Everything is updated on fly) · Easy to implement as there are variety of AJAX implementations available around · AJAX mechanism works behind the scene nothing much required from user perspective · Works with all browsers Several frameworks have emerged since then to support AJAX Web development. In this article, we will examine Microsoft's ASP.NET AJAX 1.0 RC for demonstration purposes Benefits of Microsoft ASP.NET AJAX ASP.NET AJAX integrates client script libraries with the ASP.NET 2.0 development framework. This new Web development technology extends ASP.NET, offering the interactive user interface benefits of AJAX with a programming model that is more familiar to ASP.NET developers, making it very easy to add AJAX to your applications quickly and with minimal effort. ASP.NET AJAX 1.0 RC can be downloaded from ajax.asp.net when installed; it adds an additional Web Site template for C# and Visual Basic.NET to Microsoft Visual Web Developer. When you create a new Web site project in Visual Web Developer, you will see a dialog like the one shown below. The Web.config will be updated accordingly to be able to use AJAX-based ASP.NET features. You are also expected to download the ASP.NET AJAX Control Toolkit which offers developers a rich variety of client-side controls with eye-catching control behavior without having to go through the trouble of writing and testing extensive JavaScript code. Swapnil (swaps) July 23 Learn How To Build A Provider FrameworkFolks,
Good Article on Provider Framework with examples.
Learn How To Build A Provider Framework
After reading this article, you'll be able to
(1) Change your mindset a little bit, and start thinking about 'frameworks' instead of just 'code'
(2) Understand a lot about practically applying provider pattern in your projects
(3) Gain much knowledge regarding xml config files and providers
Check out the following Link
Swapnil (Swaps)
Enter Key in ASP.NET - Complete ResearchEnter Key in ASP.NET - Complete Research One of the common requests in ASP.NET is to submit a form when visitor hit an Enter key. That could be a case if, for example you want to make Login Screen. It is expected that user just hit enter when he insert a password instead to of forcing him to use a mouse to click login button. If you want to make search function on your web site, it is frequently required to give a possiblity to hit enter after you insert a search terms instead of mouse click on a Search button. In classic HTML or ASP pages, it is not hard to submit forms using the enter key. Programmer use a <input type="submit"> to make a default button. If web site visitor click on that button or press enter key, the form will be submited. Off course, you can have a more than one form on your page and individual submit button for every form. You don't want to submit a form with Enter key? Rarely, you will need to disable an Enter key and avoid to submit form. If you want to prevent it completely, you need to use OnKeyDown handler on <body> tag of your page. The javascript code should be: if (window.event.keyCode == 13) ASP.NET problems with Enter key If you try to use Enter key in ASP.NET, according to your browser's type, you can get really weird results. Try to place one ASP.NET textbox and a button to the web form. Write a code on a OnClick event of a button. That could be something simple, like: Response.Write("The button was clicked!"); Now start debuging and write something to textbox. If you press enter while focus is on textbox, form will submit, but your code for button's click event will not be executed. Stop the debuging and place one simple HTML textbox to the form. You will not write anything in this textbox, so you can make it invisible. Just place this HTML code somewhere inside of your form tag. <INPUT type="text" style="VISIBILITY: hidden;POSITION: absolute"> Start debuging again. You cannot see the second textbox, and everything looks like before. Try again to write something in visible textbox. If you press enter now, form will submit, and also your code for button's click event will be executed. This is extremelly different behavior, and you did nothing except you placed one inivisible HTML textbox on web form. Maybe it is not elegant, but placing invisible textbox could be simple solution for you if you have only one button on your web form. But, what if you have a different situation? What if you have a few buttons with only one textbox, more than one text box with only one button, or many text boxes and many buttons on form? Different browsers has a different behaviors in these cases. if you have more buttons, only first button will be "clicked" every time. So, we need some other approach to get an universal solution.
We need to specify exactly what button will be "cliked" when visitor press Enter key, according to what textbox currently has a focus. The solution could be to add onkeydown attribute to textbox control: TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+Button1.UniqueID+"').click();return false;}} else {return true}; "); This line of code will cause that button Button1 will be "clicked" when visitor press Enter key and cursor is placed in TextBox1 textbox. On this way you can "connect" as many text boxes and buttons as you want. Default buttons in ASP.NET 2.0 ASP.NET 2.0 makes this problems easier and introduce a concept of a "default button". New defaultbutton attribute can be used with <form> or <asp:panel> control. What button will be "clicked" depends of where acutally cursor is and what button is choosen as a default button for form or a panel. Here is sample HTML code that contains one form and one panel control: <form defaultbutton="button1" runat="server"> Swapnil (Swaps) July 22 Client Call Back in ASP.NET 2.0Client Call Back in ASP.NET 2.0 ASP.NET 2.0 includes a new Client Callback feature that enables you to retrieve page values and populate them to an already-generated page with out reconstructing page. This makes it possible to use on a page with out going through the entire post back cycle; that means you can update your pages without completely redrawing the page. End users will not see the page flicker and reposition, and the pages will have a flow of a thick client application. It is an interesting feature that allows invoking server side code from Client side JavaScript using XmlHTTP. Postback and Callback Before we appreciate the feature of Callback, let's see how current Postback feature in a typical ASP.NET page works In a normal Postback situation, when any page event is triggered on ASP.NET page, a HTTP post request will be sent to web server, which then processes the request with the IPostbackEventHandler and runs the request through a series of page events. These events include loading the state (ViewState), processing data, processing Postback events and finally rendering the page to be interpreted by the consuming browser. This process completely reloads the page in the browser, which is what causes the flicker and the realignment to the top of the page. But in a Client call back situation, any page event is triggered on ASP.NET page; it causes the event to be posted to a script event handler (a JavaScript function) that sends off an asynchronous request to the web server for processing. ICallbackEventHandler runs the request through a pipeline similar to what is used with the Postback- but you notice that some of the larger steps (such as rendering the page) are excluded from the process chain. After the information is loaded, the result is returned to the script callback object. The script code then pushes this data into the web page using JavaScript's capabilities to do this without refreshing the page. Let's see an example to see how Callback feature works. Following page will generate Current date when end user clicks the button on the form, the callback service is initiated and current date is populated into the textbox. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> Partial Class _Default
Swapnil (Swaps) http://swapsnet.spaces.live.com/
July 19 Asynchronous Web Page Programming APS.NET 2.0
Asynchronous Web Page Programming
Asynchronous programming allows a process to have multiple threads, enabling the process to do more than one action simultaneously. While asynchronous programming can be complicated, it can dramatically improve performance in situations where the process would otherwise need to wait for a relatively slow action, such as accessing a network resource, to occur.
If you have done asynchronous programming in Windows Forms applications, you can also use those techniques in ASP.NET Web forms. However, ASP.NET provides a different technique as well. Additionally, because ASP.NET Web pages may have dozens of users simultaneously, the considerations and benefits of asynchronous programming are different.
Improving Performance with Asynchronous Web Page Programming In a Windows Forms application, you often use asynchronous programming to allow the application to respond to user input while a long-running process executes. In Web pages, the user can’t interact with the page until page rendering is complete, so responding to user input isn’t a valid reason for using asynchronous programming.
Instead, you should use asynchronous programming to improve the efficiency of long-running Web pages, even if each page only needs to perform one task at a time. In this case, the Web application becomes much more efficient during busy times when multiple pages are requested simultaneously because the thread pool is used more efficiently. For example, if you are creating a Web page that must query a network resource (such as a Web service), IIS and ASP.NET can only render a limited number of pages simultaneously. Therefore, the thread pool can become completely consumed, creating a performance bottleneck. Once the thread pool is consumed, your server waits for pages to finish rendering before beginning to process other pages. Even though the server might have available processor cycles, requests are queued. By enabling asynchronous Web page programming, the server can begin rendering more pages simultaneously, improving efficiency and reducing page rendering time.
To enable asynchronous Web page programming, follow these steps: 1. Add the Async="true" attribute to the @ Page directive, as the following example shows: 'VB <%@ Page Language="VB" Async="true" AutoEventWireup="false" %>
Swapnil (Swaps) http://swapsnet.spaces.live.com/
July 17 Batch Inserting from User Interface Layer in ASP.NET 2.0Folks,
Batch Inserting from User Interface Layer in ASP.NET 2.0
Learn how to insert multiple database records in a single operation. In the User Interface Layer we extend the GridView to allow the user to enter multiple new records. In the Data Access Layer we wrap the multiple Insert operations within a transaction to ensure that all insertions succeed or all insertions are rolled back. Find the Below link for complete tutorial and code download.
Swapnil (swaps)
Using Trace to Explore Web Pages in ASP.NET 2.0Using ASP.NET Trace to Explore Web Pages The trace facility that is included in ASP.NET can be used to troubleshoot and diagnose problems with your Web site. You can also use the trace facility to explore resource usage on each Web page. This lesson covers the enabling and configuring of the trace facility and then explores the data that is made available by the trace facility.
Enabling and Configuring the ASP.NET Trace Facility The trace facility can be enabled in the Web.config file, but you can use the Web Site Administration Tool to provide a user-friendly GUI to enable and configure this option. This section demonstrates the enabling and setting of the ASP.NET trace facility options.
Enabling the Trace Facility Using the Web Site Administration Tool The following steps identify how to enable and configure the trace facility using the Web Site Administration Tool: Open the Web Site Administration Tool by selecting Website | ASP.NET Configuration. Click the Application tab and click the Configure debugging and tracing link to view and modify the trace settings. Click Capture Tracing Information. This enables the trace facility. Change the settings as necessary. Below Para describes each of the settings.
Capture tracing information - Enabled - Enables the trace facility. When this option is enabled, the other trace options are also enabled.
Display tracing information on individual pages - pageOutput - Displays the trace information directly on the Web page that is being traced. Depending on the page content, the trace information displays either at the bottom of the Web page or behind the regular Web page content.
Display trace output for - localOnly - Designates either Local requests only or All requests. When set to Local Requests Only, the trace facility only operates with requests and PostBacks from the computer that the Web server is running on. The All requests setting enables the trace facility to respond for all requests and PostBacks from any computer to the Web site.
Select the sort order for trace results - traceMode - Enables sorting of the trace output either by time or by category.
Number of trace requests to cache - requestLimit - Sets the quantity of items to hold in the cache.
Select which trace results to cache - mostRecent - Designates the Most Recent Trace Results or the Oldest Trace Results. When set to Most Recent Trace Results, the cache continues to update, holding the latest results. When set to Oldest Trace Results, as soon as the number of requests has been met, the cache no longer updates until after the Web application is restarted.
Run the Web application. Navigate to the trace.axd page on the Web application (http://server/application/trace.axd). This is not a physical Web page. Instead, trace.axd is a virtual page that is constructed dynamically based on the Web pages you visited, and displays the trace data that is available.
Enabling the Trace Facility in the Web.Config File The ASP.NET trace facility can also be enabled in the Web application’s Web.config file. You do so using the following steps: Open the Web.Config file for your site. This is an XML file that contains settings for the Web site. Locate the trace element, which looks something like this.
<trace enabled="false" requestLimit="10"pageOutput="false" traceMode="SortByTime" localOnly="true" mostRecent="true" /> Change the settings as necessary. Run the Web application.
Navigate to the trace.axd page on the Web application (http://server/application/trace.axd) to display the trace data that is available.
Viewing the Trace Data After turning on the ASP.NET trace facility, you can either view the trace output on each Web page (pageOutput="true"), or view the trace output by navigating to the trace.axd (http://server/application/trace.axd) page on the current Web application. When navigating to the trace.axd page, a summary page displays, which contains the list of results that are in the cache. Click on one of the cached results to view the result of a single page request, which is similar to the resultant information that is shown on each Web page when the page output is set to True.
The trace result page is broken into sections. This information can be very useful when you are trying to identify performance issues and resource usage. Trace Result Section Description
Request Details Provides general details about the page request. Trace Information Displays performance information related to the Web page’s life-cycle events. The From First(s) column displays the running time from when the page request started. The From Last(s) column shows the elapsed time since the previous event.
Control Tree Displays information about each control on the Web page, such as the size of the rendered controls. Session State Displays all Session variables and their values. Application State Displays all Application variables and their states. Request Cookies Collection Displays the list of cookies that are passed to the server as part of the request. Response Cookies Collection Displays the list of cookies that are passed to the browser as part of the response. Headers Collection Displays the list of HTTP headers that are sent to the Web server as part of the request. Form Collection Displays the list of values that are posted back to the Web server. QueryString Collection Displays the list of values that are included in the query string. Server Variables Displays all server variables.
Swapnil (Swaps) http://swapsnet.spaces.live.com/
July 16 Storing Binary Data in Database in ASP.NET 2.0Folks,
This article explains storing of Binary Data like PDF, ZIP, and Image files in Database using ASP.NET 2.0. The Traditional approach is to upload the files into the File storage server, but sometimes there is need to store the files in database itself. This article talks about how to convert the PDF, ZIP and Image files into binary content and store it in Database. Please refer to the link below.
Swapnil (Swaps)
View State in ASP.NET 2.0
View State As you all might have already noticed, if a user clicks a button to submit an ASP.NET page, the page retains all its values and settings. For example, if you modify the text on a label and the user clicks a button, the modified text is still displayed when the page reappears. This happens because ASP.NET has a client-side state management technique built in: ViewState. The ViewState property provides a dictionary object for retaining values between multiple requests for the same page. When an ASP.NET page is processed, the current state of the page and controls is hashed into a string and saved in the page as a hidden field. If the data is too long for a single field (as specified in the MaxPageStateField-Length property), then ASP.NET performs view state chunking to split it across multiple hidden fields. The following code sample demonstrates how view state adds data as a hidden form within a Web page’s HTML:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTIxNDIyOTM0Mg9kFgICAw9kFgICAQ8PFgIeBFRleHQFEzQvNS8yMDA2IDE6Mzc6MTEgUE1kZGROWHn/rt75XF/pMGnqjqHlH66cdw==" />
View state chunking is new in ASP.NET 2.0. The sections that follow describe how to encrypt view state data, disable view state data, and add custom values to the view state.
Encrypting View State Data You can enable view state encryption to make it more difficult for attackers and malicious users to directly read view state information. This adds processing overhead to your Web server; however, it is necessary if you plan to store confidential information in the view state. To configure view state encryption for an application, set the <pages viewStateEncryptionMode> attribute to Always in your Web.config file, as the following example shows:
<configuration> <system.web> <pages viewStateEncryptionMode="Always"/> </system.web> </configuration>
Alternatively, you can enable view state encryption for a specific page by setting the value in the page directive, as the following sample demonstrates:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ViewStateEncryptionMode="Always"%>
Because ViewState supports encryption, it is the most secure method of client-side state management. Encrypted ViewState is secure enough for most security requirements; however, it is always more secure to store data on the server.
Disabling ViewState Data View state is enabled by default for every control, including Label controls, which you might never change. Unfortunately, view state adds overhead to ASP.NET forms. If you do not need to use view state, you should disable it by setting the EnableViewState property for each Web control to False. This reduces server processing time and decreases page size.
Reading and Writing Custom ViewState Data You can also add and retrieve custom values with ViewState. If you have a value that you’d like to keep track of while the user is visiting a single ASP.NET Web page, adding a custom value to ViewState is the most efficient and secure way to do that. However, ViewState is lost if the user visits a different Web page, so it is useful only for temporarily storing values. The following code demonstrates how to determine whether the time of the last visit was recorded in ViewState, how to display the value in a Label control named Label1, and then to set the value using the current time. To use this code, create a form with a Label control named Label1 and a Button control:
' Check if ViewState object exists, and display it if it does If (Me.ViewState("lastVisit") IsNot Nothing) Then Label1.Text = CType(Me.ViewState("lastVisit"), String)Else Label1.Text = "lastVisit ViewState not defined!" End If ' Define the ViewState object for the next page view Me.ViewState.Add("lastVisit", DateTime.Now.ToString())
While cookies must be strings, you can store a wide variety of serializable objects in ViewState. The following example stores a DateTime object in ViewState without converting it to a string and also uses a different technique for adding a ViewState value:
' Check if ViewState object exists, and display it if it does If (Me.ViewState("lastVisit") IsNot Nothing) Then Dim lastVisit As DateTime = CType(Me.ViewState("lastVisit"), DateTime) Label1.Text = lastVisit.ToString() Else Label1.Text = "lastVisit ViewState not defined!" End If ' Define the ViewState object for the next page Me.ViewState("lastVisit") = DateTime.Now
Swapnil (Swaps) http://swapsnet.spaces.live.com/
July 15 State Management ASP.NET - SummaryState Management in ASP.NET Summary
ASP.NET has more functions and utilities than ASP to enable you to manage page state more efficient and effective. Choosing among the options will depand upon your application, you have to think about the following before making any choose:
How much information do you need to store? Does the client accept persistent or in-memory cookies? Do you want to store the information on the client or server? Is the information sensitive? What kind of performance experience are you expecting from your pages?
Client-side state management
Method to Use
Cookies You need to store small amounts of information on the client and security is not an issue.
View state You need to store small amounts of information for a page that will post back to itself. Use of the ViewState property does supply semi-secure functionality.
Hidden fields You need to store small amounts of information for a page that will post back to itself or another page, and security is not an issue.
Note You can use a hidden field only on pages that are submitted to the server.
Query string You are transferring small amounts of information from one page to another and security is not an issue.
Note You can use query strings only if you are requesting the same page, or another page via a link.
Server-side state management
Method to Use
Application state object
You are storing infrequently changed, application-scope information that is used by many users, and security is not an issue. Do not store large quantities of information in an application state object.
Session state object
You are storing short-lived information that is specific to an individual session, and security is an issue. Do not store large quantities of information in a session state object. Be aware that a session state object will be created and maintained for the lifetime of every session in your application. In applications hosting many users, this can occupy significant server resources and affect scalability.
Database support
You are storing large amounts of information, managing transactions, or the information must survive application and session restarts. Data mining is a concern, and security is an issue.
Swapnil (swaps) http://swapsnet.spaces.live.com/
State Management in ASP.NET - 2Server-side state management: Information will be stored on the server, it has higher security but it can use more web server resources. A. Aplication object
The Application object provides a mechanism for storing data that is accessible to all code running within the Web application, The ideal data to insert into application state variables is data that is shared by multiple sessions and does not change often.. And just because it is visible to the entire application, you need to used Lock and UnLock pair to avoid having conflit value.
Application.Lock(); Application[“mydata”]=”mydata”; Application.UnLock();
Swapnil (swaps)
http://swapsnet.spaces.live.com/
|
|
|