Daily ASP.NET Community Spotlight

ASP.NET Web API and HttpClient Available on NuGet
Mon, 20 Feb 2012 19:35:09 GMT

If you don’t need the full ASP.NET MVC 4 installer with project and item templates for Visual Studio 2010 then you can download the various ASP.NET Web API packages directly from NuGet (see list of packages below). If you are new to NuGet then it is a Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects that use the .NET Framework (check out the NuGet overview ). NuGet Packages Here are the relevant NuGet packages depending on what you want to build: Web API hosted in ASP.NET: AspNetWebApi Self-hosted Web API: AspNetWebApi.Selfhost HttpClient including XML and JSON formatters: System.Net.Http.Formatting JsonValue for navigating and manipulating JSON: System.Json Additional Information...(read more)

ASP.NET MVC 4 Beta
Mon, 20 Feb 2012 02:00:21 GMT

A few days ago we released the ASP.NET MVC 4 Beta .  This is a significant release that brings with it a bunch of great new features and capabilities.  The ASP.NET MVC 4 Beta release works with VS 2010 and .NET 4.0, and is side-by-side compatible with prior releases of ASP.NET MVC (meaning you can safely install it and not worry about it impacting your existing apps built with earlier releases).  It supports a “go-live” license that allows you to build and deploy production apps with it.  Click here to download and install it today. The ASP.NET MVC 4 Beta will also be built-into the upcoming VS11 / .NET 4.5 beta that is coming out shortly.  This week’s beta doesn’t work with the previous VS11 developer preview that shipped...(read more)

Using MongoDB with ASP.NET Web API
Sun, 19 Feb 2012 06:53:47 GMT

MongoDB is a popular NoSQL database that makes it a great backend for Web APIs which lend themselves towards a document store rather than a relational store . In this blog we show how you can use MongoDB with ASP.NET Web API to build an ApiController with support for HTTP GET, PUT, POST, and DELETE. Our sample controller is a simple contact manager Web API which builds on many of the same concepts as in the tutorial “ Creating a Web API that Supports CRUD Operations ” so I would recommend that you skim that for background. In particular, the URI patterns are very similar to that of the tutorial: Action HTTP Method Relative URI Get a list of all contacts GET /api/contacts Get a filtered list of all contacts GET /api/contacts?$top=2 Get a contacts...(read more)

How to create a Web Deploy package when publishing a ClickOnce project
Sat, 18 Feb 2012 18:57:45 GMT

The other day I saw a question on StackOverflow (link in resources below) asking How you can create a Web Deploy (AKA MSDeploy) package when publishing a ClickOnce project. The easiest way to do this is to use the Web Deploy command line utility, msdeploy.exe. With the command line you can easily create an MSDeploy package from a folder with a command like the following: %msdeploy% -verb:sync -source:contentPath="C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\app.publish" -dest:package="C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\co-pkg.zip"   Here you can see that I’m using the sync verb, along with a contentPath provider ( which points to a folder ) as the source and...(read more)

Using JSON.NET with ASP.NET Web API
Sat, 18 Feb 2012 00:10:14 GMT

Json.Net is a popular framework for working with JSON. In particular, it has a bunch of features that are not supported by the DataContractJsonSerializer such as being much more flexible in what kind of types it can serialize and exactly how they should be serialized. The ASP.NET Web API Beta supports an open-ended set of formatters that can read and write data to and from any media type you want to support. For example, if you want to support the vCard format which has the media type text/vcard (previously it was text/directory) media type then you can write a formatter for vCard and register it for the media type (or types) in question. The complete sample is posted on Code Gallery . Note : If you are completely new to ASP.NET Web API then...(read more)

HttpClient: Downloading to a Local File
Fri, 17 Feb 2012 10:34:00 GMT

Downloading content to a local file is a common thing to do. The current version of HttpClient doesn’t yet provide out of the box support for saving content to a file but this sample shows how to extend HttpClient with new ways of reading content retrieved using HttpClient. This sample is also available on Code Gallery . ReadAs Extension Methods The HttpContent class contains content to be sent to a client (in the case of PUT, POST, etc.) as well as data being read from the server in a response. The basic System.Net.Http NuGet package provides support for reading the content as a stream, a string, or a byte array using one of HttpContent.ReadAsStringAsync HttpContent.ReadAsStreamAsync HttpContent.ReadAsByteArrayAsync The way to extend how an...(read more)

Push and Pull Streams using HttpClient
Fri, 17 Feb 2012 05:11:31 GMT

One of the common discussions to have around network APIs is whether streams should be push or pull . That is, do you push content to the network, or does the infrastructure pull it from you and copy it to the network? In general there is no “right” way of determining this, it is a matter of taste and what fits more naturally in the object model in question. HttpContent is the common abstraction for any kind of content in HttpClient regardless of whether it be as part of an HttpRequestMessage or an HttpResponseMessage. Luckily it supports both patterns. The pull pattern is supported by StreamContent which is one of the default implementations of HttpContent. Here the input stream is read (pulled) by the infrastructure and copied to the network...(read more)

Extending HttpClient with OAuth to Access Twitter
Thu, 16 Feb 2012 21:41:06 GMT

Many popular Web APIs such as the twitter API use some form of OAuth for authentication. HttpClient does not have baked in support for OAuth but using the HttpClient extensibility model you can add OAuth as part of the HttpMessageHandler pipeline. The HttpMessageHandler pipeline is the main extensibility point for the HTTP object model underlying both HttpClient and ASP.NET Web API (they use the exact same model). The pipeline allows up to insert message handlers that can inspect, modify, and process HTTP requests and responses as they pass by. The following diagram shows where HttpMessageHandlers sit in the message path on both client (HttpClient) and server side (ASP.NET Web API). The work like “Russian Dolls” in that each handler passes the...(read more)

HttpClient is Here!
Thu, 16 Feb 2012 09:59:00 GMT

HttpClient is a modern HTTP client for .NET. It provides a flexible and extensible API for accessing all things exposed through HTTP. HttpClient has been available for a while as part of WCF Web API preview 6 but is now shipping as part of ASP.NET Web API and directly in .NET 4.5. You can also download it using NuGet – we just use the following three NuGet packages in this blog: System.Net.Http : The main NuGet package providing the basic HttpClient and related classes System.Net.Http.Formatting : Adds support for serialization, deserialization as well as for many additional features building on top of System.Net.Http System.Json : Adds support for JsonVaue which is a mechanism for reading and manipulating JSON documents In case you haven’t...(read more)

UX Anti Patterns for Security on the Web and in the Enterprise
Tue, 14 Feb 2012 19:21:13 GMT

I log into my local bank's website quite often. I transfer money between accounts and all the usual things. Today, when I logged in, I saw that they've decided to dump the security questions they had us answer earlier this year and replace them with a completely new and obscure set. If you don't set the security questions, you can't get to your bank account . Don't get between me and my money. Seriously. There's no better way to get on my bad side. In addition, they decided to make the questions really different from the usual set. I'm sure they feel like they're doing the right thing in the name of security, but here, they have failed. That got me thinking about security usability and other anti-patterns I've...(read more)

What is worth noting in WebMatrix 2
Sat, 11 Feb 2012 01:24:00 GMT

If I have to summarize in what is worth noting in WebMatrix 2 so far, here is how I would like to put it: Inspiring Environment – Web development is an inspiring task and I believe having an inspiring environment for it is important.  In WebMatrix we have always aspired to give web developers a polished and fresh environment to achieve mundane tasks.   Some interesting things worth noting in WebMatrix 2 from this standpoint are: App Install Workflow – We aspired to ask almost zero questions when you install an open source app like WordPress or Joomla.  We make the default choices for you and yeah we know that some of you want full control so we will enable that as well. Color Picker – Yeah you would think that what is the...(read more)

One ASP.NET Sneak Peek: Elegant Web Forms and Snowballs in Hell
Wed, 01 Feb 2012 01:17:39 GMT

For the most part, I'm an ASP.NET developer. I don't need to specify MVC or Web Forms, because it's all One ASP.NET its core. My apps are often hybrids and include not just Web Forms or MVC but also SignalR and Web API. Web Forms often gets picked on because of large View State, weird markup or maybe folks don't like the controls model. However, Web Forms has its place and it's getting even better with .NET 4.5. Here's a little sneak peek of some cool ideas Damian Edwards and the team have been working on for the next version of ASP.NET . As a place to start, remember that ASP.NET routing started in MVC and moved into core ASP.NET. Routing is useful in all ASP.NET applications - MVC, Web Pages and Web Forms. Model Binding...(read more)

KB2650605 QFE : VS2010 sp1 VB web form editor may not become editable during debugging
Tue, 31 Jan 2012 23:45:00 GMT

We recently released a VS2010 sp1 QFE KB2650605 to solve a VB editor debugging problem. During VB web form debugging, VB web form may become un-editable if there are server tags inside. If you develop and debug VB web forms, you might be interested to download this QFE. http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=40811 Best regards, Xinyang Qiu Web Platforms and Tools Team Read More......(read more)

About Orchard Governance and Microsoft
Mon, 30 Jan 2012 08:29:03 GMT

Back in September, we did something with Orchard that is kind of a big deal: we transferred control over the Orchard project to the community. Most Open Source projects that were initiated by corporations such as Microsoft are nowadays still governed by that corporation. They may have an open license, they may take patches and contributions, they may have given the copyright to some non-profit foundation, but for all practical purposes, it’s still that corporation that controls the project and makes the big decisions. That wasn’t what we wanted for Orchard. We wanted to trust the community completely to do what’s best for the project. This is why we organized elections for our new Steering Committee and had five members elected. Anyone who had...(read more)

TechDays in Belgium and Netherlands
Mon, 30 Jan 2012 05:30:47 GMT

I’ll be presenting at the upcoming Belgium and Dutch TechDays next month.  I’ll be doing three tech talks at each of the events: Overview of Windows Azure A look at ASP.NET MVC 4 ScottGu Unplugged I’m particularly excited about the “A look at ASP.NET MVC 4” talk as it will be the first time I’ve presented on it (and it is shaping up to a really great release – more blog posts on that soon). For more details on how to attend the event visit the Belgium Techdays and Dutch Techdays websites.  Hope to see some of you at the conferences! Scott P.S. In addition to blogging, I use Twitter to-do quick posts and share links. My Twitter handle is: @scottgu Read More......(read more)