August 2007 - Posts
Slides and Demo solution from "ASP.NET Ajax Extensions Overview" presentation, I gave recently for Israel Electric Corporation,
available for download here. Enjoy!
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;
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.
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.
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.
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: