戰地連結︰ Home My Flickr NBA.com About

2009年7月22日星期三

Installing Driver for Legacy Network Adapter on Win2k3 x64 VPC (Hyper-V)

Overview

I installed a 64-bit Windows 2003 R2 Enterprise SP2 on one of my Hyper-V VPC, and add a Legacy Network Adaptor to it. However the network adapter is not automatically installed in the x64 win 2k3 because its driver is not available.

With some Googling I found that 64-bit version of win 2k3 and xp are not supported with corresponding Legacy Network Adaptor driver. Someone suggested a workaround by using the equivalent Vista driver (both x86 and x64).

So I go the driver files from a machine running on x86 Vista and tried it. But the driver installation terminated with Error: "Driver not intended for this platform".

Suspecting this maybe due to the x86/x64 difference, I got another set of driver files from a x64 Windows Server 2008. This time the driver installation ran smoothly and the Network Adaptor works well!

Directory containing Legacy Network Adaptor driver:

Vista:
%windir%\system32\driverstore\FileRepository\dc21x4vm.inf_7d8c6569

Windows Server 2008:
%windir%\system32\driverstore\FileRepository\dc21x4vm.inf_e14caac7

Reference

Windows XP x64 in Hyper-V - Network Drivers

2009年7月20日星期一

ASP.NET User Control - Part 1

Overview

User Control is quite useful in creating a customized control which can be reused throughout pages. Instead of creating a custom server control, developers can create user control which (in my opinion) is easier to create and modify the control layout.

In this part, I will talk about how to create a user control and include it in an .aspx page.

Reference

ASP.NET User Controls Overview

How to: Include a User Control in an ASP.NET Web Page

Steps

Create a User Control

Creating a user control is very simple with few steps:

  1. You need to have a Web Application Project
  2. In Solution Explorer, right-click on the project's name (or a folder), select "Add" => "New Item..."
  3. Select "Web User Control" under "Web" category, give the control a name and click "Add"
  4. Done!

The newly created user control consists of a .ascx (not .aspx) page and a code behind file (just ignore the designer file). The .ascx page currently contains nothing but a "@ Control" directive.

User control .ascx page is very much like a snippet of an .aspx page, you can modify the layout of the user control by adding HTML tags or ASP.NET controls in it just like what you do to .aspx page. Below is the code of a very simple .ascx page:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestUserControl.ascx.cs" Inherits="MyTestWeb.Web.Controls.TestUserControl" %>

 

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

<asp:Button ID="BtnSubmit" runat="server" Text="Submit" />

 

Include a User Control in an .aspx page

After a User Control is created, it can be used by any .aspx page within the same Web Application by including the control into the page.

To Include a User Control, we have to do 2 things:

  1. Create a "@ Register" directive which specify the "TagPrefix", "TagName" and "Src" (Source file) of the User Control.
  2. Declare the User Control with tag "<TagPrefix:TagName   />" just like any other ASP.NET control (the difference is ASP.NET Control start with TagPrefix "asp")

Below shows the code of a simple .aspx page including the User Control we just created.

<%@ Page Language="C#" MasterPageFile="~/Pages/Global.Master" AutoEventWireup="true"

    CodeBehind="TestPageWithMaster.aspx.cs" Inherits="MyTestWeb.Web.Pages.TestPageWithMaster"

    Title="Untitled Page" %>

 

<%-- "@ Register" directive --%>

<%@ Register TagPrefix="uc" TagName="TestUserControl" Src="~/Controls/TestUserControl.ascx" %>

 

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <form runat="server">

 

        <%-- User Control declaration --%>

        <uc:TestUserControl ID="TestUserControl1" runat="server" />

 

    </form>

</asp:Content>

2009年7月8日星期三

Client side validation skipped if submit Button have "onClientClick" JavaScript function

Overview

I have a form using ASP.NET validation controls, I have been using these ASP.NET validators for quite a time and they behaved well. However the problem come when I added a "onClientClick" event handler to the form submit button, and then the validation is just skipped and the form post back every time.

The problem is that the "onClientClick" event get fired before the validation so the validation is skipped. To solve this, we can use the JavaScript function "Page_ClientValidate()" to trigger the client side validation.

Reference

asp:Button Validation with OnClientClick javascript - Not Validating

ASP.NET Validation in Depth

Code Snippet

You can tell "Page_ClientValidate()" to only validate controls of a particular validation group by passing the validation group name as parameter.

function BtnSubmitButton_click()

        {

            if (Page_ClientValidate("ValidationGroup"))

            {

                return confirm("Submit this form?");

            }

            return false;

        }

2009年5月29日星期五

Moved files cannot inherit destination folder's permission, but copied files can.

Overview

When I want to share a file with others in the same network, I move the file to my shared folder. However, sometimes I receive complains from my colleagues saying that they don't have permission to read the shared files.

At the end, I found that a copied file can inherit the permission of the destination folder, but a moved file cannot. I think that it is because the copy action create a new file while the move action (within same volume) only change the hosting folder of the original file.

With some googling, I found that this behaviors is documented by Microsoft. The article also provide a way to change this behavior by modifying registry.

Reference

How permissions are handled when you copy and move files and folders

Step

Let moved files inherit destination folder's permission like copied files

  1. Run "regedit" (Fire up Registry Editor)
  2. Go to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer"
  3. Add a "DWORD" value with name "MoveSecurityAttributes" and Value "0"

2009年5月19日星期二

Using mdev of busybox

Overview

mdev is a device manager like udev, actually it is a "mini udev". mdev is very useful in embedded system as it is included in newer version of busybox. mdev can also shorten boot up time significantly compared to udev. This can be vital to some embedded system.

Below shows a sample startup script for mdev.

Reference

mdev – mini udev in busybox

mdev的使用方法和原理。

Code Snippet

Here is the startup script I used:

#!/bin/sh

echo "Mounting sysfs"
mount -t sysfs sysfs /sys

echo "Mounting /dev"
mount -t tmpfs mdev /dev

echo "Creating /dev/pts"
mkdir /dev/pts

echo "Mounting pts"
mount -t devpts devpts /dev/pts

echo "Echoing hotplug"
echo /sbin/mdev > /proc/sys/kernel/hotplug

echo "mdev -s"
mdev -s

2009年5月17日星期日

Create Private Network for VPCs with Microsoft Loopback Adaptor

Overview

If you want to add your VPCs into a network so that they (and your host machine) can access other via TCP/IP, what will you do? You can assign your physical network adaptor to VPCs so that they will be on the same network as your host machine, but first you need a DHCP server, and all your VPCs will be exposed to external.

Indeed you can use "Microsoft Loopback Adaptor" to add a virtual network adaptor to your host computer. Then you can assign the Loopback Adaptor to your VPCs to form a Private Virtual Network, so that each VPC can communicate with each other and host machine, but not accessible by external computers.

Reference

Install Microsoft Loopback Adapter

Using Microsoft Loopback Adapter

Virtual PC IP Routing: enabling VPC NAT & loopback connector at the same time

Step

To Install Microsoft Loopback Adaptor

Adding Microsoft Loopback Adaptor is like adding a new hardware in Windows. This part is copied from Reference 1.

  1. In the host operating system, right-click My Computer, and then select Properties. Depending on the style of the start menu, My Computer may be located in the Start menu.
  2. In the System Properties dialog box, on the Hardware tab, click Add Hardware Wizard.
  3. In the Add Hardware dialog box, click Next.
  4. When the Is the hardware connected? dialog box appears, click Yes, I have already connected the hardware, and then click Next.
  5. In the Installed hardware list, click Add a new hardware device, and then click Next.
  6. In the What do you want the wizard to do? list, click Install the hardware that I manually select from a list (Advanced), and then click Next.
  7. In the Common hardware types list, click Network adapters, and then click Next.
  8. In the Manufacturer list, click Microsoft.
  9. In the Network Adapter list, click Microsoft Loopback Adapter, and then click Next twice.
  10. If a message about driver signing appears, click Continue Anyway.
  11. In the Completing the Add Hardware Wizard dialog box, click Finish, and then click OK.

To assign Loopback Adaptor and corresponding IP to each VPC

After you installed the Loopback Adaptor, you should see a new network connection in "Network Connections" screen of the host computer. Right-click on the Loopback Adapator network connection and select "Properties". In the "Microsoft Loopback Adapter Properties" dialog box, verify that the "Virtual Machine Network services" check box is selected. Now the VPCs can be assigned this adaptor in VIrtual PC settings.

  1. Start Virtual PC 2007.
  2. Right-click on your target VPC and click "Settings".
  3. In the "Settings" dialog box, select "Networking" in the "Settings" list, then select "Microsoft Loopback Adaptor" for the network adaptor. (I would suggest assigning the second network adaptor to Loopback Adaptor as we want to reserve the first one for "Shared networking NAT")
  4. For assigning IP, just treat it like other physical network and set the appropriate IP and netmask. Leave the Default gatway blank for the Virtual network

Configure firewall and test the network

At this point each VPCs should be able to "see" and ping others and the host. However the firewall settings on them may block the connection. You can disable windows firewall for the Loopback Adaptor to solve this problem:

  1. On your host computer, go to "Windows Firewall"
  2. Select "Advanced"
  3. Uncheck the network connection (in this case, the "VPC Virtual Network") that you don't want firewall to monitor.
  4. Click "OK".
  5. Repeat 1~4 on every VPCs.

blog170520091

2009年4月7日星期二

Writing, Starting and Stopping Linux daemon (w/ start-stop-daemon)

Overview

The first page written by Devin Watson shows a tutorial on how-to write a daemon (with an example). The second one at Tony's Cafe shows how to write scripts for Debian Linux to run the daemon. The last one is the Manpage of "start-stop-daemon" program.

Reference

Linux Daemon Writing HOWTO

Creating a Daemon in Debian Linux

Manpage of START-STOP-DAEMON