Coding standards
When you work with other programmers on a team, you are bound to find many different styles. Of course this is why coding standards exist. What coding standards (if any) do you follow? At his blog, JP Hamilton has a very nice post up about this very topic. Check it out here.
0The role of ‘Models’ in ASP.NET MVC
I’m far from an expert when it comes to the ASP.NET MVC framework so I’m always interested in reading about how other people work with it. Some time ago I ran into a post by Hadi Hariri on the devlicious blog where he talks about the Models in ASP.NET MVC. I found it to be very thought provoking. Check it out here.
0Debugging in Visual Studio with ReSharper
A lot of the .NET developers I know use ReSharper extensively, and swear by it. It’s easy to see why when you pick it up and start using it. I recently ran across this post by James Kovacs and thought it was a great tip. James talks about how to use ReSharper to quickly copy the contents of an exception’s stack trace for debugging. Check it out – it could save you some time the next time you are hunting down a nasty bug.
0Filtering Data with the QueryExtender Control – New in .NET 4.0!
ASP.NET 4.0 adds a new QueryExtender control to make filtering easier. This is great news for virtually all developers since we all often create data-driven web pages. This new QueryExtender control gives us some additional flexibility in filtering as we can use it with the EntityDataSource or LinqDataSource controls. The QueryExtender control supports a number of filtering options: SearchExpression, RangeExpression, PropertyExpression,
OrderByExpression, and CustomExpression. The QueryExtender control can create filters for data that is retrieved from a data source, without using an explicit Where clause in the data source. The control can be used to filter data in markup of a Web page by using declarative syntax.
To see an excellent step by step tutorial on how to use the new ASP.NET QueryExtender control, visit the MSDN walkthrough on the topic here: http://msdn.microsoft.com/en-us/library/dd537669.aspx
0Routing in ASP.NET 4
ASP.NET 4 adds built-in support for routing with Web Forms. Routing is a feature that was introduced with ASP.NET 3.5 SP1 and lets you configure an application to use URLs that are meaningful to users and to search engines because they do not have to specify physical file names. This can make your site more user-friendly and your site content more discoverable by search engines.
Routing in Web Forms Applications…Really?
Yes, routing isn’t JUST for the ASP.NET MVC framework – you can also implement it in your Web Forms applications. You do so by using the MapPageRoute(String, String, String) method of the RouteCollection class. The MapPageRoute method creates a Route object and adds it to the RouteCollection object. You specify properties for the Route object in parameters that you pass to the MapPageRoute method. This is probably best shown in code:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute(“”,
“Category/{action}/{categoryName}”,
“~/categoriespage.aspx”);
}
As shown above, typically, you add routes in a method that is called from the handler for the Application_Start event in the Global.asax file. This approach makes sure that the routes are available when the application starts. It also enables you to call the method directly if you intend to unit test the application.
To see an excellent step by step tutorial on how to use ASP.NET Routing in a Web Forms Application, visit the MSDN walkthrough on the topic here: http://msdn.microsoft.com/en-us/library/dd329551.aspx
0.NET Framework 4 Client Profile
What is the .NET Framework 4 Client Profile?
A subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Windows Communication Foundation (WCF), and ClickOnce features.
When & Why should you use the .NET Framework 4 Client Profile?
Application download and install times are just as much a measure of your application as it’s run-time performance. You should strive tomake the deployment as quick and painless as possible for all of your applications.
Applications that target the .NET Framework 4 Client Profile typically improve the deployment experience by having smaller download sizes and quicker install times. An application that targets the .NET Framework 4 Client Profile has a smaller redistribution package that installs the minimum set of client assemblies on the user’s computer, without requiring the full version of the .NET Framework 4 to be present.
What should you know about using the .NET Framework 4 Client Profile?
If you are targeting the .NET Framework 4 Client Profile, you cannot reference an assembly that is not in the .NET Framework 4 Client Profile. Instead you must target the .NET Framework 4. If you attempt to reference an assembly in your project that is not included in the .NET Framework Client Profile, Visual Studio will display an error message. When you deploy an application that targets the .NET Framework 4 Client Profile, you only need to deploy the .NET Framework 4 Client Profile. If you are deploying using ClickOnce, you can select the .NET Framework 4 Client Profile as the .NET Framework Launch Condition. If you deploy the .NET Framework 4 Client Profile and your application targets the .NET Framework 4, the user will be prompted to install the .NET Framework 4 when he or she tries to run your application.
0Touch and Manipulation in Windows Presentation Foundation (WPF) – New in .NET 4.0!
Touch and Manipulation in Windows Presentation Foundation (WPF)
Exciting news for WPF developers passionate about taking their UI to the next level of interactivity!
From MSDN:
Elements in WPF now accept touch input. The UIElement, and UIElement3D, and ContentElement classes expose events that occur when a user touches an element on a touch-enabled screen. In addition to the touch events, the UIElement supports manipulation. A manipulation is interpreted to scale, rotate, or translate the UIElement. For example, a photo viewing application might allow users to move, zoom, resize, and rotate a photo by touching the computer screen over the photo. For more information about touch, see Walkthrough: Creating Your First Touch Application
It’s an exciting time to be a WPF developer.
ASP.NET Auto-Start Web Applications – New in .NET 4.0!
ASP.NET Auto-Start Web Applications
From MSDN excerpt:
Some Web applications need to load large amounts of data or perform expensive initialization processing before serving the first request. In earlier versions of ASP.NET, for these situations you had to devise custom approaches to “wake up” an ASP.NET application and then run initialization code during the Application_Load method in the Global.asax file.
A new scalability feature named auto-start that directly addresses this scenario is available when ASP.NET 4 runs on IIS 7.5 on Windows Server 2008 R2. The auto-start feature provides a controlled approach for starting up an application pool, initializing an ASP.NET application, and then accepting HTTP requests.
To use the auto-start feature, an IIS administrator sets an application pool in IIS 7.5 to be automatically started by using the following configuration in the applicationHost.config file:
<applicationPools>
<add name="MyApplicationPool" startMode="AlwaysRunning" />
</applicationPools>
Because a single application pool can contain multiple applications, you specify individual applications to be automatically started by using the following configuration in the applicationHost.config file:
<sites>
<site name="MySite" id="1">
<application path="/"
serviceAutoStartEnabled="true"
serviceAutoStartProvider="PrewarmMyCache" >
<!-- Additional content -->
</application>
</site>
</sites>
<!-- Additional content -->
<serviceAutoStartProviders>
<add name="PrewarmMyCache"
type="MyNamespace.CustomInitialization, MyLibrary" />
</serviceAutoStartProviders>
When an IIS 7.5 server is cold-started or when an individual application pool is recycled, IIS 7.5 uses the information in the applicationHost.config file to determine which Web applications need to be automatically started. For each application that is marked for auto-start, IIS7.5 sends a request to ASP.NET 4 to start the application in a state during which the application temporarily does not accept HTTP requests. When it is in this state, ASP.NET instantiates the type defined by the serviceAutoStartProvider attribute (as shown in the previous example) and calls into its public entry point.
You create a managed auto-start type with the necessary entry point by implementing the IProcessHostPreloadClient interface, as shown in the following example:
public class CustomInitialization : System.Web.Hosting.IProcessHostPreloadClient
{
public void Preload(string[] parameters)
{
// Perform initialization.
}
}
After your initialization code runs in the Preload method and the method returns, the ASP.NET application is ready to process requests.
With the addition of auto-start to IIS .5 and ASP.NET 4, you now have a well-defined approach for performing expensive application initialization prior to processing the first HTTP request
Client side programming with ASP.NET – New Improvements in ASP.NET 4.0!
Setting Client IDs
As an ASP.NET developer, have you been frustrated when it comes to client side programming? Do you consider JavaScript the bane of your existence? Is it because you are constantly struggling to write client script that references HTML elements rendered for your server side controls?
The new ClientIDMode property makes it easier to accomplish the above tasks. More and more developers are making increasing use of Microsoft Ajax which in turn makes the need to do this more common. For example, you may have a data control that renders a long list of products with prices and you want to use client script to make a Web service call and update individual prices in the list as they change without refreshing the entire page.
Typically you get a reference to an HTML element in client script by using the document.GetElementById method. You pass to this method the value of the id attribute of the HTML element you want to reference. In the case of elements that are rendered for ASP.NET server controls earlier versions of ASP.NET could make this difficult or impossible. In previous versions of ASP.NET, You were not always able to predict what id values ASP.NET would generate, or ASP.NET could generate very long id values. The problem was especially difficult for data controls that would generate multiple rows for a single instance of the control in your markup.
ASP.NET 4 adds two new algorithms for generating id attributes. These algorithms can generate id attributes that are easier to work with in client script because they are more predictable and that are easier to work with because they are simpler. For more information about how to use the new algorithms, see the following topics:
Windows Communication Foundation (WCF) – Multiple IIS Site Bindings Support – New in .NET 4.0
When hosting a Windows Communication Foundation (WCF) service under Internet Information Services (IIS) 7.0, you may want to provide multiple base addresses that use the same protocol on the same site. This allows the same service to respond to a number of different URIs. This is useful when you want to host a service that listens on http://www.contoso.com and http://contoso.com. It is also useful to create a service that has a base address for internal users and a separate base address for external users. For more information, see Supporting Multiple IIS Site Bindings
0