.NET Technical bits

Thursday, December 30, 2010

New concepts in ASP.NET 4.0, Visual Studio 2010 IDE

1. Code snippets: - Code snippets are pre-developed code templates which can save time spent on thinking about the syntax. There are already a lot of built-in code snippets in VS2005 and VS2008. However, those are only available for the code-behind. Code snippets in VS2010 are introduced for JScript, HTML, and ASP.NET markup as well.
2. New Profiles: - We have seen different development profiles in previous versions of .NET. Like VB, C#, Web Development, and General Development. We select a profile based on our priorities. These are selected after the first installation of Visual Studio or from the Import Export option.
In VS2010, two more profiles are introduced and both support HTML developers. Those are:
1. Web Development
2. Web Development (Code Optimized)
3. Generate From Usage: - In previous versions of ASP.NET, Microsoft introduced code refactoring to generate methods and identifiers from existing code. In ASP.NET 4.0, there is a new concept of Generate From Usage - generates properties, methods, classes, and other types based on existing code.
4. Multi Targeting: - In VS2008, it is possible to create a project in version 2.0 or 3.0, rather than developing in default 3.5. Also, there is an option to change a developed project's target framework version.
The same option is available in VS2010, but with one improvement. In the previous versions, if you create a project in framework 2.0, intellisense will still show you the types and members of 3.5 version as well, so there are more chances of error if you cannot identify the member of the chosen framework. But in VS2010, the intellisense will show you options for the appropriate framework only.
5. Multi-Monitor: - Visual Studio 2010 provides us facility to move windows of the IDE outside of the Visual Studio IDE and place them on the desktop area. It also supports having different IDE windows on multiple monitors. If we close Visual Studio and open it again, we will find all the windows on the same places where we finished them last time.
6. Code Navigation in Class Files: - A new Navigate To option gives us facility to search a term in a file more quickly. It searches the text as you type, but it works for class files only, i.e., it doesn't work for HTML or code-behind files. In the following example, it shows the function name as I type it in the Navigate To window; on selection of any, it will navigate to the function definition.

7. View Call Hierarchy: -This featrure helps to see the use of a function and its properties. For example, if you right click on a function name, it will show you the hierarchical list of function usage.
8. Code Identifier Highlighting: - On selection of an identifier, the IDE will highlight the places for you where it is utilized. For example, I selected variable i and it highlights the different places it is used.
9. Intellisense Improvements: - In VS2008, on selecting properties for an object, intellisense will show you the properties based on the alphabetical order as you type.
In VS2010, it shows you the properties based on groups. For example, if you type text for a text box, it will show you the members based on the word text, like Text, TextChanged, TextMode. It also supports Pascal case intellisense. For example, if you type TC, it will navigate to the TextChanged member.
10. EnablePersistedSelection: -On selecting a row in controls like DataList or GridView, if we move to another page index, it selects the same numbered row on the newly selected page, although we selected it only on the first page.
To avoid this, ASP.NET 4.0 has introduced a new property for these controls, called EnablePersistedSelection. If you set it to true, it will not select the same numbered row on other pages, and on navigation to the original page, for example, the first page, it will show the initially selected row as selected.
11. Web.Config Transformation: - Normally, we set some values in web.config for the development environment, and then we change those values manually at the time of deployment or testing.
For example, if we have a connection string or any key value combination in the web.config file, and we want to replace those at the time of project publishing or deployment, then we can use the new web.config transformation. It is an automatic way to perform this operation.
Web.config settings can be overridden by other config files like web.release.config, web.debug.config etc., at the time of debug, release. These values are not overridden in the original web.config but in the published web.config.
With the help of transformation, we can replace, remove, or delete a node, and for a node itself, we can remove or set attributes.
12. URL Routing: - Nowadays, we see that website URLs are more SEO specific and do not show any descriptive information. For example, rather than showing a URL like: http://mywebsite.com/userprofiles.aspx?userid=1, developers would prefer to show the URL as: http://mywebsite.com/mydetails.
URL mapping in ASP.NET 2.0 provides us an option to achieve this functionality up to some extent. We can mention exact URLs to navigate and URLs to show to the user. But in the case of postback, this option starts showing the actual URL in the browser.
URL routing was introduced in ASP.NET 3.5. Developers had to create different route handler classes depending on the number of URL routings for a website. The postback issue was solved with this URL routing option.
In ASP.NET 4.0, you do not need to define separate handler classes for each routing. There is a built-in helper function MapPageRoute which helps you to implement routing more quickly. These routes are registered on Application_Start. For example, in this example, in global.asax, the SetRouting method sets routing, the first parameter is the router's friendly name, the second parameter is to check for the URL pattern to match, and the third is the ASPX page where this functionality would be implemented for the users.
13. Add Reference Dialog: - In previous versions of Visual Studio, on opening the Add Reference dialog box, it will take some time to load .NET assembly files initially till the time it loads all the references from the GAC. In VS2010, on opening Add Reference, it opens the Projects tab by default.
If you click on the .NET or COM tab by mistake, you still have an option of canceling it before it loads all the assemblies. So, the VS IDE does not freeze like before.
14. Compressing Session Values: - ASP.NET session out-of-process state values are saved in a database or on the server. These are saved in a serialized format. Bigger session values consume more resources to be sent to the server. Now, those can be compressed with a new built-in property compressionEnabled. This attribute for the sessionState element can be mentioned in the web.config.

Scope of WCF Security and WCF Bindings and Behaviors

When you create an overall security policy – for example, transfer security with authentication and authorization for your services – you can use bindings and behaviors to configure the required settings.
Bindings and behaviors are described as follows:
• Bindings. Bindings control the security mode, client credential type, and other security settings.
• Behaviors. Service behaviors control impersonation levels, how client credentials are authenticated and authorized, and service credentials.
You can configure bindings and behaviors, or you can program against the object model. Your binding selection determines the available security options for WCF. The following table summarizes the most commonly used bindings in WCF.

Tuesday, November 30, 2010

Difference Between .net 2.0,3.0,3.5

.NET Framework 2.0
Released with Visual Studio 2005 , Microsoft SQL Server 2005, and BizTalk 2006.
The 2.0 Redistributable Package can be downloaded for free from Microsoft, and was published on 2006-01-22.
The 2.0 Software Development Kit (SDK) can be downloaded for free from Microsoft.
It is included as part of Visual Studio 2005 and Microsoft SQL Server 2005.
Version 2.0 is the last version with support for Windows 2000, Windows 98 and Windows Me.
It shipped with Windows Server 2003 R2 (not installed by default).
Changes in 2.0 on comparison with 1.1
Numerous API changes.
A new hosting API for native applications wishing to host an instance of the .NET runtime. The new API gives a fine grain control on the behavior of the runtime with regards to multithreading, memory allocation, assembly loading and more (detailed reference). It was initially developed to efficiently host the runtime in Microsoft SQL Server, which implements its own scheduler and memory manager.
Full 64-bit support for both the x64 and the IA64 hardware platforms.
Language support for generics built directly into the .NET CLR.
Many additional and improved ASP.NET web controls.
New data controls with declarative data binding.
New personalization features for ASP.NET, such as support for themes, skins and webparts.
.NET Micro Framework - a version of the .NET Framework related to the Smart Personal Objects Technology initiative.
Partial classes
Anonymous methods
.NET Framework 3.0
.NET Framework 3.0, formerly called WinFX includes a new set of managed code APIs that are an integral part of Windows Vista and Windows Server 2008 operating systems. It is also available for Windows XP SP2 and Windows Server 2003 as a download. There are no major architectural changes included with this release; .NET Framework 3.0 uses the Common Language Runtime of .NET Framework 2.0 Unlike the previous major .NET releases there was no .NET Compact Framework release made as a counterpart of this version.
.NET Framework 3.0 consists of four major new components:
Windows Presentation Foundation (WPF), formerly code-named Avalon; a new user interface subsystem and API based on XML and vector graphics, which uses 3D computer graphics hardware and Direct3D technologies. See WPF SDK for developer articles and documentation on WPF.
Windows Communication Foundation (WCF), formerly code-named Indigo; a service-oriented messaging system which allows programs to interoperate locally or remotely similar to web services.
Windows Workflow Foundation (WF) allows for building of task automation and integrated transactions using workflows.
Windows CardSpace, formerly code-named InfoCard; a software component which securely stores a person's digital identities and provides a unified interface for choosing the identity for a particular transaction, such as logging in to a website.
.NET Framework 3.5
Version 3.5 of the .NET Framework was released on 19 November 2007, but it is not included with Windows Server 2008. As with .NET Framework 3.0, version 3.5 uses the CLR of version 2.0. In addition, it installs .NET Framework 2.0 SP1, .NET Framework 2.0 SP2 (with 3.5 SP1) and .NET Framework 3.0 SP1, which adds some methods and properties to the BCL classes in version 2.0 which are required for version 3.5 features such as Language Integrated Query (LINQ). These changes do not affect applications written for version 2.0, however As with previous versions, a new .NET Compact Framework 3.5 was released in tandem with this update in order to provide support for additional features on Windows Mobile and Windows Embedded CE devices.
The source code of the Base Class Library in this version has been partially released (for debugging reference only) under the Microsoft Reference Source License.
Changes since version 3.0
New language features in C# 3.0 and VB.NET 9.0 compiler
Adds support for expression trees and lambda methods
Extension methods
Expression trees to represent high-level source code at runtime
Anonymous types with static type inference
Language Integrated Query (LINQ) along with its various providers
LINQ to Objects
LINQ to XML
LINQ to SQL
Paging support for ADO.NET
ADO.NET synchronization API to synchronize local caches and server side datastores
Asynchronous network I/O API
Peer-to-peer networking stack, including a managed PNRP resolver
Managed wrappers for Windows Management Instrumentation and Active Directory APIs
Enhanced WCF and WF runtimes, which let WCF work with POX and JSON data, and also expose WF workflows as WCF services.WCF services can be made stateful using the WF persistence model.
Support for HTTP pipelining and syndication feeds.
ASP.NET AJAX is included
New System.CodeDom namespace.