WinCE: Allow accessing a web site by specified network interface

Our device has two network interfaces, LAN1 and LAN2. We need to restrict our access to the web site to one of these two network interfaces. In the WinCE WebAdmin interface, looks like that we can control it by changing the enable/disable status of a network interface. However, by changing that option we can't successfully reach our goal.

After some tries, we come out with a solution to do this. Below are some key points:
  1. Turn off "Allow default site" option in Default Web Site to disallow unmapped requests to be redirected to the Default Web Site
  2. In registry, delete the key of "NetworkInterfaces" of our target Web Site
  3. For target Web Site, set the key "HostedSites" to the IP of the network interface you allow to receive requests. For example, to allow LAN1 (192.168.123.100), we set it to "192.168.123.100;". To allow LAN1 and LAN2 (192.168.123.101), we set it to "192.168.123.100;192.168.123.101"
Our app needs to change the value of "HostedSites" key on the fly once user changed the setting. We have to restart the Web server in the app to take the change into effect:


BOOL restartWebServer()
{
PROCESS_INFORMATION ProcInfo;
const TCHAR ServicesExe[] = _T("\\Windows\\services.exe");
const TCHAR Arguments[] = _T("refresh HTP0:");

return CreateProcess(ServicesExe, Arguments, NULL, NULL, NULL, 0, NULL, NULL, NULL, &ProcInfo);
}

留言

熱門文章