Leon

Developer Academy II - LINQ Presentation

Last week, at second anual Israeli Dev Academy conference, I gave presentation about LINQ.I was very lucky to have huge (in Israeli scale :-)) and very enthusiastic croud. My goal was to pass a couple of important LINQ related ideas:

  1. LINQ is not a new OR mapper or API to deal with XML
  2. LINQ is all about having best of two worlds: Objects and Data
  3. LINQ changes the way you write code
  4. You can get fare performance with LINQ

You are welcome to download and use presentation slides and demos. You will need VS2008 RTM to run demo solution. You can download VS2008 trial version from here.

ASP.NET Ajax Extensions Overview Slides & Demo
Slides and Demo solution from "ASP.NET Ajax Extensions Overview" presentation, I gave recently for Israel Electric Corporation, available for download here. Enjoy!
ASP.NET Login Control & ReturnUrl Problem

I was surprised today by an odd behavior of Login control. When browsing some pages in my web site that required authentication, I was redirected to the Login page, but then, after successful login, I was redirected to the page, specified by DestinationPageURL property of Login control (instead of original URL). I went to investigate. Here are the results:

First of all Login control standard behavior:
If the user browse the Login page directly, after login, asp.net will redirect the user to page which is defined by DestinationPageURL property. If the DestinationPageURL property is empty, the default value is default.aspx. If the user browse another page but is redirected to the Login.aspx for being not authorized, then after login, asp.net will redirect the user to page which the user originally wants to access. In this situation, DestinationPagURL property is ignored. Login control uses ReturnUrl query string parameter to locate original page.

The situation on my site:
It is a bit more complex. The site actually has two completely different login pages. One of them defined as Login page in Web.config. In some cases users (depending on referrer and cookies) redirected from main login page to the secondary login page, which also has Login control.
It appears that Login control behaves slightly different in this scenario. If page is not defined as Login page in configuration file, ReturnUrl parameter is ignored completely. Login control try to redirect user to the page specified by DestinationPageURL property. If DestinationPageURL property not set, page that hosts Login control simply being reloaded, using the same URL.
Knowing all this, the solution come easily:

On the secondary login page I add flowing lines to the Page_Load method:

string returnUrl = Request.Params["ReturnUrl"];
if (!String.IsNullOrEmpty(returnUrl))
    Login1.DestinationPageUrl = returnUrl;

TFS Setup and SQL Server Collation Limitations
Team Foundation Server has some limitations on SQL Server collation it can use. You can face this problem when trying to setup TFS with existing instance of SQL Server. See whole description of the problem and solution here.
Local Resource Generation and Orcas Beta2

There was an issue with local resources generation in Orcas beta1. Each time we tried to perform "Generate Local Resource" for web page, A resource writer could not be found." message was shown in output window and nothing was generated. You can find reference to this problem here and here. This was not a critical issue for beta1 product stage IMHO. Now, in beta2 it gets better. Local Resource Generation option finally working fine in VS2008, but... After beta2 setup on my machine, the same problem found its way into VS2005! For those who have the same problem, or would like to recreate and investigate: I have side by side installation of VS2005 and VS2008 beta2. There were no previous Orcas builds installed on this box.

By the way, beta2 looking very cool and this is the first real issue I have after installation 10 days ago.

Dynamic Application Configuration in .NET Applications

We have couple of choices to work with application in .NET 2.0:

Pros Cons
appSettings section in standard configuration files Simple existing API, changes in web.config immediately reflected in application Cons: name-value string pares only can be stored, application need restart to accept external changes
Custom configuration sections Can store complex data Should be implemented for each configuration structure, implementation is not very intuitive, application need restart to accept external changes
applicationSettings section & Settings files Standard API, built-in (in VS2005) editor for simple types, support for design-time binding, writable from application code, complex types can be stored in ArrayList Limited supports for complex types, application need restart to accept external changes

Challenge

So what would I like to have?

  • I want to store and retrieve from configuration store arbitrary class.
  • If configuration changes between two subsequent attempts to configuration, later access should reflect changes.
  • I am too lazy to build implementation for each class, I'll have to store.

Solution

Solution based on using XML configuration file in any convenient schema. Configuration consists of classes that represent data, stored in configuration file and manager which is responsible to store, retrieve and cache configuration data. Manager uses simple XML serialization/deserialization to read/write data. Configuration file path stored in standard application configuration file. System.Web.Caching.Cache used to cache configuration data.

And what about implementation? To address my laziness problem, I built simple utility to generate the whole implementation from XML configuration file. All you need is supply configuration file path, output directory and desirable namespace. You can download result of this exersise here.

Read the whole article on codeproject.

How to Specify Specific Language for Localization

ASP.NET 2.0 infrastructure uses provider architecture in conjunction with local and global resources to support localization. Provider architecture gives us option to replace default resx (XML) resources, used to store localized data, with anything else (database for example). Global resources provide us with auto-generated, strongly-typed API to access application wide resources. Local resources can use implicit and explicit binding and have nice “Generate Local Resource” (Tools>Generate Local Resource in Visual Studion) option to generate default resource file for current page and inject implicit binding. See Web Pages Resources Overview in MSDN for more.

Localization provider uses current culture information to select appropriate resources to be served. How can we specify language to be used? We have couple of choices:

  • As I already mentioned, by default, localization provider will use current thread culture information. This culture determined by request header Accept-Language. Value of this header is set by browser. For example, in IE accepted languages could be configured through Tools>Internet Options…>Languages. It is not a very user friendly option, especially in multilingual country like ours.
  • In case no specific language was specified by browser, default culture can be set in Web.Config file, in globalization element.

    <globalization uiCulture="he" />

  • At the page level, you can set culture in <@ Page pragma in aspx file. This definition will supersede those sent by browser and defined in Web.Config.

    <%@ Page Language="C#" UICulture="ru"

  • Finally, culture can be set in codebehind: All subsequent calls to resource related API (GetLocalResourceObject, GetGlobalResourceObject) will be affected. Here is the catch: to influence implicitly bounded (using meta:resourcekey) to local resources attributes, you have to set uiculture in InitializeCulture page method override.

    protected override void InitializeCulture()
    {
          this.UICulture = "he";
    }

    Culture, set in code will override all previous definitions.
Microsoft Developer Academy Event Survey
Microsoft Developer Academy event will take place at January 31. It should be highly technical event. You can see the list of proposed lectures in this survey. It is your opportunity to vote for the topics you are most interested in. Fill free to make any suggestions or propose topics that are not on the list.
ASP.NET AJAX 1.0 RC Released

ASP.NET AJAX (formely Atlas) RC released during this weekend. Like previous versions it is available in 3 parts:

Practical Advanced ASP.NET 2.0 Presentation & Demo
Following one day training I did during MVP week, I packed PowerPoint slides together with all demo code. You can download it from here. PowerPoint 2007 presentation is inside. Fill free to reuse it as you like.
Our Team System Blog
Our group, which specilised in Team System consulting and implementation finaly start to blog. From now on I will post my VSTS related entries there. And today, read VSS to Team System Migration Checklist.
InteropForm Toolkit - .NET - VB6 bridge part 2
Ok, as promised, I finished C# project and item templates to be used with Interop Form Toolkit. In addition I extended Interop Wrapper Add-In to support C# code generation. You can download template, Add-In and full source code from here. I'll be glad to here what do you think.
InteropForm Toolkit - .NET - VB6 bridge

Do you have existing VB6 system?
Would you like to gradually migrate them into .NET world?
Can you afford "all or nothing" migration?

After a long period of talking and expectation Interop Form Toolkit is finally released. It is VS2005 Add-In together with project template and documentation, which allows an easy creation of mixed VB6/VB.NET application. Toolkit automates interop objects generation and provides an easy way of VB6 - .NET communication through events and shared state. Toolkit is surprisingly fare documented and came with two sample project.

After couple of hours playing with new toy, one thing I could not understand is "why it supports VB.NET only?" It happens that I personally prefer C# these days... So with a little help of my File Disassembler buddy I translated project template into C#. Existing Add-In generates wrapper classes in VB.NET, and it should be translated also. Now I have simple, fully functioning, combined C#-VB6 sample. It is about 2:30 in the morning on my clock, so I'll recreate Add-In tomorrow (and will, hopefully, post it along with C# project template).

Atlas Control Toolkit Refresh Released
First refresh of "Atlas" Control toolkit is out. You wiil found four new controls there, some new helpers and fixes. You can download it from here. Go for it!
Atlas Controls Toolkit Next Drop on Its Way
Next version of Atlas Controls Toolkit will be out (probably) during next week. It will include Safari support, existing controls improvement and new extenders. Thanks Shawn for update (teaser :)).
More Posts Next page »