# Tuesday, March 25, 2008

This is quite strange story... but I decided to publish this post because I didn't find any proper solution anywhere; and I mean it ANYWHERE!

It begins like that: I am running an asp.net 2.0 web application that as part of its work, it has to communicate 3rd party assembly, which suppose to retrieve some validation data. Until here everything is just fine right?

In order to invoke the 3rd party service (using an API of course), there is a need to install a X509Cerificate with 'secret' password and to install it on the server that runs the web application. After doing it you must  impersonate the ASP.NET process with the logged-in user that installed the certificate in order to 'grant' this user permission (administrator) to the current context of the web application.

Note: the user credentials will be kept in the web application web.config encrypted of course.

When running this application in my dev box, everything was working just fine, but when done with unit testing and was ready to QA, only when the user that installed the X509Certificate was logged in to the system (windows) the access to this specific certificate could be done. When the user was logged off, the Initialize method that initializes the certificate, couldn't find it in the CurrentUserStore:

public void Initialize(some parameters...)
{
   X509CertificateCollection certificates;
   X509CertificateStore store = X509CertificateStore.CurrentUserStore("My");
   
   store.Open();
   certificates = store.FindCertificateBySubjectName("<subject>");
   if (certificates.Count <= 0)
   {
      throw new Exception("<message>"));
   }
}

I admit that I didn't have any clue of how solving this acute problem, which of course stuck all the process of dev.

After consulting with some colleagues, we decided to try a 'detour solution', that will raise the user up into the system (will keep it alive, unlike doing log off to the user that terminates it from the OS).

Finally the solution (what you've waited for of course): 

We created a blank window service (with an installer) that actually does nothing, complied it and installed it in the QA server. Now here is the catch: First, the window service's startup type is set to Automatically (will be started always when the OS is up). secondly we adjusted the service's log on to a specific account that held the credentials of the user that installed the certificate of course. The purpose of this action is to keep this user up all time in order let our 3rd party application find its certificate in its store.

Outcome - it is working smoothly like magic. We can continue working...

Tuesday, March 25, 2008 8:49:00 PM (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Thursday, December 13, 2007

The reason I published this post is because I didn't find any result when googling the error description and solved it myself at last.

If you're asp.net developers you probably know the ObjectDataSource object, which represents a business object that provides data to data-bound controls in multi-tier Web application architectures.

I like this object, most of the time this object can solve you all the annoying steps logic of calling the BL/DAL object in order to retrieve the data and populate the wanted presentation control.

On one of my working on website's pages (which is quite complex one that knows to list data from several sources and procedures), I am using such of object as a data source in the main GridView that renders a list of records. In order to interact with each different select method I had to set every time the SelectMethod property and it's specific parameters in the code-behind. Until now everything is just fine...

It seems that working this way affects the other postback events on the page, (because after event postback, the OnInit and OnLoad events are being called first and just after it the event handler itself is being called), here my page was crashed and gave this error message: "The Select operation is not supported by ObjectDataSource '<objectdatasource_id>' unless the SelectMethod is specified."

This error caused because the page expected the SelectMethod property to be initialized between the OnInit and OnLoad methods and just after it the rest of the events.

The resolution is quite easy in this case;

First, you need to remove the ObjectDataSourceID property definition from the control properties' definitions layout in the control source and set the DataSource for the control to the desired one in the OnInit method. After it, in the OnPreRender method call the control's DataBind method in order to bind the data source. This last action will allow to any event to happen and just after it to set up the Control (the GridView in my case) with data.

protected override void OnInit(EventArgs e)
{
   base.OnInit(e);
   MyGridView.DataSource = MyObjectDataSource;
}

protected override void OnPreRender(EventArgs e)
{
   base.OnPreRender(e);
   MyGridView.DataBind();
}

I hope it'll help anyone...

.NET 2005 | ASP.NET | Bugs | C#
Thursday, December 13, 2007 1:02:19 AM (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Monday, October 15, 2007

As you know (if you're checking up this blog once on a while) or now, I am leading the technologic part of an application that we're working on the last 6 months, and this application (web) is multi-lingual.

The case: In order to read properly some configuration to the application, we are using an XML that represents some flow steps, for example:

<activePages>
   <page url="<some url>" ordinal="1" isInitial="true" />
   <page url="<some url>" ordinal="2" />
   <page url="<some url>" ordinal="2.1" type="US" />
   <page url="<some url>" ordinal="2.2" />
</activePages>

This XML structure is being read into an object that need to be saved in the application output cache for further usage. As you can see, the 'ordinal' field need to be converted into a double (or float) member in the cache's memory object.

While doing some Unit Testing on the application and changing the culture on runtime into French (or other European Language), the XML read action was failed and threw an exception.

Is'nt it Strange? In fact no!
After some googling I found that the European cultures/ languages numeration syntax is different than the US of the Hebrew, for example 1.1 will be written as 1,1 using the European language.

At least (as an addition to the bug resolution) I learned something new regarding enumeration... ;)

Bugs | C#
Monday, October 15, 2007 12:14:56 PM (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Monday, October 8, 2007

I wouldn't call it a problem/error/bug/you can call it how you want, I'll call it a moment of idiotic lack of attention?

I struggled with a very common problem (it seems to be a common after some googling): "My Global.asax events are not being constructed/called - what should I do?"; this one was so familiar and I was sure that I've done everything like it has to be, so again what was it?

Finally I figured out my problem myself and was supprised of it (I'm seriously not jocking), the Global.asax file was not placed under the root folder of my web application (my web aplication structure is quite 'complex' because it suppose to serve many web sites that sits also in the same solution). I replaced it in the right folder (the one that the IIS is pointed to) and that's it.

I think that post can solve to (starter?) web developers this (common?) problem while it occurs, because google's results didn't supply very good solutions for this one.

What aobut me? Even after developing and designing many web applications, things like that could happen to anyone :-S

ASP.NET | Bugs | Life
Monday, October 8, 2007 2:42:52 PM (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Monday, August 6, 2007

Post Prolog: Out of the record, as a continues to the previous post, I want to say that I am enjoing my life as a father, if I had know it I would do it earlier, BTW the little one named by my wife and me as Ori. More pics will be publish soon...)

Now, to this post issue...

I bumped in on a strange scenario; In my current working application, I have a page that holds a repeater that displays some data. This data is being declared in each partner's web.config's configSection. In order to read it once, I set this custom object as a Serializable one (which implements the ISerializable interface of course) and saved it into the ViewState of the page.

Now, when reading this object and saving it into the ViewState, everything has worked just fine (the server serialized this data properly).
But, when trying to grab this data from the ViewState (de-serialize this data) an annoying and vauge error message has been displayed was saying that: "The state information is invalid for this page and might be corrupted".

After a long and frustrating research about it, it turns out that the server will have NO KNOWLEDGE of the assembly name (Note: It was randomly generated when your site compiled on first run) because its own version of that assembly will have been compiled with a completely different random name, and it will not be able to de-serialise the viewstate and get the requested data.

To get around this problem, we should AVOID PLACING custom types into the viewstate (place'em somewhere else, like session, application etc.).

If you've got some more complex objects (or some custom types), these will need to be moved into a seperate class library project that is pre-compiled before deploying to the web-server. By doing it, it can be ensured that every web server has a copy of the same assembly and that the assembly has the same signature/name!  Try to avoid creating custom types in your App_Code or any of your web site files.  Rather create custom types in their own project to be compiled into a seperate assembly.

Cheers by now...

Monday, August 6, 2007 2:25:07 PM (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Sunday, June 3, 2007

I had installed the AJAX extesions framework on my computer in order to assimilate it in my web application that I am working on right now. I added some AJAX controls such as <asp:ClientScript>, <asp:UpdatePanel> and more, and damn... I find that the markup intellisense no longer works for these controls, or for any controls nested within them.

This happens because my ClientScript control is defined in the master page, and when I tried to drag (create) some other AJAX control in the other aspx pages that inherits the master page, the intellisense was lost.

I found a great solution/trick in ScottGu's Blog, that says that in order to see that intellisense in the rest of aspx pages, we need to leave the master page designer open (isn't it little bit ackward?)

For some more information and tricks (in ScottGu's Blog) you can click here.

AJAX | Bugs
Sunday, June 3, 2007 3:01:56 PM (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Thursday, May 31, 2007

I am working now on a large web application, that need to be used by more than one websites (at least 5 of them, websites and web services), therefore I have needed to do some isolating here with my main core projects.

Some background...
I have a common assembly (web application) that holds only the user controls, server controls and custom controls, which need to serve the all other web applications that are using them. This assembly has a reference to the other web application in order to have some information about some properties, session variables and global members, by this information, it knows to gereate some actions on runtime (or even in design). BUT, in the other hand, this web application need to use the controls that the first assembly has published, here we have a problem, we got a circular references, which is now allowed in .NET framework, also it isn't allowed anywhere I think...

So, how we gonna solve this problem?

The solution is quite simple and is known as Seperate Interface Pattern. (Click here to get some more info).

The main steps to implement it are:
Let define a project that called ProjectA and holds the user controls (etc...) implementations along with InterfaceB. ProjectA would maintain a reference to InterfaceB, which will hold any properties such as members, methods, events etc...

Now, lets define ProjectB which will implement InterfaceA. Now, ProjectB would reference ProjectA and (BUT) ProjectA would not reference ProjectB of course.

The result, ProjectA can access to ProjectB's specific exposed members and ProjectB can use the controls of ProjectA.

.NET 2005 | Bugs | Code | Patterns
Thursday, May 31, 2007 2:26:25 PM (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback
# Saturday, July 8, 2006

Hello all!

I know that I didn't write for a long time, this is because I am very busy these days. In work, we are at the end of a big web application project, and the stress is start to overflow. At home, I am also working on my own project (Haverut.co.il, if you forgot or didn't know), but this Saturday, I decided to share a problem that I had encountered it while working at home with Typed Datasets to connect and retrieve data from the database.

I am developing my website project under Visual Studio 2005 and SQL Server 2000 (this is because my web-hosting server is supports only SQL Server 2000). When I had installed VS. 2005, SQL Server Express 2005 had automaticlly been installed, this situation created 2 versions of SQL server databases.

Now to the BUG...
When I had tried to debug a flow that connect to the DB and grab some data from it, the application had been crashed on run time error and the exception sayed: "Unable to connect to debugger on 'COMPUTERNAME' (Error = 0x80070057). Ensure that client-side components, such as SQLLE.DLL, are installed and registered on 'COMPUTERNAME'. Debugging disabled for connection 51."
Very annoying bug, firstly because I didn't encountered it before and basicly because there is no troubleshooting tips at Microsoft help & support (you can see it yourself here).

Microsoft are saying that because the 2 different versions of SQL Sever on the computer, the T-SQL debugger uses the SQL startup account of the default instance (which is SQL 2005 Express edition) and it doesn't appropriate the SQL Server that I am working with (which is SQL 2000).
After long seeking for a resolve in the web I didn't find anything, so firstly I uninstalled SQL Server 2005 Express from the computer - it didn't helped much, and after long combinations and attempts I decided to install again SQL Server 2000 SP 3... I returned to the application, debuged the specific flow and a MIRACLE - it worked...

Now I can continue working on my Haverut.co.il web site (evetually...). So, if you have any questions about it or some comments I will glad to hear.

Now I am going to enjoy my Shabbat vacation in a trek in Zavitan water fall with my wife and good friends, be well...

Saturday, July 8, 2006 11:34:22 AM (Jerusalem Standard Time, UTC+02:00)  #    Disclaimer  |   |  Trackback