Friday, June 5, 2009

ASP.NET Caching

Caching

Caching is the process of storing frequently used data, usually data that is costly to generate, for reuse. Typically this data is stored in memory since retrieving data from memory is much more efficient than retrieving the data from other locations, such as a database.

ASP.NET has several facilities for supporting caching: a Cache API for storing arbitrary data and an Output Cache used to store frequently requested Pages.

Let's discuss a quick example.

A catalog used on an e-commerce site might only change once a week. An ASP.NET Web application could be built that provides a front-end interface for that catalog, allowing customers to purchase products. When a customer is simply browsing the catalog, the system is making (in most cases) network calls to a back-end database server. The database server is also doing calculations on the data, such as a join query, and returning results.

This type of configuration is quite common, be it a catalog or some other type of commonly requested data from a database. However, the design in the above example can be improved upon. We know that the data in the database only changes once a week, and we know that there are several performance costs associated with retrieving the data:

  1. Executing of the ASP.NET code to make the database request.
  2. Use of the network for the Web server to communicate with the database server.
  3. Work done on the database server to compile and execute the query (or simply execute stored procedure).

Caching allows us to eliminate much of the above work and improve the performance and scalability of our application. We can improve performance by caching the results and serving them statically (versus dynamically on each request) and our scalability increases since we're using fewer resources to service each request.

Beta 1 of ASP.NET introduced the Cache API as well as Page output caching, which uses the Cache API. Let's discuss these two features in more detail.

Cache API

Storing frequently requested data in memory is nothing new for ASP developers. We've had two types of objects that solve this problem:

  • Session objects
  • Application objects

Session is used to store per-user data across multiple requests. There have been some changes for Session in ASP.NET but most of these changes are application level changes and don't affect the way Session is used, that is, it's still a simple key/value pair.

The Application object from ASP is also carried forward to ASP.NET, and it to remains identical in function (key/value pairs). For example, we could write the following in either ASP or ASP.NET:

see full detail:

http://msdn.microsoft.com/en-us/library/ms972379.aspx

Partial update of parent page via AJAX (ASP.NET 2.0) on close of a child window - conditionally

Introduction

At times, we are in situations where we need to open a child window, do some work on it, and then close it. Now, based on what was done on the child window, we may need to refresh the parent page or not. Now, not just refresh, a partial refresh! I have tried to demonstrate how we can pass on a value to a child, do something out there, and on saving it, we partially update the parent page. If nothing was done on the child window or the operation was canceled, then there would be no update of the parent page. This whole operation gives a good feel to the user, and the performance of the page would look a lot improved.

Background

We had a requirement in our project where we needed to update the parent page partially based on a particular value returned from the child window. Earlier, we were able to update the parent page, but all the time! Finally, after getting around the way described below, we were able to achieve partial update of the parent page only when required.

Using the code

For demonstration's sake, I had placed few Labels on the parent page. Couple of them inside the UpdatePanel and one outside it - just to keep an eye on the page getting partially updated whenever any update is done. The parent page ASPX looks like:

See full detail: http://www.codeproject.com/KB/ajax/AjaxUpdateParentPage.aspx?msg=3068586#xx3068586xx

Thursday, June 4, 2009

Integrating PayPal Payments into E-Commerce Applications with ASP.NET

E-Commerce applications require mechanisms for payment. Although more commonly than not e-Commerce sites will use full credit card processing gateways, giving PayPal as an additional option of payment provides additional payment options for your customers, especially those that don’t want to pay by credit card over the Internet. If you run a Web shop that uses direct credit card processing and want to integrate PayPal seamlessly, you’ll find that using PayPal as a processing service is not as straight forward as using a payment gateway. In this article I describe how you can minimize the external PayPal interaction and work the PayPal payment into the order processing workflow to provide a seamless interface using ASP.NET and C#. However, the principles used here should be applicable to any Web programming environment.

Payment processing on the Web is a big market and there a myriad of services and providers that allow you to process credit cards and bank cards over Internet connections. Most of these services are using credit card processing that automates the process of credit card validation. These providers usually provider either HTML or API based interfaces to process credit cards. HTML based interfaces provide you with a URL your application can redirect to on the provider’s site, which then handles the actual payment processing. API based interfaces allow your application talk directly to the provider’s services so that the payment processing can be integrated into your own application.

If you’re running your own E-Commerce applications you generally will want to use an API so the payment processing can be directly integrated into your own application. This makes sure the user of your app sees a consistent Web interface – as far as the user is concerned they are never leaving your site, but rather your Web backend is making the remote calls against the payment processing service and simply returning the success or failure of the request. HTML based payment interfaces generally look unprofessional as the user is whisked off to some other site for payment processing. Using external HTML processing often also requires you to handle inventory and order management through the payment provider which can be hassle especially if your e-commerce app already handles this. Still HTML based interface are popular because they can often be driven from non-data driven site and thus mitigate all the order management to the processing provider’s servers which can be beneficial for small sites.


Why PayPal?
On my own Web Site’s West Wind Web Store I use API based processing with Authorize.NET to perform most payment processing. This works great is fast and provides an integrated mechanism that provides seamless integration. We sell our software products online and from time to time there are those customers that are still squeamish about using their credit cards online – often customers from Europe – that would rather use an alternate payment mechanism. So a while back I looked at integrating PayPal into my store software.

PayPal may not be the first choice for order processing in a custom e-Commerce application, but it does provide another payment option for your customers. Some customers (at least in my business) are notoriously difficult in finding the ‘right’ payment mechanism and PayPal has been the answer for me in a number of cases, which is why I eventually sat down and integrated it into my Web Store application.

I've actually been surprised how many orders I get in my store through PayPal. When I originally hooked this up a few months back I thought of it more of a novelty and another bullet item for the store software, but there are quite a few people left in this world who don't trust the Internet (or the vendors for that matter) with their credit cards. PayPal is nice in that respect in that they provide the ability to keep the credit card from any vendor at all - now you just have to worry that PayPal stays safe and honest.

On the merchant front too I've found a lot of people actually using the PayPal functionality as their main payment mechanism instead of merchant services. A lot of small operations or personal sites don't want to deal with merchant services it seems. I can't blame them - most merchant providers or at least the 'resellers' are crooks trying to make a quick buck of the unsuspecting vendor. Getting set up also takes some amount of paperwork and often can take weeks. Luckily that seems to be changing somewhat with better and more consistent gateway services appearing with reasonable prices (my experience with MerchantPlus and Authorize.Net has been a real joy actually). Still, with PayPal you hit the ground running as soon as you have configured your account and provided a bank account.
On the downside, PayPal is a purely Web based interface. If you need to integrate payment processing into a non-Browser based application, PayPal is not an option since PayPal works exclusively through the Web browser interface. So if your business also takes phone orders and has an offline POS system, PayPal will be a hassle as you'd have to enter orders on the Web. PayPal also has rather high sales percentages that are generally much higher than merchant accounts (unless you are super high risk). Be sure you do the math. A little time up front may save you a lot of money in the long run - percentages are what often make or break your sales margins.
PayPal acts as a middle man between the buyer and seller so that the seller never has to expose his payment information to the seller directly. Instead the buyer registers his credit card or bank account with PayPal and maps his account to an email address and then uses PayPal to make purchases. The advantage here is that the seller never gets the buyers payment information and therefore can’t abuse it (accidentally or otherwise) in any way..

So what do you need to accept payments? The nice thing about PayPal is that it’s easy to sign up to accept payments. If you already have a PayPal account you use for buying things online, then you are already set up to also receive payments. All you need to have a bank account so payments can be deposited into it. That’s it!


How PayPal works

PayPal is not a payment gateway and they don’t provide a direct API interface to their service, except for very large/high volume customers. Rather, like the HTML based services I mentioned earlier, the buyer has to go to the PayPal site, login and accept the payment request. However, this process can be automated to some extent by configuring PayPal to return to specific URLs in case of success or failure and providing a callback confirmation Url that allows you to verify that PayPal processed a payment on your behalf. This configuration is done via POST data or QueryStrings passed to the PayPal pages.

In my Web Store I want PayPal to process only my final order amount. PayPal supports a number of order and inventory management features, but in an e-Commerce site scenario such as mine, all of this handled by my own Web application – all I want PayPal to do is process the final order amount.

As you might expect from this description this process is fairly involved if you want to completely integrate the payment into the application. The process goes like this:

  1. User picks items in our store Web site
  2. User fills out order info and goes to our store’s order page
  3. We provide the order total
  4. User accepts the order of multiple items and final amount
  5. User selects PayPal as payment
  6. User gets redirected to the PayPal site
  7. PayPal site takes user through the payment process
  8. On Success PayPal redirects back to our order confirmation page
  9. On Failure PayPal redirects back to our order form (redisplays order info)
  10. Finally we need to confirm to PayPal that we want to process this orderand PayPal confirms to us that the order went through.

See full detail: http://www.west-wind.com/presentations/PayPalIntegration/PayPalIntegration.asp

Credit Card Validator control for ASP.NET

Introduction
A while ago I started working on converting an eCommerce payment gateway's (
DataCash) COM server to a native .NET assembly using their XML API. Once I had got a basic version working I decided to produce a simple web form to test it out, and so opened it up for all comers (and received some very generous donations from CP members -- thanks guys :). As part of this web form I wanted to include support to check that users had entered a card number, expiration date etc., and then wanted to extend it further to include support for checking that the card number was valid before issuing a request to the payment gateway's server. This is the result, a drop-in replacement for any of the other validation controls.

Incidentally, you can see a demo of the validator in use (as well as the card payment gateway assembly) at the following address:
https://ssl500.securepod.com/oobaloo/DataCash/, besides this you may also be interested in the everything you ever wanted to know about CC's guide.
Before getting into any of the implementation details here is a simple UML class diagram to show the rough layout of the Control.


see full detail: http://www.codeproject.com/KB/validation/creditcardvalidator.aspx

Integrating Electronic Payment Processing into ASP.NET Web Applications

Electronic Payment processing continues to be a common theme for many Web based applications and while the process is getting easier with the market maturing, there's still a maze of choices and options in setting up your payment solutions and get them integrated into existing applications. In this article, I'll give a high level overview of the electronic payment processing by looking at the various players involved in the payment processing operation and some suggestions and options you have on getting hooked up with the right provider. I'll talk about how the process works, what it takes to get started and what it's going to cost. Finally I'll take you through an application that integrates payment processing and show a class you can use to integrate a few of the common Gateway services into existing applications.

The process of taking electronic payments from customers and getting the money deposited into your own accounts is a winding one, with several levels of providers being part of the transaction process. Figure 1 shows an overview of the process and the entities involved.
See full detail: http://www.west-wind.com/presentations/aspnetecommerce/aspnetecommerce.asp

Wednesday, June 3, 2009

Live Data Binding using ASP.NET AJAX 4.0

Introduction
Many of you may already be familiar with the upcoming version of ASP.NET AJAX, version 4.0. The release was out on March 12, 2009. The key features for this version are:

  • ADO.NET Data Services support
  • WCF and ASMX Web service integration
  • ASP.NET AJAX Client Templates
  • Declarative instantiation of client-side controls and behaviors
  • Observable pattern for plain JavaScript objects
  • Live Bindings
  • Markup Extensions
  • DataView control and DataContext component
  • Command Bubbling
  • Change tracking and identity management
  • Support for managing complex links and associations between entities from multiple entity sets or tables
  • Extension methods allowing change tracking and read-write client-server scenarios using other JSON services, including RESTful or JSONP based services
This preview version can be downloaded from here. This writing is mostly for highlighting the "Live Binding" feature introduced in this release of ASP.NET AJAX. This will also cover some operations on DataView control and DataContext component.

What is Live Binding?

Live binding is having the data bound in real-time. Meaning when there's any change in the data source, the changes are reflected to the data bound interface instantly and vice versa. For example if you have an interface component, like a table, bound to a data source, like an array, any change to that array from the code is reflected in the view table instantly. If you are using an edit template for updating the data of a selected row of the table, the data in the table will get updated as you change a field in your edit form if both the table and the form use "Live Binding".
span >Pretty cool, right?

Inside Live Binding

This is all done through client-side script, JavaScript. But how does it come in action? The core of the live binding is the implementation of an "Observer" pattern. The observer pattern enables an object to be notified about changes that occur in another object. This is not an event handler based pattern which we often misuse as an observer pattern. ASP.NET AJAX 4.0 implements this pattern completely. It adds observer functionality to ordinary JavaScript objects or arrays so that they raise change notifications when they are modified through the Sys.Observer interface.

Live Binding in Action

To implement live binding, you will need the ASP.NET AJAX 4.0 framework included in your file. After downloading from here, you'll need to reference them to your file. You can use a conventional

see full detail: http://dotnetslackers.com/articles/ajax/Live-Data-Binding-using-ASP-NET-AJAX-4-0-Preview-4.aspx

.NET 4 Revealed

The next-generation .NET Framework 4 and Visual Studio 2010 beta 1 bits reached developers' workstations last month, after a seven-month hiatus. The first -- and in some cases, only -- community technology previews (CTPs) appeared last October at Microsoft's Professional Developers Conference (PDC).
The updated framework promises maturing class libraries and new parallelism capabilities to facilitate the development of components that can take advantage of the intensive I/O capabilities of multi-core systems.


The updated framework promises maturing class libraries and new parallelism capabilities to facilitate the development of components that can take advantage of the intensive I/O capabilities of multi-core systems.

"With 4, I see less new things and more of an extension in terms of beefing up what's there-the Windows Communication Foundation, Windows Presentation Foundation, Workflow services," says Mark Driver, vice president of research at Gartner Inc. "I don't see a whole lot of new APIs but rather the evolution of the APIs that they introduced as part of 3.5."
See full detail: http://adtmag.com/articles/2009/06/02/net-4-revealed.aspx

Speed Up Your Site With AJAX

Want to increase the interactivity, speed and usability of your web pages? AJAX could be the answer. Short for Asynchronous JavaScript and XML, AJAX is a web development technique for creating interactive web applications. In general, it makes web pages feel more responsive by exchanging small amounts of data with a server behind the scenes so an entire web page does not have to be reloaded each time the user makes a change.

The benefits are obvious to Fairytale Brownies in Chandler, Arizona, which recently implemented AJAX to speed up the checkout process on its site. Founded in 1992 by childhood friends Eileen Joy Spitalny and David Kravetz, both 40, Fairytale Brownies is the nation’s leading purveyor of mail-order gourmet brownies, with 2007 sales projections of $8.9 million. When the
company recently redesigned its website to make its brownies look more appealing, it used AJAX to speed up the gift list checkout section.

“This gift
list shows our customers who received gifts from them before,” explains Spitalny. “It’s a very popular feature, but we wanted to make it as quick and easy to use as possible.”
Before AJAX, any change to addresses, ship dates, quantities or gift messages meant waiting for entire
web pages to reload. But AJAX loads pages only once; changes need only small data updates. This translates into a smoother process that benefits not only customers, but also employees, who spend less time on the phone with customers.

Fairytale employed an outside consultant to implement AJAX. Spitalny suggests finding a programmer who is familiar with JavaScripting and XML. She also suggests a visit to
http://ajax.asp.net, a Microsoft site that provides free tutorials and starter kits to help programmers understand the technology.

See full detail: http://news.alibaba.com/article/detail/technology/100109433-1-speed-up-your-site-ajax.html

Tuesday, June 2, 2009

Web Paging Navigation Control

Introduction
this web paging control for navigation in data list.

how to use this control
1-Set Control setting in page load 2-to get page index from this control use PagingControl1_PageIndexClick(object sender, EventArgs e) event

Sample for how to use this control
See full detail:http://www.c-sharpcorner.com/UploadFile/Nesreeen/WebPagingControl05182009155353PM/WebPagingControl.aspx

Using the Backgroundworker with VB.Net 2005

I write a lot of Client side WinForm programs to analyze wireless network test results, from 100MB log files and MySQL databases. I wanted to be able to run some background tasks that can take 10+ minutes to complete.Using Google, I found a few programs that used the Backgroundworker (in .Net 2.0). Although all the examples I found were overly complicated and hard to follow; so I decided to write a very simple program in VB.Net 2005 that showed how to use all the features of the Backgroundworker.
See full detail: http://www.vbdotnetheaven.com/UploadFile/ffortino/Page105242009222549PM/Page1.aspx

Monday, June 1, 2009

Client-side Data Binding in ASP.NET AJAX 4.0

The 4.0 release of ASP.NET AJAX will include a significant number of new features targeted at client-side programming. Earlier releases of ASP.NET AJAX included client-side programming features like web service proxies, global helper functions (like $get and $create), client library additions (like Sys.StringBuilder), and a complete set of extensions to add classes, namespaces, interfaces, and inheritance to the JavaScript language. Most of these features, however, were targeted at supporting the developer in building client-side features by hand, and did not help much with generating client-side HTML or manipulating the DOM. Version 4.0 introduces two major features for simplifying client-side development: client-side data binding and declarative component creation. As we’ll see, the addition of these two features greatly expands the options you have when writing client pages. Additionally, declarative instantiation and templating define a client-side model that is very familiar and therefore easy to use.

As you may be aware, the first release of ASP.NET AJAX had a supplemental futures release that contained an implementation of declarative instantiation and client binding, so we always knew this was coming. However, the earlier implementation was based on XML and required that the user insert a script element marked with the type=’text/xml-script’ attribute below the HTML for the page. While initially very promising, this technique had several drawbacks including its verbosity, its dependence on a client XML parser, and performance issues. Finally in version 4.0, we have a completely new implementation that doesn’t suffer from any of these limitations, and looks to be really useful and easy to use.
This article is based on the preview 4 release of ASP.NET Ajax available for download at
http://www.codeplex.com/aspnet/, and thus the details of some features explained here are subject to change before the final release.

DataView and client templates
We will start with a simple example that demonstrates how to associate an array of items in JavaScript with a client template. The core mechanism for client data binding and templating is a client-side class named Sys.UI.DataView. This class inherits from the Sys.UI.Control class which defines a mechanism for associating with an HTML element in the DOM, and it also defines several properties and methods including the data property which can be initialized with an array of data to bind to a template. The page below uses the DataView class to associate a list of courses and their codes to an HTML table template (note we are manually including the script files for ASP.NET Ajax 4.0 – these will be included through the standard ScriptManager control in the final release).

See full detail: http://www.pluralsight.com/main/whitepapers/ClientDataBindingAjax4.aspx