Friday, April 26, 2013

RegisterArrayDeclaration

I would like to use ClientScript.RegisterArrayDeclaration to declare an array in client side.So that, it looks like following code.
Client side:
var CheckBoxIDs = new Array(
'ctl00_MainContent_GridViewList_ctl02_CheckBoxItem', 
'ctl00_MainContent_GridViewList_ctl03_CheckBoxItem', 
'ctl00_MainContent_GridViewList_ctl04_CheckBoxItem', 
'ctl00_MainContent_GridViewList_ctl05_CheckBoxItem', 
'ctl00_MainContent_GridViewList_ctl06_CheckBoxItem');

Server side:
ClientScript.RegisterArrayDeclaration("CheckBoxIDs ", checkboxID);

It works fine. However, I need to add elements into the array dynamically. Instead of using ClientScript, ScriptManageer should be used this time.

ScriptManager RegisterArrayDeclaration

Wednesday, April 24, 2013

SerializationException: VewState

In order to save temporary data within a .aspx page, ViewState is my choice.  The data is a List of custom object.
ViewState["TempData"] = new List<ABC>();
Unfortunately, it throws an SerizationException. This error message shows that the class is not serializable. After I add "[Serializable] "  to the class, the problem is solved. But, I don't know why the class needs to be serialized. 

This issue is related to how ViewState packs data into a hidden field. ViewState serialized data into based 64 string and then stored into hidden form field. Later, page can get back state data by deserialized the hidden field.


Understanding ASP.NET View State
[ASP.NET] 利用ViewState保存自訂物件

Wednesday, April 17, 2013

Allow Remote WMI connection in Windows Servers 2008 R2

I wanna a C# program to get disk space of a remote server whose OS is Windows Server 2008 R2. The program and the server are under different domains. I use server's domain account to authenticate the connection. 

Unluckily, the most different part of this task is the configuration of enabling remote WMI connection, not the program to get a disk space. Two error codes:  

=> The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)  
=> Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))  

I have spent much time on the first one and it seems there are some thing wrong with my config. Here are some steps I still remember:

1. Allow WMI to communicate through firewall



2. Enable "remote launch" and "remote activation" in Access Permission of Component Services



3. Enable "remote access" in Access Permission of Component Services



4. Enable "remote enable" in WMI Control Properties



You can simply test WMI connection by using wmic command
wmic /node:localhost /user:administrator /password:1234 bios get serialnumber