[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
This afternoon we made available the VS 2010 and .NET 4 release candidates. You can find download links here.
Right now the downloads are available only to MSDN subscribers. Starting Wednesday (Feb 10th) everyone will be able to download them (regardless of whether you are a MSDN subscriber or not).
Background on the Release Candidate
I blogged about us deciding to ship a public VS 2010 release candidate last December. The primary motivation behind releasing a public RC was to ensure that we could get broad testing and feedback on the performance and stability work we’ve been doing since the last public VS 2010 Beta 2 release.
Over the last few months we’ve been releasing interim builds to a small set of folks who have been helping us validate fixes and measure very large projects and solutions. The feedback from them has been extremely positive the last few weeks – which is why we are now opening up today’s build to a much wider set of people to people to try out.
The RC has only been out a few hours so far – but the feedback so far on Twitter has been nice to see:
@DanWahlin: The performance improvements with Visual Studio 2010 RC compared to previous builds are huge. Really happy with what I'm seeing so far.
@peterbromberg: VS2010 RC: I must admit, I am impressed. Major speed and performance improvements. They are obvious immediately!
@Nick_Craver: RC performance is ridiculously faster, can't wait to switch over full time!
@Rlz2cool: Just tried VS2010 RC. One word incredible. Super fast, great build with things I saw in earlier releases fixed. So awesome.
@ddotterer: Trying out VS2010 RC: Snappier UI, much faster intellisense, significant build time reduction, etc. Overall: AWESOME JOB
@tomkirbygreen: Oh my goodness, VS2010 RC is much, much faster. Kudos to the VS perf team and everyone else. Uninstalling Visual Studio 2008 :-)
@JoshODBrown The developers on the Visual Studio 2010 RC must have had their usual beverages replaced with unicorn tears or something. #VS2010#awesome
Our goal with releasing the public RC build today is to get a lot of eyes on the product helping to find and report the remaining bugs we need to fix. If you do find an issue, please submit a bug report via the Visual Studio Connect site and also please send me an email directly (scottgu@microsoft.com) with details about it. I can then route your email to someone to investigate and follow-up directly (which can help expedite the investigation).
If you do install and use the VS 2010 RC we’d also really appreciate if you would fill out this survey about your experiences.
Answers to a few questions and known issues
Here are a few answers to some questions/known issues:
If you have previously installed VS 2010 Beta 2 on your computer you should use Add/Remove Programs (within Windows Control Panel) to remove VS 2010 Beta2 and .NET 4 Beta2 before installing the VS 2010 RC. Note that VS 2010 RC can be installed on the same machine side-by-side with VS 2008 and VS 2005.
Silverlight 3 projects are supported with today’s VS 2010 RC build – however Silverlight 4 projects are not yet supported. We will be adding VS 2010 RC support for SL4 with the next public Silverlight 4 drop. If you are doing active Silverlight 4 development today we recommend staying with the VS10 Beta 2 build for now.
We recently identified a crashing bug that can impact systems that have multi-touch and some screen-readers enabled. We are working on a patch for people who are impacted by it.
We recently found an issue where project upgrades from VS 2008 can take a long time to complete if the project has .xsd files within them. If you think VS is taking a long time on a project upgrade give it a few more minutes to complete before assuming it has hung – you might be running into this slow upgrade issue. Note that once the project is upgraded the performance should return to normal. We are working to fix this with the final release.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
A few people have emailed me recently asking about the availability of a Visual Studio –vsdoc intellisense hint file for jQuery 1.4.1.
I blogged about –vsdoc files in the past – they provide additional intellisense help information for Visual Studio, and enable you to get a richer intellisense experience with dynamic Javascript libraries. If you are using VS 2008 SP1 you’ll want to download and install this patch in order to have VS 2008 automatically use –vsdoc files with intellisense. VS 2010 has support for –vsdoc files built-in.
jQuery 1.4.1 –vsdoc download
The good news is that you can download –vsdoc files for jQuery directly from the jQuery web-site (look for the “Documentation: Visual Studio” link under each major version). Here is a direct pointer to the recently released –vsdoc file for jQuery 1.4.1 that you can use.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
This is the fifteenth in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release. Today’s post covers a nice addition to ASP.NET and Windows Forms with .NET 4 - built-in charting control support.
You can download and use these runtime controls for free within your web and client applications today. You can also download VS 2008 tooling support for them. They provide a rich set of charting capabilities that is easy to use. To get a sense of what all you can do with them, I recommend downloading the ASP.NET and Windows Forms sample projects which provide more than 200 samples within them. Below is a screen-shot of some pie and doughnut chart samples from the ASP.NET sample application:
Charting Controls Now Built-into .NET 4
With .NET 3.5 you had to separately download the chart controls and add them into your application. With .NET 4 these controls are now built-into ASP.NET 4 and Windows Forms 4 – which means you can immediately take advantage of them out of the box (no separate download or registration required).
Within ASP.NET 4 applications you’ll find that there is now a new built-in <asp:chart> control within the “Data” tab of the Toolbox:
You can use this control without having to register or wire-up any configuration file entries. All of the charting control configuration is now pre-registered with ASP.NET 4 (meaning nothing has to be added to an application’s web.config file for them to work). This enables you to maintain very clean and minimal Web.config files.
Learning more about the <asp:chart> control
Scott Mitchell has written a great series of articles on the www.4guysfromrolla.com site on how to take advantage of the <asp:chart> control:
Getting Started - walks through getting started using the Chart Controls, from version requirements to downloading and installing the Chart Controls, to displaying a simple chart in an ASP.NET page.
Plotting Chart Data - examines the multitude of ways by which data can be plotted on a chart, from databinding to manually adding the points one at a time.
Rendering the Chart - the Chart Controls offer a variety of ways to render the chart data into an image. This article explores these options.
Sorting and Filtering Chart Data - this article shows how to programmatically sort and filter the chart's data prior to display.
His articles are written using .NET 3.5 and the separate ASP.NET charting controls download – but all of the concepts and syntax work out of the box exactly the same with ASP.NET 4.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
Earlier this evening the ASP.NET team shipped ASP.NET MVC (Release Candidate 2) for VS 2008/.NET 3.5. You can download it here.
The RC2 release of ASP.NET MVC 2 is a follow-up to the first ASP.NET MVC 2 RC build that we shipped in December. It includes a bunch of bug fixes, performance work, and some final API and behavior additions/changes. Below are a few of the changes between the RC1 and RC2 release (read the release notes for even more details):
The new ASP.NET MVC 2 validation feature now performs model-validation instead of input-validation (this means that when you use model binding all model properties are validated instead of just validations on changed values of a model). This behavior change was based on extensive feedback from the community.
The new strongly-typed HTML input helpers now support lambda expressions which reference array or collection indexes. This means you can now write code like Html.EditorFor(m=>m.Orders[i]) and have it correctly output an HTML <input> element whose “name” attribute contains the index (e.g. Orders[0] for the first element), and whose “value” contains the appropriate value.
The new templated Html.EditorFor() and Html.DisplayFor() helper methods now auto-scaffold simple properties (and do not render complex sub-properties by default). This makes it easier to generate automatic scaffolded forms. I’ll be covering this support in a future blog post.
The “id” attribute of client-script validation message elements is now cleaner. With RC1 they had a form0_ prefix. Now the id value is simply the input form element name postfixed with a validationMessage string (e.g. unitPrice_validationMessage).
The Html.ValidationSummary() helper method now takes an optional boolean parameter which enables you to control whether only model-level validation messages are rendered by it, or whether property level validation messages are rendered as well. This provides you with more UI customization options for how validation messages are displayed within your UI.
The AccountController class created with the default ASP.NET MVC Web Application project template is cleaner.
Visual Studio now includes scaffolding support for Delete action methods within Controllers, as well as Delete views (I always found it odd that the default T4 templates didn’t support this before).
jQuery 1.4.1 is now included by default with new ASP.NET MVC 2 projects, along with a –vsdoc file that provides Visual Studio documentation intellisense for it.
The RC2 release has some significant performance tuning improvements (for example: the lambda based strongly-typed HTML helpers are now much faster).
Today’s RC2 release only work with VS 2008 and .NET 3.5. We’ll shortly be releasing the VS 2010 RC (which will be available for everyone to download). It will include ASP. NET MVC 2 support built-in (no separate download required).
Hope this helps,
Scott
P.S. The source code for the ASP.NET MVC RC2 release (along with a MVC futures library that goes with it) can be downloaded here. You can learn even more about ASP.NET MVC 2 by reading the ASP.NET MVC 2 blog series I’m working on.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
I’ve been working on a series of blog posts the last few months that cover some of the new features coming with .NET 4 and VS 2010.
Earlier today someone pointed me at some nice “quick hit” videos that have been published that also provide quick first looks at some of the new features coming with ASP.NET 4 and VS 2010. These videos aren’t an exhaustive list of everything new – but do provide a great way to quickly learn about many of the cool new things coming with the release.
You can learn more about a few of the new VS 2010 features by watching these 8 VS 2010 Quick Hit Videos.
ASP.NET Team Member Interviews
In addition to the feature demo videos above, you can also watch these ASP.NET team member interviews done by Scott Hanselman. In them various ASP.NET team members talk about a few of the new features they’ve worked on.
There are a lot more features coming with .NET 4 and VS 2010 not covered by all of these videos. But hopefully the above clips provide a good way to quickly get a sense of some of the new capabilities.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
This is the fourteenth in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release. Today’s post covers some of the output caching extensibility improvements being made to ASP.NET 4. These can be used by all ASP.NET 4 applications – including those built using both ASP.NET Web Forms and ASP.NET MVC.
Output Caching Today
ASP.NET 1.0 introduced the concept of output caching, which enables developers to capture and store the generated output of pages, controls, controllers, and HTTP responses in an in-memory cache. On subsequent web requests, ASP.NET can then serve content faster by retrieving and using the generated output from the cache instead of having to execute the page/controller to regenerate the output from scratch. This can dramatically improve the performance of your application – especially in cases where your content is based on data within a database (since when the content is output cached you end up not having to hit the database on subsequent requests).
ASP.NET’s output caching system is flexible enough to enable you to cache different versions of content depending on the querystring/form-post parameters to a page/controller (for example: Browse.aspx?category=Beverages versus. Browse.aspx?category=Meat). It also enables you to cache different versions based on the browser type or user-language preference of the client visiting your application. This allows you to cache a mobile version of a page separate from a version optimized for a desktop browser, as well as to vary the cache entries based on whether the user wants to read a page in English or French. You can configure ASP.NET to cache a particular output cache entry for a specific period of time (for example: 1 minute – after which the next request will regenerate the content and cache it again). You can also configure ASP.NET to dynamically invalidate a cache entry based on an external event (for example: if the database upon which the cached content depends changes).
One limitation of output caching with ASP.NET V1->V3.5, though, is that the cache store itself is not extensible – and the cached content always has to be stored in-memory.
ASP.NET 4 Output Cache Extensibility
ASP.NET 4 adds an extensibility point to output caching that now enables developers to configure one or more custom output-cache providers. Output-cache providers can use any storage mechanism to persist output cached content. This makes it possible to easily create output-cache providers that store the cached content using any persistence mechanism – including local or remote disks, databases, cloud storage, and distributed cache engines (like memcached or velocity).
You can create a custom output-cache provider by creating a class that derives from the new System.Web.Caching.OutputCacheProvider class in ASP.NET 4. Within your derived class you then override 4 public methods that provide implementations for adding/removing/retrieving/updating cached content (a unique key is passed to identify each separate cached entry). You can then configure ASP.NET 4 to use your custom outputcache provider by registering it using the new <providers> subsection of the <outputCache> element within an application’s web.config file:
Above I’ve added a new output cache provider (which I’ve named “SampleCache”) that is implemented using the “ScottOutputCache” class within my OutputCacheSample.dll assembly. I’ve also configured ASP.NET to use my “SampleCache” implementation as the default output cache implementation whenever content is output cached – this is done by setting the “defaultProvider” attribute on the <outputCache> element.
And now, when I add an OutputCache directive to the top of any of .aspx page the content will be cached and stored using my ScottOutputCache provider:
Likewise, if I add an [OutputCache] attribute on any action method within an ASP.NET MVC Controller the content will also be cached and stored using my ScottOutputCache provider:
Customizing Which Output Cache Provider is Used
Above I configured ASP.NET to by default always cache content using my “SampleCache” provider whenever output caching is used within the application.
As a slightly more advanced option, developers can also configure ASP.NET to dynamically choose which output cache provider to use on a per-request basis. This is useful for scenarios where you want to have a slightly richer set of cache semantics. For example, you might want to cache the “Home” page or "Top 10" requested pages of a site using the built-in ASP.NET in-memory provider (which will be super fast because the content will be in-memory), and then cache less frequently requested pages that get lower traffic on disk.
You can dynamically indicate which output cache provider to use on a per-request basis by overriding the GetOutputCacheProviderName() method within the Global.asax file of an application. Below I’m indicating that for the “Home.aspx” page within my application I want to use the built-in in-memory ASP.NET output cache provider – and that I then want to use whatever is registered within the web.config file for every other request:
This ability to easily switch between providers depending on scenarios ends up enabling a bunch of really powerful scenarios.
Common Output Cache Providers
We’ll be shipping samples that demonstrate how to implement a disk-based output cache provider that stores cached content on the file-system. We’ll also be shipping samples that demonstrate how to integrate output caching with the new Windows Server AppFabric Caching Service (formerly known as “Velocity”). AppFabric’s caching service will be a free, fully supported, Microsoft distributed cache system. It will also be easy to use the new ASP.NET 4 output caching extensibility with memcached – a popular open source distributed caching system.
The addition of output-cache provider extensibility to ASP.NET 4 enables developers to easily pursue more aggressive and more intelligent output-caching strategies for web sites and applications. These can significantly improve the performance and responsiveness of applications, and improve both end-user experiences as well as reduce the amount of server resources required.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
Technical debates are discussed endlessly within the blog-o-sphere/twitter-verse, and they range across every developer community. Each language, framework, tool, and platform inevitably has at least a few going on at any particular point in time.
Below are a few observations I’ve made over the years about technical debates in general, as well as some comments about some of the recent discussions I’ve seen recently about the topic of ASP.NET Web Forms and ASP.NET MVC in particular.
General Observations About Technical Debates
Below are a few general observations independent of any specific technical debate:
a) Developers love to passionately debate and compare languages, frameworks, APIs, and tools. This is true in every programming community (.NET, Java, PHP, C++, Ruby, Python, etc). I think you can view these types of religious technical debates in two ways:
They are sometimes annoying and often a waste of time.
They are often a sign of a healthy and active community (since passion means people care deeply on both sides of a debate, and is far better than apathy).
Personally I think both points are true.
b) There is never only “one right way” to develop something. As an opening interview question I sometimes ask people to sort an array of numbers in the most efficient way they can. Most people don’t do well with it. This is usually not because they don’t know sort algorithms, but rather because they never think to ask the scenarios and requirements behind it – which is critical to understanding the most efficient way to do it. How big is the sequence of numbers? How random is the typical number sequence (is it sometimes already mostly sorted, how big is the spread of numbers, are the numbers all unique, do duplicates cluster together)? How parallel is the computer architecture? Can you allocate memory as part of the sort or must it be constant? Etc. These are important questions to ask because the most efficient and optimal way to sort an array of numbers depends on understanding the answers.
Whenever people assert that there is only “one right way” to a programming problem they are almost always assuming a fixed set of requirements/scenarios/inputs – which is rarely optimal for every scenario or every developer. And to state the obvious - most problems in programming are far more complex than sorting an array of numbers.
c) Great developers using bad tools/frameworks can make great apps. Bad developers using great tools/frameworks can make bad apps. Be very careful about making broad assumptions (good or bad) about the quality of the app you are building based on the tools/frameworks used.
d) Developers (good and bad) can grow stronger by stretching themselves and learning new ideas and approaches. Even if they ultimately don’t use something new directly, the act of learning it can sharpen them in positive ways.
e) Change is constant in the technology industry. Change can be scary. Whether you get overwhelmed by change, though, ultimately comes down to whether you let yourself be overwhelmed. Don’t stress about having to stop and suddenly learn a bunch of new things - rarely do you have to. The best approach to avoid being overwhelmed is to be pragmatic, stay reasonably informed about a broad set of things at a high-level (not just technologies and tools but also methodologies), and have the confidence to know that if it is important to learn a new technology, then your existing development skills will mostly transition and help. Syntax and APIs are rarely the most important thing anyway when it comes to development – problem solving, customer empathy/engagement, and the ability to stay focused and disciplined on a project are much more valuable.
f) Some guidance I occasionally give people on my team when working and communicating with others:
You will rarely win a debate with someone by telling them that they are stupid - no matter how well intentioned or eloquent your explanation of their IQ problems might be.
There will always be someone somewhere in the world who is smarter than you - don’t always assume that they aren’t in the room with you.
People you interact with too often forget the praise you give them, and too often remember a past insult - so be judicious in handing them out as they come back to haunt you later.
People can and do change their minds - be open to being persuaded in a debate, and neither gloat nor hold it against someone else if they also change their minds.
g) I always find it somewhat ironic when I hear people complain about programming abstractions not being good. Especially when these complaints are published via blogs – whose content is displayed using HTML, is styled with CSS, made interactive with JavaScript, transported over the wire using HTTP, and implemented on the server with apps written in higher-level languages, using object oriented garbage collected frameworks, running on top of either interpreted or JIT-compiled byte code runtimes, and which ultimately store the blog content and comments in relational databases ultimately accessed via SQL query strings. All of this running within a VM on a hosted server – with the OS within the VM partitioning memory across kernel and user mode process boundaries, scheduling work using threads, raising device events using signals, and using an abstract storage API fo disk persistence. It is worth keeping all of that in mind the next time you are reading a “ORM vs Stored Procedures” or “server controls – good/bad?” post. The more interesting debates are about what the best abstractions are for a particular problem.
h) The history of programming debates is one long infinite loop – with most programming ideas having been solved multiple times before. And for what it’s worth – many of the problems we debate today were long ago solved with LISP and Smalltalk. Ironically, despite pioneering a number of things quite elegantly, these two languages tend not be used much anymore. Go figure.
Some Comments Specific to ASP.NET Web Forms / ASP.NET MVC debates:
Below are a few comments specific to some of the recent debates that I’ve seen going around within the community as to whether a ASP.NET Web Forms or ASP.NET MVC based approach is best:
a) Web Forms and MVC are two approaches for building ASP.NET apps. They are both good choices. Each can be the “best choice” for a particular solution depending on the requirements of the application and the background of the team members involved. You can build great apps with either. You can build bad apps with either. You are not a good or bad developer depending on what you choose. You can be absolutely great or worthless using both.
b) The ASP.NET and Visual Studio teams are investing heavily in both Web Forms and MVC. Neither is going away. Both have major releases coming in the months ahead. ASP.NET 4 includes major updates to Web Forms (clean ClientIDs and CSS based markup output, smaller ViewState, URL Routing, new data and charting controls, new dynamic data features, new SEO APIs, new VS designer and project improvements, etc, etc). ASP.NET 4 will also ship with ASP.NET MVC 2 which also includes major updates (strongly typed helpers, model validation, areas, better scaffolding, Async support, more helper APIs, etc, etc). Don’t angst about either being a dead-end or something you have to change to. I suspect that long after we are all dead and gone there will be servers somewhere on the Internet still running both ASP.NET Web Forms and ASP.NET MVC based apps.
c) Web Forms and MVC share far more code/infrastructure/APIs than anyone on either side of any debate about them ever mentions - Authentication, Authorization, Membership, Roles, URL Routing, Caching, Session State, Profiles, Configuration, Compilation, .aspx pages, .master files, .ascx files, Global.asax, Request/Response/Cookie APIs, Health Monitoring, Process Model, Tracing, Deployment, AJAX, etc, etc, etc. All of that common stuff you learn is equally valid regardless of how you construct your UI. Going forward we’ll continue to invest heavily in building core ASP.NET features that work for both Web Forms and MVC (like the URL Routing, Deployment, Output Caching, and DataAnnotations for Validation features we are adding with ASP.NET 4).
d) I often find debates around programming model appropriateness and abstractions a little silly. Both Web Forms and MVC are programming web framework abstractions, built on top of a broader framework abstraction, programmed with higher level programming languages, running on top of a execution engine abstraction that itself is running on top of a giant abstraction called an OS. What you are creating with each is HTML/CSS/JavaScript (all abstractions persisted as text, transmitted over HTTP – another higher level protocol abstraction).
The interesting question to debate is not whether abstractions are good or not – but rather which abstractions feels most natural to you, and which map best to the requirements/scenarios/developers of your project.
e) We are about to do a pretty major update to the www.asp.net site. As part of that we will be posting more end to end tutorials/content (for both Web Forms and MVC). We will also be providing tutorials and guidance that will help developers quickly evaluate both the Web Forms and MVC approach, easily learn the basics about how both work, and quickly determine which one feels best for them to use. This will make it easy for developers new to ASP.NET, as well as developers who already know either Web Forms or MVC, to understand and evaluate the two approaches and decide which they want to use.
f) Decide on a project about whether you want to use Web Forms or MVC and feel good about it. Both can be good choices. Respect the choices other people make – the choice they have made is also hopefully a good one that works well for them. Keep in mind that in all likelihood they know a lot more about their own business/skills than you do. Likewise you hopefully know a lot more about your own business/skills than they do.
g) Share ideas and best practices with others. That is a big part of what blogs, forums, listservs and community is all about. What makes them work great is when people know that their ideas aren’t going to be ripped to shreds, and that they will be treated with respect. Be constructive, not snarky. Teach, don’t lecture. Remember there is always someone else out there who you can also learn from.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
This is the second in a series of blog posts I’m doing on the upcoming ASP.NET MVC 2 release. This blog post covers some of the validation improvements coming with ASP.NET MVC 2.
ASP.NET MVC 2 Validation
Validating user-input and enforcing business rules/logic is a core requirement of most web applications. ASP.NET MVC 2 includes a bunch of new features that make validating user input and enforcing validation logic on models/viewmodels significantly easier. These features are designed so that the validation logic is always enforced on the server, and can optionally also be enforced on the client via JavaScript. The validation infrastructure and features in ASP.NET MVC 2 are designed so that:
1) Developers can easily take advantage of the DataAnnotation validation support built-into the .NET Framework. DataAnnotations provide a really easy way to declaratively add validation rules to objects and properties with minimal code.
2) Developers can optionally integrate either their own validation engine, or take advantage of existing validation frameworks like Castle Validator or the EntLib Validation Library. ASP.NET MVC 2’s validation features are designed to make it easy to plug-in any type of validation architecture – while still taking advantage of the new ASP.NET MVC 2 validation infrastructure (including client-side validation, model binding validation, etc).
This means that enabling validation is really easy for common application scenarios, while at the same time still remaining very flexible for more advanced ones.
Enabling Validation with ASP.NET MVC 2 and DataAnnotations
Let’s walkthrough a simple CRUD scenario with ASP.NET MVC 2 that takes advantage of the new built-in DataAnnotation validation support. Specifically, let’s implement a “Create” form that enables a user to enter friend data:
We want to ensure that the information entered is valid before saving it in a database – and display appropriate error messages if it isn’t:
We want to enable this validation to occur on both the server and on the client (via JavaScript). We also want to ensure that our code maintains the DRY principle (“don’t repeat yourself”) – meaning that we should only apply the validation rules in one place, and then have all our controllers, actions and views honor it.
Below I’m going to be using VS 2010 to implement the above scenario using ASP.NET MVC 2. You could also implement the exact same scenario using VS 2008 and ASP.NET MVC 2 as well.
Step 1: Implementing a FriendsController (with no validation to begin with)
We’ll begin by adding a simple “Person” class to a new ASP.NET MVC 2 project that looks like below:
It has four properties (implemented using C#’s automatic property support, which VB in VS 2010 now supports too – woot!).
We’ll then add a “FriendsController” controller class to our project that exposes two “Create” action methods. The first action method is called when an HTTP-GET request comes for the /Friends/Create URL. It will display a blank form for entering person data. The second action method is called when an HTTP-POST request comes for the /Friends/Create URL. It maps the posted form input to a Person object, verifies that no binding errors occurred, and if it is valid will eventually save it to a database (we’ll implement the DB work later in this tutorial). If the posted form input is invalid, the action method redisplays the form with errors:
After we’ve implemented our controller, we can right-click within one of its action methods and choose the “Add View” command within Visual Studio – which will bring up the “Add View” dialog. We’ll choose to scaffold a “Create” view that is passed a Person object:
Visual Studio will then generate a scaffolded Create.aspx view file for us under the \Views\Friends\ directory of our project. Notice below how it takes advantage of the new strongly-typed HTML helpers in ASP.NET MVC 2 (enabling better intellisense and compile time checking support):
And now when we run the application and hit the /Friends/Create URL we’ll get a blank form that we can enter data into:
Because we have not implemented any validation within the application, though, nothing prevents us from entering bogus input within the form and posting it to the server.
Step 2: Enabling Validation using DataAnnotations
Let’s now update our application to enforce some basic input validation rules. We’ll implement these rules on our Person model object – and not within our Controller or our View. The benefit of implementing the rules within our Person object is that this will ensure that the validation will be enforced via any scenario within our application that uses the Person object (for example: if we later added an edit scenario). This will help ensure that we keep our code DRY and avoid repeating rules in multiple places.
ASP.NET MVC 2 enables developers to easily add declarative validation attributes to model or viewmodel classes, and then have those validation rules automatically be enforced whenever ASP.NET MVC performs model binding operations within an application. To see this in action, let’s update our Person class to have a few validation attributes on it. To do this we’ll add a “using” statement for the “System.ComponentModel.DataAnnotations” namespace to the top of the file – and then decorate the Person properties with [Required], [StringLength], [Range], and [RegularExpression] validation attributes (which are all implemented within that namespace):
Note: Above we are explicitly specifying error messages as strings. Alternatively you can define them within resource files and optionally localize them depending on the language/culture of the incoming user. You can learn more about how to localize validation error messages here.
Now that we’ve added the validation attributes to our Person class, let’s re-run our application and see what happens when we enter bogus values and post them back to the server:
Notice above how our application now has a decent error experience. The text elements with the invalid input are highlighted in red, and the validation error messages we specified are displayed to the end user about them. The form is also preserving the input data the user originally entered – so that they don't have to refill anything. How though, you might ask, did this happen?
To understand this behavior, let’s look at the Create action method that handles the POST scenario for our form:
When our HTML form is posted back to the server, the above method will be called. Because the action method accepts a “Person” object as a parameter, ASP.NET MVC will create a Person object and automatically map the incoming form input values to it. As part of this process, it will also check to see whether the DataAnnotation validation attributes for the Person object are valid. If everything is valid, then the ModelState.IsValid check within our code will return true – in which case we will (eventually) save the Person to a database and then redirect back to the home-page.
If there are any validation errors on the Person object, though, our action method redisplays the form with the invalid Person. This is done via the last line of code in the code snippet above.
The error messages are then displayed within our view because our Create form has <%= Html.ValidationMessageFor() %> helper method calls next to each <%= Html.TextBoxFor() %> helper. The Html.ValidationMessageFor() helper will output the appropriate error message for any invalid model property passed to the view:
The nice thing about this pattern/approach is that it is pretty easy to setup – and it then allows us to easily add or change validation rules on our Person class without having to change any code within our controllers or views. This ability to specify the validation rules one place and have it be honored and respected everywhere allows us to rapidly evolve our application and rules with a minimum amount of effort and keep our code very DRY.
Step 3: Enabling Client-side Validation
Our application currently only performs server-side validation – which means that our end users will need to perform a form submit to the server before they’ll see any validation error messages.
One of the cool things about ASP.NET MVC 2’s validation architecture is that it supports both server-side and client-side validation. To enable this, all we need to do is to add two JavaScript references to our view, and write one line of code:
When we add these three lines, ASP.NET MVC 2 will use the validation meta-data we’ve added to our Person class and wire-up client-side JavaScript validation logic for us. This means that users will get immediate validation errors when they tab out of an input element that is invalid.
To see the client-side JavaScript support in action for our friends application, let’s rerun the application and fill in the first three textboxes with legal values – and then try and click “Create”. Notice how we’ll get an immediate error message for our missing value without having to hit the server:
If we enter some text that is not a legal email the error message will immediately change from “Email Required” to “Not a valid email” (which are the error messages we specified when we added the rules to our Person class):
When we enter a legal email the error message will immediately disappear and the textbox background color will go back to its normal state:
The nice thing is that we did not have to write any custom JavaScript of our own to enable the above validation logic. Our validation code is also still very DRY- we can specify the rules in one place and have them be enforced across all across the application – and on both the client and server.
Note that for security reasons the server-side validation rules always execute even if you have the client-side support enabled. This prevents hackers from trying to spoof your server and circumvent the client-side rules.
The client-side JavaScript validation support in ASP.NET MVC 2 can work with any validation framework/engine you use with ASP.NET MVC. It does not require that you use the DataAnnotation validation approach – all of the infrastructure works independent of DataAnnotations and can work with Castle Validator, the EntLib Validation Block, or any custom validation solution you choose to use.
If you don’t want to use our client-side JavaScript files, you can also substitute in the jQuery validation plugin and use that library instead. The ASP.NET MVC Futures download will include support for enable jQuery validation against the ASP.NET MVC 2 server-side validation framework as well.
Step 4: Creating a Custom [Email] Validation Attribute
The System.ComponentModel.DataAnnotations namespace within the .NET Framework includes a number of built-in validation attributes that you can use. We’ve used 4 different ones in the sample above - [Required], [StringLength], [Range], and [RegularExpression].
You can also optionally define your own custom validation attributes and use them as well. You can define completely custom attributes by deriving from the ValidationAttribute base class within the System.ComponentModel.DataAnnotations namespace. Alternatively, you can choose to derive from any of the existing validation attributes if you want to simply extend their base functionality.
For example, to help clean up the code within our Person class we might want to create a new [Email] validation attribute that encapsulates the regular expression to check for valid emails. To do this we can simply derive it from the RegularExpression base class like so, and call the RegularExpression’s base constructor with the appropriate email regex:
We can then update our Person class to use our new [Email] validation attribute in place of the previous regular expression we used before – which makes the code more clean and encapsulated:
When creating custom validation attributes you can specify validation logic that runs both on the server and on the client via JavaScript.
In addition to creating validation attributes that apply to individual properties on an object, you can also apply validation attributes at the class level – which allows you to perform validation logic across multiple properties within an object. For an example of this in action, you can review the “PropertiesMustMatchAttribute” custom attribute that is included in the AccountModels.cs/vb file within the default ASP.NET MVC 2 application project template (just do a File->New ASP.NET MVC 2 Web Project within VS 2010 and look for this class).
Step 5: Persisting to a Database
Let’s now implement the logic necessary to save our friends to a database.
Right now we are simply working against a plain-old C# class (sometimes referred to as a “POCO” class - “plain old CLR (or C#) object”). One approach we could use would be to write some separate persistence code that maps this existing class we’ve already written to a database. Object relational mapping (ORM) solutions like NHibernate support this POCO / PI style of mapping today very well. The ADO.NET Entity Framework (EF) that ships with .NET 4 will also support POCO / PI mapping, and like NHibernate will also optionally enable the ability to define persistence mappings in a “code only” way (no mapping file or designers required).
If our Person object was mapped to a database in this way then we wouldn’t need to make any changes to our Person class or to any of our validation rules – it would continue to work just fine.
But what if we are using a graphical tool for our ORM mappings?
Many developers using Visual Studio today don’t write their own ORM mapping/persistence logic – and instead use the built-in designers within Visual Studio to help manage this.
One question that often comes up when using DataAnnotations (or any other form of attribute based validation) is “how do you apply them when the model object you are working with is created/maintained by a GUI designer”. For example, what if instead of having a POCO style Person class like we’ve been using so far, we instead defined/maintained our Person class within Visual Studio via a GUI mapping tool like the LINQ to SQL or ADO.NET EF designer:
Above is a screen-shot that shows a Person class defined using the ADO.NET EF designer in VS 2010. The window at the top defines the Person class, the window at the bottom shows the mapping editor for how its properties map to/from a “People” table within a database. When you click save on the designer it automatically generates a Person class for you within your project. This is great, except that every time you make a change and hit save it will re-generate the Person class – which would cause any validation attribute declarations you make on it to be lost.
One way you can apply additional attribute-based meta-data (like validation attributes) to a class that is auto-generated/maintained by a VS designer is to employ a technique we call “buddy classes”. Basically you create a separate class that contains your validation attributes and meta-data, and then link it to the class generated by the designer by applying a “MetadataType” attribute to a partial class that is compiled with the tool-generated class. For example, if we wanted to apply the validation rules we used earlier to a Person class maintained by a LINQ to SQL or ADO.NET EF designer we could update our validation code to instead live in a separate “Person_Validation” class that is linked to the “Person” class created by VS using the code below:
The above approach is not as elegant as a pure POCO approach – but has the benefit of working with pretty much any tool or designer-generated code within Visual Studio.
Last Step – Saving the Friend to the Database
Our last step – regardless of whether we use a POCO or tool-generated Person class – will be to save our valid friends into the database.
Doing that simply requires us to replace the “Todo” placeholder statement within our FriendsController class with 3 lines of code that saves the new friend to a database. Below is the complete code for the entire FriendsController class - when using ADO.NET EF to do the database persistence for us:
And now when we visit the /Friends/Create URL we can easily add new People to our friends database:
Validation for all the data is enforced on both the client and server. We can easily add/modify/delete validation rules in one place, and have those rules be enforced by all controllers and views across our application.
Summary
ASP.NET MVC 2 makes it much easier to integrate validation into web applications. It promotes a model-based validation approach that enables you to keep your applications very DRY, and helps ensure that validation rules are enforced consistently throughout an application. The built-in DataAnnotations support within ASP.NET MVC 2 makes supporting common validation scenarios really easy out of the box. The extensibility support within the ASP.NET MVC 2 validation infrastructure then enables you to support a wide variety of more advanced validation scenarios – and plugin any existing or custom validation framework/engine.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
This is the first in a series of blog posts I’m doing on the upcoming ASP.NET MVC 2 release. This blog post covers the new strongly-typed HTML helpers added with ASP.NET MVC 2.
Existing HTML Helper Methods
ASP.NET MVC 1 shipped with a set of HTML helper methods that can be used within view templates to help with the generation of HTML UI. For example, to output a textbox you could write code (within your .aspx view template) using the Html.TextBox() helper method below:
The first parameter to the helper method above supplies the name/id for the textbox, and the second parameter specifies the value it should have. The helper method above would then render HTML like below back to a browser:
New Strongly-Typed HTML Helper Methods
One of the common feature asks people had for ASP.NET MVC 2 was for us to also support strongly-typed HTML helpers that use lambda expressions when referencing models/viewmodels passed to a view template. This enables better compile-time checking of views (so that bugs can be found at build-time as opposed to runtime), and also enables better code intellisense support within view templates.
New strongly-typed HTML helper methods are now built-into ASP.NET MVC 2. These methods use a "Html.HelperNameFor()” naming convention. For example: Html.TextBoxFor(), Html.CheckBoxFor(), Html.TextAreaFor(), etc. They support using a lambda expression to specify both the name/id of the element, as well as the value to render for it.
For example, using ASP.NET MVC 2 we can now use the new Html.TextBoxFor() helper in addition to the Html.TextBox() helper above:
Notice above how we do not need to specify the “ProductName” string parameter anymore – lambda expressions are flexible enough that we can retrieve both the name of the property/field on our model object in addition to its value.
Because the HTML helpers are strongly-typed, we also get full intellisense support for them within Visual Studio when writing the lambda expression:
The HTML rendered is the same as the late-bound version of our HTML helper shown previously:
List of Strongly-Typed HTML Helper Methods built-into ASP.NET MVC 2
ASP.NET MVC 2 has built-in support for the following strongly-typed HTML helpers:
HTML Element Helpers:
Html.TextBoxFor()
Html.TextAreaFor()
Html.DropDownListFor()
Html.CheckboxFor()
Html.RadioButtonFor()
Html.ListBoxFor()
Html.PasswordFor()
Html.HiddenFor()
Html.LabelFor()
Other Helpers:
Html.EditorFor()
Html.DisplayFor()
Html.DisplayTextFor()
Html.ValidationMessageFor()
I’ll be covering the new Html.EditorFor() and Html.DisplayFor() helper methods in a later blog post in this series when I cover the improved auto-scaffold functionality in ASP.NET MVC 2. We’ll also be using the Html.ValidationMessageFor() helper in my next blog post in this series which covers the improved validation support within ASP.NET MVC 2.
Strongly-Typed HTML Helpers within Scaffolding
VS 2008 and VS 2010 both by default now use the new strongly-typed HTML helpers when “scaffolding” new strongly-typed view tempates using the “Add View” command.
For example, let’s assume we had a simple “ProductsController” class like below that has an “Edit” action method that renders an edit form for a “Product” model class:
We can right-click within the Edit action method using Visual Studio and choose the “Add View” context menu command to create a view template. We’ll choose to create an “Edit” template that is scaffolded using a Product object:
With ASP.NET MVC 2, the view template that is created by default now uses the new strongly typed HTML helper methods to reference the Product model object:
Summary
The strongly-typed HTML helpers included with ASP.NET MVC 2 provide a nice way to get better type-safety within your view templates. This enables better compile-time checking of your views (allowing you to find errors at build-time instead of at runtime), and also supports richer intellisense when editing your view templates within Visual Studio.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
Over the last six months the ASP.NET team has been steadily releasing preview, then beta, and now release candidate builds of ASP.NET MVC 2.
Given that the final release is not too far away, I thought it was a good time to start a new multi-part ASP.NET MVC 2 blog series that discusses the new features and how best to take advantage of them.
ASP.NET MVC 2
We shipped ASP.NET MVC 1.0 last March. Since then, almost 1 million developers have downloaded and used the final release, and its popularity has steadily grown month over month.
ASP.NET MVC 2 is the next significant update of ASP.NET MVC. It is a compatible update to ASP.NET MVC 1 – so all the knowledge, skills, code, and extensions you already have with ASP.NET MVC continue to work and apply going forward. Like the first release, we are also shipping the source code for ASP.NET MVC 2 under an OSI-compliant open-source license.
ASP.NET MVC 2 Features
ASP.NET MVC 2 adds a bunch of new capabilities and features. I’ll cover them in a lot more depth with this blog series. Some of them include:
Auto-Scaffold UI Helpers with Template Customization (post coming soon)
Support for partitioning large applications into “Areas” (post coming soon)
Asynchronous Controllers support (post coming soon)
Support for rendering sub-sections of a page/site using Html.RenderAction (post coming soon)
Lots of new helper functions, utilities, and API enhancements (post coming soon)
Improved Visual Studio tooling support (post coming soon)
How to download ASP.NET MVC 2
ASP.NET MVC 2 is designed to work with both VS 2008 / .NET 3.5, as well as with VS 2010 / .NET 4. Supporting both versions means that you can start using it today without having to wait to upgrade to VS2010 / .NET 4.
Click here to download the ASP.NET MVC 2 release candidate for .NET 3.5 and VS 2008. It can be installed side-by-side with ASP.NET MVC 1.0 on the same machine.
ASP.NET MVC 2 is a built-in component of VS 2010 / .NET 4 – which means you will not have to download or install anything to get it once you install any version of Visual Studio 2010. The current public VS 2010 Beta 2 release includes the ASP.NET MVC 2 Preview 2 release. The upcoming VS 2010 Release Candidate that will be available for download next month will have a more recent ASP.NET MVC 2 RC built-in.
ASP.NET Web Forms + ASP.NET MVC
We are always careful to make clear that ASP.NET MVC is an option with ASP.NET. ASP.NET Web Forms continues to be the most widely used approach when building applications with ASP.NET, and the new ASP.NET 4 release contains significant improvements for ASP.NET Web Forms development (clean client IDs and CSS based control markup, better viewstate management, new data and charting controls, URL routing, SEO improvements, and much more). You can learn more about these improvements within my ongoing VS 2010 and .NET 4 blog series.
We’ll be improving and enhancing both the ASP.NET Web Forms and ASP.NET MVC programming models even further in future releases. Developers can and should choose to use whichever model feels most comfortable and natural to them. We’ll be publishing new videos and guidance on the www.asp.net shortly that helps provide additional guidance about each and how to pick the one that feels most comfortable to you.
[In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]
This is the thirteenth in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release. Today’s post covers some of the improvements being made around Search Engine Optimization (SEO) with ASP.NET 4.
Why SEO?
Search engine optimization (SEO) is important for any publically facing web-site. A large percentage of traffic to sites now comes from search engines, and improving the search relevancy of your site will lead to more user traffic to your site from search engine queries (which can directly or indirectly increase the revenue you make through your site).
Measuring the SEO of your website with the SEO Toolkit
Last month I blogged about the free SEO Toolkit we’ve shipped that you can use to analyze your site for SEO correctness, and which provides detailed suggestions on any SEO issues it finds.
I highly recommend downloading and using the tool against any public site you work on. It makes it easy to spot SEO issues you might have in the site, and pinpoint ways to optimize it further.
ASP.NET 4 SEO Improvements
ASP.NET 4 includes a bunch of new runtime features that can help you to further optimize your site for SEO. Some of these new features include:
New Page.MetaKeywords and Page.MetaDescription properties
New URL Routing support for ASP.NET Web Forms
New Response.RedirectPermanent() method
Below are details about how you can take advantage of them to further improve your search engine relevancy.
Page.MetaKeywords and Page.MetaDescription properties
One simple recommendation to improve the search relevancy of pages is to make sure you always output relevant “keywords” and “description” <meta> tags within the <head> section of your HTML. For example:
One of the nice improvements with ASP.NET 4 Web Forms is the addition of two new properties to the Page class: MetaKeywords and MetaDescription that make programmatically setting these values within your code-behind classes much easier and cleaner.
ASP.NET 4’s <head> server control now looks at these values and will use them when outputting the <head> section of pages. This behavior is particularly useful for scenarios where you are using master-pages within your site – and the <head> section ends up being in a .master file that is separate from the .aspx file that contains the page specific content. You can now set the new MetaKeywords and MetaDescription properties in the .aspx page and have their values automatically rendered by the <head> control within the master page.
Below is a simple code snippet that demonstrates setting these properties programmatically within a Page_Load() event handler:
In addition to setting the Keywords and Description properties programmatically in your code-behind, you can also now declaratively set them within the @Page directive at the top of .aspx pages. The below snippet demonstrates how to-do this:
As you’d probably expect, if you set the values programmatically they will override any values declaratively set in either the <head> section or the via the @Page attribute.
URL Routing with ASP.NET Web Forms
URL routing was a capability we first introduced with ASP.NET 3.5 SP1, and which is already used within ASP.NET MVC applications to expose clean, SEO-friendly “web 2.0” URLs. URL routing lets you configure an application to accept request URLs that do not map to physical files. Instead, you can use routing to define URLs that are semantically meaningful to users and that can help with search-engine optimization (SEO).
For example, the URL for a traditional page that displays product categories might look like below:
With ASP.NET 4.0, URLs like above can now be mapped to both ASP.NET MVC Controller classes, as well as ASP.NET Web Forms based pages. You can even have a single application that contains both Web Forms and MVC Controllers, and use a single set of routing rules to map URLs between them.
It is pretty common within web applications to move pages and other content around over time, which can lead to an accumulation of stale links in search engines.
In ASP.NET, developers have often handled requests to old URLs by using the Response.Redirect() method to programmatically forward a request to the new URL. However, what many developers don’t realize is that the Response.Redirect() method issues an HTTP 302 Found (temporary redirect) response, which results in an extra HTTP round trip when users attempt to access the old URLs. Search engines typically will not follow across multiple redirection hops – which means using a temporary redirect can negatively impact your page ranking. You can use the SEO Toolkit to identify places within a site where you might have this issue.
ASP.NET 4 introduces a new Response.RedirectPermanent(string url) helper method that can be used to perform a redirect using an HTTP 301 (moved permanently) response. This will cause search engines and other user agents that recognize permanent redirects to store and use the new URL that is associated with the content. This will enable your content to be indexed and your search engine page ranking to improve.
Below is an example of using the new Response.RedirectPermanent() method to redirect to a specific URL:
ASP.NET 4 also introduces new Response.RedirectToRoute(string routeName) and Response.RedirectToRoutePermanent(string routeName) helper methods that can be used to redirect users using either a temporary or permanent redirect using the URL routing engine. The code snippets below demonstrate how to issue temporary and permanent redirects to named routes (that take a category parameter) registered with the URL routing system.
You can use the above routes and methods for both ASP.NET Web Forms and ASP.NET MVC based URLs.
Summary
ASP.NET 4 includes a bunch of feature improvements that make it easier to build public facing sites that have great SEO. When combined with the SEO Toolkit, you should be able to use these features to increase user traffic to your site – and hopefully increase the direct or indirect revenue you make from them.
[In addition to blogging, I’m also now using Twitter for quick updates and to share links. Follow me at:twitter.com/scottgu]
Hope you all had a great holiday – welcome to 2010!
Last month I did a blog post about some of the presentations I did in Europe and posted the slides+demo files from them. High-quality videos of the talks I did in Sweden were posted two weeks ago on the Channel9 site, so you can also now watch videos of the talks online as well. The videos use a nice format where you can watch me talking as well as the screen at the same time. The code is readable when running in full-screen mode.
Below are links to the different talks along with the slides+sample files:
ASP.NET 4 and VS 2010 Web Development
This 90 minute talk provides a nice introduction to ASP.NET 4 and VS 2010 for Web Development. It is primarily demo-driven and walks-through a lot of the new features coming with the release.
The talk starts with a 2 minute introduction of someone introducing me which is in Swedish – but the rest of the talk is of me talking in English.
This 2 hour talk provides a nice introduction to ASP.NET MVC, and explains it by walking through how to build a simple application with it from scratch. Along the way it highlights and discusses some of the new features coming in ASP.NET MVC 2.
In October we shipped the public Beta 2 release of Visual Studio 2010 and .NET 4. The feedback on the new features in VS 2010 and .NET 4 has been really great. I’ve been working on a blog series about some of them (lots more posts to go!) and have also had a chance to present them to a broad range of audiences – and it has been great hearing the excitement people have about them.
At the same time, though, we’ve also received feedback that the performance and virtual memory usage of VS 2010 Beta 2 is not where people need it to be before we ship.
We’ve been doing an intensive performance optimization push the last two months that is delivering significant performance and virtual memory usage improvements across the product. The early feedback from a small set of customers testing interim builds since Beta2 has been positive about these improvements. We still have several big performance fixes in the process of being checked in that will improve things even further.
Public Release Candidate
In order to make sure that these fixes truly address the performance issues reported, and to help validate them across the broadest number of scenarios and machine configurations, we’ve decided to ship another public preview release of VS 2010 and .NET 4 before we ship. Specifically, we plan to make a Release Candidate build available in February that everyone will be able to download and test. It will be a public build and include a broad “go live” license that supports production deployment.
The goal behind the Release Candidate is to get broad feedback on the readiness of the product. In order to ensure that we are able to receive and react to this feedback, we will also be moving the launch of Visual Studio 2010 and .NET 4 back a few weeks.
Please continue to send us your feedback about the product, as well as details on issues you encounter with the current Beta 2 release. Your feedback is invaluable, and really helps ensure we deliver the right product. Feel free to send me email (scottgu@microsoft.com) if you have a specific issue you are running into that you don’t think has already been reported.
[In addition to blogging, I’m also now using Twitter for quick updates and to share links. Follow me at:twitter.com/scottgu]
Last month I gave a Silverlight 4 keynote at the PDC conference. You can watch my keynote online here (my part of the keynote starts at the 53:30 mark in the video).
I showed off a number of fun demos during the keynote that highlighted some of new features coming in Silverlight 4. Today we posted the samples online (with code) so that you can download and run them locally on your own machines.
You can download the keynote demos here (source code + VS project file included with each sample).
Keynote Demos
Below are some details about each of the demos now available for download:
PhotoBooth Application
The PhotoBooth application demonstrates some of the fun things you can do with the new WebCam and Microphone support in Silverlight 4. It allows you to record videos and take photos within the browser – and then optionally apply effects to them (for example: the bulge effect below). For kicks you can publish a photo of any of the pictures to Twitter :-)
BarCode Scanner
The BarCode Scanner application also uses the new WebCam support in Silverlight 4. It allows you to scan an ISBN barcode from the back of a book, and will then use Amazon web-services to look up details about the book online:
Rich Notepad
The rich notepad application shows off some of the new text editing features in Silverlight 4. It allows you to edit rich text within the browser, supports Bidi text (including Arabic and Hebrew), supports both left-to-right and right-to-left control layout (RTL is show below – notice how the scroll-bar is on the left hand side of the screen), supports programmatic copy/paste to the system clipboard, custom right-click context menus, printing, and drag/drop of files from the desktop into the browser to edit:
HTML Hosting
The HTML Hosting application shows off using the new Silverlight 4 webbrowser control in an out of browser application (note: you must run the application out of the browser for it to work). It allows you to use the control both interactively (meaning you can click the HTML within it and run it like an application). It also allows you to use the hosted HTML as a brush that you can apply to other Silverlight controls. For fun you can click the MSDN.com tab below and you’ll get rick-rolled to YouTube. You can still use the HTML as a brush and carve it up into a jigsaw – even though the video is still playing (using Flash hosted within the HTML):
Learn More
Keep an eye on Tim Heuer’s blog as well as John Papa’s blog. They post regularly about Silverlight, and will be doing some blog posts in the near future that cover the above applications in more detail.
Summary
You can download the keynote demos here (source code + VS project file included with each sample). They work with the public Silverlight 4 Beta + SL4 VS Tools Support. They provide a nice way to relive the keynote on your own machine, as well as show off the demos to friends.
Hope this helps,
Scott
P.S. The Facebook application we showed in the keynote will also be available for download in the future. We are still adding more features to it and polishing it up – I’ll do a blog post about it as soon as it is available.
[In addition to blogging, I’m also now using Twitter for quick updates and to share links. Follow me at:twitter.com/scottgu]
Over the last few weeks I’ve been polling developers to see how many are using the new Search Engine Optimization (SEO) toolkit to increase traffic to their web-sites. I’ve been surprised by how many people either have never heard of the tool, or have not yet had a chance to run it against their websites. This blog post provides a quick summary about why anyone doing web-development should check it out.
Why use the free SEO Toolkit?
In a nutshell – the free SEO Toolkit Analyzer helps you increase traffic and visitors to your site, and as a result can increase the revenue you directly or indirectly make through your web-site.
The SEO Toolkit Analyzer increases traffic to your site by helping you assess and improve the search relevancy ranking of your site with search engines like Google, Bing, and Yahoo. As your search relevancy ranking improves, and your site becomes more search engine optimized, you’ll find that your site receives more and more user traffic from search engine queries.
Takes less than 5 minutes to download and run the SEO Analyzer
It takes less than 5 minutes to download and run the SEO Toolkit Analyzer against your web-site. You simply point the tool at the top-level URL of your web-site, and then it will automatically crawl your site like a search engine would – following each link, reviewing the HTML on each page, and generating a human friendly report of every SEO or content violation it finds on the site - along with suggestions on how to fix each of them:
It works with any web-server
The SEO Toolkit works with any web-server. It works with IIS5, IIS6, IIS7 and IIS7.5 – it will even work with Apache web-servers running on Linux. Basically you can point the SEO Analyzer at any remote HTTP server and it will crawl the site and generate a SEO report. You do not need to setup any software on the remote server – instead the tool crawls and analyzes the site remotely just like a search engine would. This means you can even run the site on your friends (or potential customers) sites and generate reports for them.
The SEO Toolkit does require that you have the IIS7 Admin tool installed on your local dev/client machine in order to host the SEO Analysis admin UI tool. The IIS7 admin tool is a built-in feature of Windows Vista, Windows 7, and Windows Server 2008. The IIS7 admin UI only needs to be installed on your local dev machine though – you do not need to have IIS7 installed on the server. The SEO utility running inside it will work fine against your IIS5, IIS6 and other web servers.
Use the green “Install Now” button on the IIS SEO Toolkit download page in order to automatically install the SEO Toolkit on your development machine (clicking the button will also download and install the Web Platform Installer if you don’t already have it installed).
How to Learn More
I wrote up a tutorial on how to use the SEO Toolkit this past summer (the UI in some of the dialogs has changed a little – but the functionality is the same).
If you haven’t downloaded the SEO Toolkit and used it to analyzer your web-site yet, then I highly recommend spending 10 minutes now and giving it a try. You’ll find it provides a really easy, automated way to quickly find and identify SEO issues you have on your web-site – along with suggestions on how to fix them. Fixing them will increase the traffic and visitors to your web-site.
Mike Volodarsky demonstrates the IIS 7.0 extensibility model by extending the Response Modification into a configurable Web server module and a custom management page for IIS Manager.
This month Dino Esposito shows you how to get Windows-style modal dialog boxes for your Web applications thanks to the Ajax Control Toolkit and some clever coding.
by Gerardo de Geest and Gerben van Loon at 16:00 PM, 01/22/2008
Web Service Software Factory: Modeling Edition is a collection of resources for modeling and building Web services for Windows Communication Foundation and ASMX.
The .NET Framework has excellent internationalization support, but JavaScript does not. If you’re using ASP.NET AJAX, learn what you need to do to adapt.
Introducing Web-centric features of Windows Communication Foundation in the .NET Framework 3.5, including the HTTP programming model and the new syndication API.
AJAX Extenders extend the behavior and features of ordinary Web controls so you can reduce postbacks and control input even better than with AJAX alone.
The second of this two-part series delves into the script services programming model, which is useful if you’re looking for a full paradigm shift in building AJAX applications.
In the first of a two-part column, Dino explains AJAX from an architectural standpoint to help developers, architects, designers, and administrators better understand the issues that affect their sites.
ASP.NET 2.0 supports several methods for deploying Web sites to production. Web Deployment Projects add yet another worthwhile approach. Fritz Onion explains.
IIS 7.0 takes the speed, reliability, and security of IIS 6.0 and turns it into a highly extensible and manageable Web server that will run Web apps of the future.
This month James McCaffrey presents a technique that allows you to write lightweight test automation to verify the functionality of AJAX Web applications.
AJAX allows you to build rich browser applications using powerful combinations of existing client-side Web technologies. This month Dino delves into AJAX
Microsoft AJAX Library and the ASP.NET 2.0 AJAX Extensions provide a number of compelling features ranging from client-side data binding, to DHTML animations and behaviors. Learn all about them here.
Yes, I know we all have our feelings for VSS, but I've been using this little trick (for the lack of a better word) for several years now, and I thought it's about time for me to post it here in case is beneficial to anybody else. At the very first line on many of my programs you will find a region similar to the following:
#region Version Header
///<remarks>
/// $Workfile: MyLogger.cs $
/// Description: This class implements a logging mechanism by wrapping the ABC Library.
/// Author: José Luis Manners Docs: José Luis Manners
This is basically a header I use to document every .cs file. There's not worst feeling in the world than having to modify somebody else's code (or perhaps and old code of yours) and not even knowing what it's suppose to do or how its purpose has changed overtime. What's interesting about this header is that it takes advantage of the keyword expansion capabilities of VSS, so things like file name, modification date, version, etc., are automatically updated in the code by VSS every time you do a check-in. The keywords are those enclosed in '$', btw.
To make your life easier and avoid copy and pasting each time you create a new cs file, you can create a wizard template that has this header embedded in it, and when you create a new class the header will be automatically included with the code generated by VS.NET (you can find lots of information online on how to do modify VS.NET templates). In my case, everytime I create a new C# file I run a macro I wrote that prompts me for the description and takes care of filling in the non-VSS sections, including putting the system date in the "Created:" session, and generates the entire header.
There is a VSS keyword which I'm not showing and that is "$History: $". With this keyword you can have VSS keep a log of all the changes directly in your code, so information like version, remarks, name of person that checked-in that version, dates, etc., are stamped in your code. This is basically the information you can see from within VSS when you select "Show History" on a file and click on "History Details". Althought having all this historical information directly in the source code is a little overwhelming to some people (none the last redundant), it could also be very beneficial to others - you take your pick.
HINT: You can put the history log on a separate region in your code, that way it's "out of your way".
For more information on VSS keyword expansion features and the entire list of available keywords see the following link:
Web Service Software Factory is designed to help you build Web service solutions that follow known architecture and design patterns, as Aaron Skonnard explains here.
Thank you everyone for coming to my talk this past weekend at the Jacksonville Code Camp held in beautiful (and always under construction) Jacksonville, Florida. For those of you who asked, you can get the code I used during my demos from the following link:
Also, you can get more information regarding the temperature monitor and the serial/ethernet device server I used on my demos from the manufacturers links below:
Due to the distributed nature of a business process it makes sense for a workflow to be deployed as a distributed application. See how Windows Workflow and Web Services hold the key.
Jeff Prosise describes performance problems in an ASMX Web service that relied on legacy COM and Visual Basic 6.0 to perform key processing tasks and the approach he took to find a fix.
In this article, Chandu Thota highlights some of the most salient features of the Virtual Earth APIs and shows you how to build your own powerful mapping and local search applications using them.
This article discusses a new load test tool in Visual Studio 2005 Team System for performance and stress testing your Web sites, Web services, and other server components. Combined with its handy reporting capabilities, the load test tool provides some powerful options for sharing and managing test results.
Someone posted a message in one of the many newsgroups I frequently visit. He needed to find out at runtime how many Windows forms exist in a project. Here's the message and my solution to his problem in case anybody else finds it useful:
"Saludos
Estoy haciendo un proyecto WinForm y requiero saber cómo puedo ver las formas que están dentro del proyecto
Claro , con el explorador en modo diseño, solo que requiero verlas en en tiempo de corrida. No se si conoces en Access el objeto forms collection que te muestra las características de las formas de la currentdb, de manera que yo pudiera recorrer con una instruccion for each... todas y cada una de las formas y abrir una en particular. En Visual .net yo puedo instanciar una forma, pero lo hago sabiendo su nombre : no puedo por ejemplo decir for each frm in forms if frm.name='XXXX' frm.show exit for endif next ya que no existe el objeto forms que me muestre las formas del proyecto.
gracias"
We can easily obtain this information at runtime using Reflection. All we have to do is call the GetExecutingAssembly method to obtain an Assembly object that points to the assembly we're executing (our current project), we then call GetTypes on that assembly object to get a list of all the types defined inside of it. The rest is just looping through the list and check which type(s) match what we're looking for, in this case we're looking for Windows forms:
Somebody posted a message in the C# newsgroup asking for a way to populate a ListBox with the name of the months in Spanish. He basically had created an enum and wanted to fill up the ListBox from that enum. The enum looks like this:
publicenum Meses:int
{
Enero=1,
Febrero = 2,
Marzo = 3,
Abril = 4,
Mayo = 5,
Junio = 6,
Julio = 7,
Agosto = 8,
Septiembre = 9,
Octubre = 10,
Noviembre = 11,
Diciembre = 12
}
At first, one of the most simple ways that comes to mind is to do something similar to this:
ListBox listBox1 = new ListBox();
listBox1.Items.Add(Meses.Enero);
listBox1.Items.Add(Meses.Febrero);
listBox1.Items.Add(Meses.Marzo);
listBox1.Items.Add(Meses.Abril);
listBox1.Items.Add(Meses.Mayo);
listBox1.Items.Add(Meses.Junio);
listBox1.Items.Add(Meses.Julio);
listBox1.Items.Add(Meses.Agosto);
listBox1.Items.Add(Meses.Septiembre);
listBox1.Items.Add(Meses.Octubre);
listBox1.Items.Add(Meses.Noviembre);
listBox1.Items.Add(Meses.Diciembre);
This solution works fine, it does what's needed. But what happens if you want to have a localized version of your application in another language? It would look strange to have a ListBox with a label that says "Please select a month: " and the months inside the ListBox shown in Spanish, don't you think?. Besides, the values are kind of hard-coded in a sense, and personally, I've never been a fan of hard-coding anything.
Here comes CultureInfo to the rescue
Like with many other things in software development, there is always more than one way to produce the same results, and this is no exception. Believe or not, the 13 lines of code from the previous example could be easily reduced to only 3 (yes, you heard me right!!). All you really need to do is use a CultureInfo object and its DateTimeFormat property so you can get an array of strings with the name of the months already translated into the language of the culture you want. We then just add the array to the Items collection of the ListBox using the AddRange method:
// Get the CultureInfo from the Dominican Republic
ASP.NET 2.0 aims to reduce the amount of code required to accomplish common Web programming tasks by 70 percent or more. New services, controls, and features make it almost as dramatic an improvement to ASP.NET 1.x as that was to ASP Classic. Here Jeff Prosise explores the new features.
If you want to develop (or continue "sharpening") your C# programming skills. I'd recommend you frequently check the Centro de Desarrollo Microsoft Visual C# (for Spanish speakers) or the Visual C# Developer Center (for English speakers). These two great C# resources contain courses, articles, technical presentations, and some other goodies which you can access directly from the respective site.
Or better yet, if you speak both languages... well you get the idea.
This article describes the WSE policy framework, which allows you to describe constraints and requirements a Web service must enforce. Discussions include security scenarios in WSE 3.0 and extending the framework with custom constraints and requirements.
Recently I had a need to create a Form with a disabled close button. Believe or not, this simple task cannot done be achieved by simply configuring a property at design time, because no such design-time property exists. One alternative is to set the ControlBox property to "false", but in reality this removes the three buttons (minimize, maximize, and close) altogether.
After a little "googling" I found some examples but they were all using P/Invoke and/or were written in VB. But then I remembered that during my good old days of Win32/C++/MFC programming I used to change the visual style of a window class by setting up values from the constants in the include file winuser.h. In that file there was a constant named CS_NOCLOSE which was used to disable the close button in the window. That's cool, but... how can I use that stuff now?
Well, reading the beloved MSDN documentation (I really mean that) it turns out that the Form class has a property named CreateParams which allows you to set parameters that define the appearance of the form before it gets created. So the only thing that needs to be done is to override this property in my Form and add the value for CS_NOCLOSE that we want. Something similar to this:
protectedoverride CreateParams CreateParams
{
get
{
constint CS_NOCLOSE = 0x200;
CreateParams cp = new CreateParams();
cp = base.CreateParams;
cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE;
return cp;
}
}
voilá, it works!! BTW, if you like to know where the include file is, it should be under “C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include”, or something close to that depending on your installation of the Framework. Here's a snapshot of how it looks like if your curious:
Like with the Datagrid Jerárquico (Hierarchical Datagrid) sample application, for long time I've been receiving emails from people asking me to send them an example on how to use log4net. So, I've figured is about time to put something together and keep it centralized so everybody can get it instead keep sending it via email. You can get this little app from the "Attachments" link.
Ensuring the security of a Web application is critical and requires careful planning throughout the design, development, deployment, and operation phases. It is not something that can be slapped onto an existing application. In this article, Mike Volodarsky outlines best practices that allow you to take advantage of the security features of ASP.NET 2.0 and IIS 6.0 to build and deploy more secure Web applications.
In this article, Niels Flensted-Jensen demonstrates how you can combine new and existing Microsoft technologies with minimal new code to provide flexible authorization for individual Web service methods. Windows 2003 Authorization Manager, Web Service Enhancements 3.0, and Enterprise Library all play a part.
"I am documenting my code with the XML tags included in .NET for this, but my comments inside these tags do not show"
Well, the first thing you need to do is to configure the project in VS.NET so that it generates XML documentation. This can be done in the property window under the "Build" tag, put the name of the XML file you want to generate under "XML Dcomentation File". Now complie your project and a file with the XML comments will be created.
Now take this file and process it with NDoc. This tool allows you to generate MSDN-like documentation of your code. This type of documentation will show the code included within the <example> and <code> tags.
ASP.NET provides a number of ways to maintain user state, the most powerful of which is session state. This article takes an in-depth look at designing and deploying high-performance, scalable, secure session solutions, and presents best practices for both existing and new ASP.NET session state features straight from the ASP.NET feature team.
by Ted Pattison and Fritz Onion at 17:00 PM, 08/08/2005
ASP.NET 2.0 introduces a Web Part control that is designed to deal with the serialization, storage, and retrieval of customization and personalization data behind the scenes. In this article, the authors explain how you can put the WebPart control to work in your ASP.NET 2.0 applications.
Dave Fetterman of the Microsoft's .NET Base Class Library (BCL) Team just published this paper on using some of the new culture-agnostic methods of the String class in favor of using CultureInfo.InvariantCulture when writing localized applications.
By now, you're certainly collecting a variety of data from your Web site. But once you collect it, what do you do with it. For it to be meaningful, this data must be categorized and analyzed. The SQL Server 2005 data mining functionalities can help you get the most out of those reams of data you collect, as Peter Pyungchul Kim explains.
The very tools that have helped drive the growing adoption of Web services, and the enabling abstractions that they provide, can often prevent developers from peeking behind the curtains at the XML standards that make up the Web services stack. This article will offer a solution that enables type sharing between proxies created for complementary Web services, while at the same time providing an opportunity to examine the Web Services Description Language (WSDL) and its interaction with the Web services tools you know and love.
In this article the author focuses on one critically important Web services specification that has been largely overlooked: the Business Process Execution Language for Web Services (BPEL4WS, or BPEL). He describes why BPEL is important and what it offers you if you are implementing Web services today or planning to in the future. Concrete examples using BizTalk Server 2004 are presented in the article.
If you want to schedule ASP.NET tasks, one solution is to use a Web service to provide an interface to your ASP.NET application and build a Windows service that calls to it at scheduled intervals. Thus the ASP.NET application doesn't have to own the scheduling logic. Here the author shows how to schedule your ASP.NET tasks using a Windows service to initiate the Web service call because Windows services can start themselves when Windows boots up.
Web Services use XML to communicate with each other. But sometimes the XML your service emits is not the same XML that another service is expecting. If you want to avoid the problems that this kind of situation can cause, you need to get good control over your XML serialization. Here author Chris Dix shows you exactly how to tackle this problem.
Last week we had David McNamee from developerLabs, Inc. talking about some of the new features that will ship with C# 2.0. Although this is a well known subject among .NET ranks, what made his an interesting presentation was the practical and straight-forward way on which David treated topics like: generics, anonymous methods, partial classes, etc., and if you add to that his enthusiasm for .NET, then you have a great presentation in my opinion.
Another thing I liked was the way code was presented. Unlike other speakers that already have some pre-written code and all they do is add a few lines here and there, David wrote all the code from scratch. I think this technique gives the audience a better sense of knowing where everything is or coming from, while makes them more participant as the code progresses.
Good job David and hope to see you at CodeCamp this coming weekend !!
Excel 2003 lets you dynamically integrate the data provided by different Web services. It also lets you take advantage of the latest capabilities in Office 2003 to customize list views, graphs, and charts, and to catalog bulk items online or offline. Find out how you can makle the most of the data returned from your Web services with the Office 2003 Web Services Toolkit API.
I've received a few emails from people inquiring about the sample code that demostrates how to create a hierarchical datagrid. You can download the code from the "Attachments" link below. Let me know if there are any questions and/or suggestions.
Writing a Web application with ASP.NET is unbelievably easy. So many developers don't take the time to structure their applications for great performance. In this article, the author presents 10 tips for writing high-performance Web apps. The discussion is not limited to ASP.NET applications because they are just one subset of Web applications.
Cuando en C# necesitas llamar funciones de Win32 API que reciben cadenas de caracteres, debes ponerle cuidado al tipo de acceso que la función receptora le da al argumento como también al tipo de dato de .NET que le vas a enviar a dicha función.
Las funciones que usan cadenas de caracteres como argumentos de entra (in) pueden ser llamadas desde .NET con simplemente pasarle un objeto System.String. La traducción de System.String a LPTSTR es hecha por el compilador automáticamente mediante un mecanismo que se llama "marshaling". De esta manera la función puede acceder el argumento con el tipo de dato correcto. Pero a pesar de que el compilador hace la traducción, hay un factor adicional que hay que considerar cuando el argumento es utilizado como argumento de salida (out).
Cuando un argumento es de salida quiere decir que el argumento va a ser modificado internamente por la función receptora. Recuerda que los objetos System.String son inmutables, o sea, no se pueden cambiar y si le cambias el valor, un nuevo objeto será creado. Por lo tanto si envías el argumento como System.String cuando la función lo modifique y lo recibas nuevamente ya no va a ser el mismo objeto que originalmente enviaste. La manera de solucionar esto es pasarle a la función un objeto StringBuilder en lugar de System.String. El compilador hará la conversión de un objeto StringBuilder a un LPTSTR y cuando la función lo modifique y regrese todavía será el mismo objeto StringBuilder que enviaste.
Pongamos este conocimiento en práctica con algo de código. Vamos a llamar la función GetComputerName del Win32 API. Esta función tiene el siguiente prototipo:
BOOLGetComputerName(
LPTSTRlpBuffer,
LPDWORDlpnSize
);
Entonces en C# la declaramos con el siguiente prototipo:
Cuando llamas GetComputerName la función te devuelve el nombre de tu computadora en el objeto buffer que le pasaste. Ahora bien, si cambias el prototipo para que reciba un String y llamas la función pasándole un objeto String, notarás que tu objeto no contiene el valor esperado.
Once you've addressed security in your code, it's time to look at the environment it runs in. Firewalls stop unauthorized traffic from getting into your network, and smart Web service-specific firewalls, like the one that comes with Internet Security and Acceleration (ISA) Server 2004, bring XML intrusion prevention to your system for that added layer of safety.
by Jason Masterman and Ted Pattison at 17:00 PM, 07/19/2004
Microsoft Office SharePoint Portal Server 2003, which is part of the Office System, lets you create and manage virtual servers, site collections, sites, workspaces, and users. You can also use the Windows SharePoint Services object model to design and implement user-targeted applications. In the second part of a two part series, the authors take a look at the WSS and SPS object models, Web Part Page anatomy, creating and deploying Web Parts, and Web Part security. They also discuss Web Part infrastructure and how to create custom Web Parts.
This article presents a general-purpose client quality reporting mechanism that can be used in any .NET-based transaction system that employs HTTP/SOAP. The design uses client response time and quality recording, upload of logs as SOAP headers attached to new transaction requests, and server handoff of these headers to a low priority queue for logging and analysis. This technique gives an enterprise near real-time information on actual end-user response times. These response times reflect network delays, client application overhead and server delays. By using this technique, enterprises can avoid the need to develop custom software to mine HTTP logs.
ASP.NET 2.0 has addressed some of the most common problems developers face today with a suite of controls, components and IDE tools. One such issuer is maintaining preferences information about individual users of a Web application in a uniform manner. This article drills down into ASP.NET 2.0 to illustrate how it helps solve these problems far easier than is possible today, and demonstrates how these features can be combined to build powerful, personalized Websites in very little time.
When creating a distributed system you frequently need to provide for communication between two entities that are not in sync. Microsoft Message Queue Server (MSMQ) provides the kind of store-and-forward messaging in a pre-built infrastructure that can help you address these kinds of messaging needs. In the past, MSMQ was accessed using a COM wrapper. Now there's a .NET wrapper that lets you accomplish your messaging goals easily from your Framework-based code. To illustrate the use of the wrapper, the author builds a messaging application, sends MSMQ messages over the Web, and discusses messaging security.
The ASP.NET advanced templated controls, such as the DataList and DataGrid, are perfect for many data representation situations. However, when you need the flexibility to render a variety of layouts, the Repeater control is what you need. In this article the author builds a full-featured blog application to illustrate the use of the Repeater and DataList controls that render nested data in a master-detail relationship. He then discusses how to override the default implementations of these controls by adding some client-side JavaScript code that makes the blog more responsive and enhances its usability.
If you're building an ASP.NET Web site you could probably use a good, solid code foundation to start with and build upon. Wouldn't it be nice to start with a complete site, make a few tweaks and customizations, and go live? The ASP.NET Starter Kits are packaged solutions that let you do just that. The five kits-Community, Reports, Commerce, Portal, and Time Tracker-supply full, reusable code that can be easily customized. In addition, there are a number of ISPs that support automatic deployment of ASP.NET Starter Kit Web sites, leaving you with little left to do when you have to get there fast. Here, the author introduces the ASP.NET Starter Kits and builds a community Web site with lots of advanced features such as ratings, user polls, upload quotas, change notifications, and themes.
by Aaron Skonnard and Dan Sullivan at 17:00 PM, 07/14/2003
In an earlier article the authors showed how to build a custom WebMethods extension that provides XML Schema validation, a function that is lacking in ASP.NET. In the process they established a foundation for enforcing business rules during the deserialization of XML data. The technique, which is described in this article, uses declarative XPath assertions to test business rule compliance. In building this business rules validation engine, the authors integrate the validation descriptions into the WSDL file that is automatically generated by the WebMethod infrastructure. Finally, they demonstrate how to extend wsdl.exe, the tool that generates WebMethod proxy/server code from WSDL files, to make use of their extensions.
by Edited by Nancy Michell at 17:00 PM, 07/14/2003
This month find out which part of an HTML document has called a script, how to concatenate binary files, find a node, reference one script from another, build a GUI database front end in Access, and compare XML files.
by Aaron Skonnard and Dan Sullivan at 17:00 PM, 06/16/2003
WebMethods make the development of XML Web Services easier by encapsulating a good deal of functionality, but there is still a lot of underlying XML processing that you have to be responsible for. For example, WebMethods do not validate messages against the implied schema. Because they are not validated, the response that's returned can result in unintended consequences. To address this, the authors extend the WebMethod framework by adding XML Schema validation through a custom SoapExtension class.
Fortunately for developers, threading in ASP.NET is a lot easier than it was in ASP. In this article, the author takes a look at threading in the ASP.NET HTTP pipeline, and explains how threads are managed efficiently without the involvement of the developer. The article considers how the common language runtime threadpool is used by ASP.NET to service requests, looks at the pooling mechanisms used for handlers, modules, and applications, and covers both IIS 5.0 and IIS 6.0 and how they differ in their approach to request processing and thread allocation. Finally, how and when to use asynchronous handlers is discussed for developers who still need to use threads in their own applications.
Without good security, Web Services will never reach their potential. WS-Security and its associated technologies, the focus of this article, represent the future of security for Web Services. Provided here is an overview of these emerging security standards that explains what they do, how they work, and how they get along together. Topics discussed include integrity and confidentiality and how these are provided by public key cryptography, WS-Security, and more. Some of the key components of WS-Security, such as the wsu namespace, are also covered.
In the .NET Framework, the CodeDOM object model can represent code in a variety of languages. This article examines how source code templates written with the Framework's System.CodeDom and System.CodeDom.Compiler namespaces allow developers to create reusable boilerplate source code that can be shared between projects. Components designed via templates improve productivity and shorten development time. Here C++-style classes and templates are simulated and code is generated in multiple languages through the creation of CodeDOM object graphs. Compiling object graphs and formatting output code are also explained.
LinkLabels are Windows Forms controls that enable a user to hyperlink to a URL that points to either the Web or the local directory system. While the SDK documentation discusses the control, it does not demonstrate how linking is accomplished, nor does it outline the power and flexibility the control provides. This article fills those gaps, showing how to link using the LinkLabel control. It also shows the flexibility of this control for the programmer using the .NET Framework. In addition, the author covers the large number of properties that allow you to customize your controls and accurately place them. Their built-in behaviors are also discussed, along with their use in both Visual Basic .NET and C#.
by Jeff Dunmall and Keith Clarke at 16:00 PM, 12/16/2002
Load testing should be part and parcel of every Web development effort, and it should be performed early in the process. However, if you think you can load test using your development environment, you're going to have some surprises when you go live. In this article, the authors outline the process of planning your load testing effort, considering which machines to use, how many users to simulate, which tools are right for you, and how to interpret your results.
by Kirk Fertitta and Chris Sells at 16:00 PM, 11/11/2002
Throughout this issue, you'll read all about the promise of Web Services and how the .NET Framework enables Web Service development. Many people will also be building their Web Services atop C++ code and frameworks like ATL Server, particularly when performance is paramount. In this article, the authors show how fully functional Web Services are built using ATL Server and Visual Studio .NET. Beginning with unmanaged C++ classes, they add ATL attributes that make the code work over HTTP.
by Krishnamurthy Srinivasan at 16:00 PM, 11/11/2002
The Office XP Web Services Toolkit makes it possible to build applications that gather information and trigger transactions through various Web Services. The toolkit allows you to easily discover Web Services remotely. It also includes the Web Service Reference Tool, which lets you call a Web Service from inside an Office application. This article shows how toolkit-generated code can be used to access simple, as well as complex, Web Services. The author steps through the auto-generated code to explain the classes that collect parameters, the schema to format the request/response, and the actual operations of the Web Service.
Performance is an important concern for any application, but becomes critical when the app is a Web Service accessed by thousands of clients simultaneously. One hardware approach to distributing Web Services requests evenly is a Web farm consisting of multiple servers. Once on a Web farm, Web Service performance can be improved by using ADO.NET DataSet objects to cache frequently accessed data, reducing round-trips to the database. Here the author describes data caching in a Web farm environment and discusses how to avoid the cross-server synchronization problems inherent in this approach.
Web Services are all about exchanging data in the form of XML messages. If you were about to design a database schema, you probably wouldn't let your tool do it for you. You'd hand-tool it yourself to ensure maximum efficiency. In this article, the author maintains that designing a Web Service should be no different. You should know what kind of data will be returned by Web Service requests and use the structure of that data to design the most efficient message format. Here you'll learn how to make that determination and how to build your Web Service around the message structure.
Building Web Services to provide enterprise-level solutions is only the first step. You need to take care of the infrastructure aspects of your solution as well, including provisioning, billing, security, and reporting. In this article, the author uses the .NET Framework and SQL Server 2000 to design a provisioning system that will take care of all these housekeeping tasks. He discusses the general requirements of a Web Service provisioning system, walks through the implementation, and then outlines various scenarios for putting this system to work.
by Paul Yao and David Durant at 17:00 PM, 10/14/2002
If you've built Web sites using ASP.NET, you'll welcome the Microsoft Mobile Internet Toolkit (MMIT). MMIT extends the Visual Studio .NET IDE you already know by providing new controls for handheld devices letting you easily develop applications for wireless devices. This means you can write less code while adapting it to more devices. Not only does MMIT integrate with Visual Studio .NET, it extends ASP.NET as well. This article gives you the background you need to write, test, and deploy a site with MMIT and make all your code able to target specific devices for a custom fit.
Visual Basic .NET comes loaded with features not available in previous versions, including a new threading model, custom class creation, and data streaming. Learn how to take advantage of these features with an application that is designed to extract information from Web pages for indexing purposes. This article also discusses basic database access, file I/O, extending classes for objects, and the use of opacity and transparency in forms.
by Tim Ewald and Keith Brown at 17:00 PM, 08/12/2002
ASP.NET is a flexible and extensible framework for server-side HTTP programming. While most people think of ASP.NET in terms of pages served, there is a lower-level infrastructure sitting beneath this page model. The underlying plumbing is based on a pipeline of app, module, and handler objects. Understanding how this pipeline works is key if you want to get the most out of ASP.NET as an HTTP server platform, while making your process more efficient, and keeping your server secure. This article introduces the architecture of the pipeline and shows how you can use it to add sophisticated functionality to an ASP.NET-based app.
There can be many reasons to reroute incoming Web requests. For instance, sometimes it's necessary to redirect a browser to a page based on user criteria without passing long lists of parameters in the URL. In the past, the only way to intercept such page requests and send them elsewhere was with ISAPI. Now, in ASP.NET, the IHttpModule interface provides notification of server requests, and lets you easily reroute them based on criteria other than browser type or version. Here the author demonstrates the use of IHttpModule for interception and explains the use of ISAPI filters for anyone who isn't yet using ASP.NET.
One of the most significant features of ADO.NET is its integration with XML. Developers can either use an ADO-like API to access the data or work directly with an XML representation of the data. This article demonstrates how both of these techniques can be used together to create Web applications that take advantage of XML standards such as XSLT. The example presented here is a bug tracking application built using C# and the.NET Framework. The development of the application covers several topics including data access using ADO.NET, the presentation of data using XSLT stylesheets, and the integration of ADO.NET with the .NET XML Framework.
Pre-built custom controls make application design easier and faster and allow you to maintain UI consistency. However, prepackaged controls can be big and slow, and are OS-specific. For those who don't want to use prepackaged controls, Visual Studio .NET provides controls for Web Forms similar to those found in Windows Forms, including label and textbox, and new additions such as the DataGrid, all of which you can customize. If you want to design your own controls, the .NET Framework provides inheritable classes that take care of all the nasty stuff you want to avoid, including page lifecycle, maintaining state across invocations, and browser detection. This article discusses these concepts, as well as eventing, rendering, and client-side scripting.
XML is becoming the ubiquitous data format on the Web, and XML support in SQL Server is evolving to meet the additional demand. Using XML, SOAP, HTTP, and SQL Server, you can now build powerful Web Services easily. To show just how simple it is with SQLXML 3.0, this article walks the reader through the process step by step, from setting up a virtual directory enabling data access via HTTP to executing queries and building Web Services. Finally, the author illustrates the creation of two Web Services clients-one with C# that works with the Microsoft .NET Framework and one with the SOAP Toolkit 2.0 for anyone still using earlier development tools.