| Swaps 的个人资料Swaps Blog照片日志 | 帮助 |
|
7月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/
7月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/
7月26日 Silverlight ResourcesFolks,
If Anybody interested in knowing what is SLiverLight and how it works, this is the link to go through
Swapnil (swaps)
Tab Key in Web ApplicationsTab Key in ASP.NET Applications To make your Web application more efficient and easier to use, you need to remove any difficulty in web form navigation that your user could experience. User interface and web site navigation must be logical, easy to use and if possible: already well-known from other applications. Off course, nobody wants to learn some new complicated and unnecessary things and crawl through a large help files. Users wants self-explanatory interface that they can start to use immediately. One of common standards is using a keyboard TAB key to move focus forward (or Tab + Shift key to move focus back) between controls on form, instead of forcing your Web site visitor to use a mouse click for changing a focus. Off course, your visitor still CAN use a mouse to set focus in the some text box, but many of them, and they are usually experienced and expert users will more like to use a keyboard only, because it is faster and more efficient way. Tab order in web form So, you need to define a logical navigation through a web form using a Tab key. There is a TabIndex property of server controls. First control in form should lowest TabIndex. With every next tab, focus will move to the control with next higher TabIndex. It is pretty simple to set tab order, you need only to care about few common problems: Problem 1: When we run the page, we can see there is no control with focus when web page is loaded. Much better solution is to have a focus on the right place immediately after page is shown. One solution, which shows how you can set a focus to textbox named txtFirstName, when page is loaded, could be a code like this: Page.RegisterStartupScript("SetInitialFocus", _ Problem 2: Focus moves through a web form, but also goes to Web browser address bar, Google or Yahoo toolbar etc. It is more expected that focus should move only inside the web form, instead to goes to browser address bar. Let say the last focus in on the button named "btnOK" and we want when user press tab key, move focus to the first textbox "txtFirstName" and skip browser toolbars, address bars and other distraction things. You can do it with next piece of code: btnOK.Attributes.Add("onkeydown", _ You don't want to move a focus to specific control?For some reason, you don't want to some control receive a focus. That could be a case if, for example you have an invisible text box or some search text box on top of the web page, but you want to allow tab functionality only to few main controls on the web form. Simply set TabIndex property of server control, or tabindex attribute of HTML control to -1. When you run web page and hit tab key, controls with TabIndex = -1 will never get a focus. Although, user can click into this control with a mouse and set focus on that way. How to type TAB key in textbox or textareaSometimes, you don't need to move cursor to the next control when hit Tab key. What if you need to type Tab character into text box or text area as a part of the text? Off course, your user can type tab in Notepad or some other text editor and simply do copy/paste to your form, but it is not so elegant solution for your Web application :). Instead of that, you can use script like this (in text box named txtLongText): txtLongText.Attributes.Add("onkeydown", _ Or better, to avoid hard coding, you can put this code to function named EnableTabType. Function has only one parameter, which specifies what is TextBox control where you need to enable typing of Tab characters. Public Sub EnableTabType(tb As TextBox) Tab key endnoteDefault value of TextBox AutoPostBack property is false. If you set it to true and if text in TextBox control is changed, tab key will cause form to submit. After submiting, it is possible to loose a focus on current control, especially if you used javascript on page load to set focus initially. In that specific case, you can register client script dynamically and only if Page.IsPostBack value is false. Swapnil (Swaps) http://swapsnet.spaces.live.com/
7月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) 7月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) 7月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/
7月19日 Developing RIA using ASP.NETFolks, Developing RIA using ASP.NET Over the last year or so RIAs have made a big impact on the web, mainly due to the adoption of One of the main things to note about RIAs is the paradigm shift with regards to presentation, data and behaviour. Check out on this link http://dotnetslackers.com/articles/aspnet/DevelopingRIAs1.aspx Swapnil (swaps) http://swapsnet.spaces.live.com/
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/
7月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/
7月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/
7月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/
7月11日 State Management in ASP.NETFolks,
It is something very common and we are using some of the features of ASP.NET like State Management in Web Pages. Since we use these features on day to day basis, it becomes very essential to get clear understanding of it. Let me highlight in detail and the various ways of Managing State in ASP.NET.
Web form pages are HTTP-Based, they are stateless, which means they don’t know whether the requests are all from the same client, and pages are destroyed and recreated with each round trip to the server, therefore information will be lost, therefore state management is really an issue in developing web applications There is no information maintained on the server between round trips. Information will be stored in the page or on the client’s computer. if (Request.Cookies[“username”]!=null) A hidden field does not render visibly in the browser, but you can set its properties just as you can with a standard control. When a page is submitted to the server, the content of a hidden field is sent in the HTTP Form collection along with the values of other controls. A hidden field acts as a repository for any page-specific information that you would like to store directly in the page. Hidden field stores a single variable in its value property and must be explicitly added it to the page. protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1; Each control on a Web Forms page, including the page itself, has a ViewState property, it is a built-in struture for automatic retention of page and control state, which means you don’t need to do anything about getting back the data of controls after posting page to the server. //to save information Query strings provide a simple but limited way of maintaining some state information.You can easily pass information from one page to another, But most browsers and client devices impose a 255-character limit on the length of the URL. In addition, the query values are exposed to the Internet via the URL so in some cases security may be an issue. string categoryid, productid;
We will see Server Side State management in next article
Hope this is useful to you all
Swapnil (swaps) http://swapsnet.spaces.live.com/
7月10日 Connection Pooling @ GlanceFolks,
I had come across a good article on ADO.NET Connection pooling the Table of contents is as follows
Table of Contents
Please check the following link for the details http://www.codeproject.com/useritems/ADONET_ConnectionPooling.asp
Swapnil (swaps) http://swapsnet.spaces.live.com/
|
|
|