Friday, 30 July 2010

Random information on Silverlight

Just want to document two things I came across yesterday.

First one is an error:

This morning one of my colleague try to check out my application and try out. They were able to compile successfully and when he ran the application, he got an error

WCF RIA services will fail unless the silverlight project is hosted in and launched from the same web project that contains the WCF RIA services

This happens when you have you silverlight application (client side) set as the startup project. All you have to do is set web as the start up project and assign the .aspx or .html as the start up page and you are all set.

Second one is tip:

I have created a simple application which consumes a model set to connect to a database. Which worked fine. Now I have to change it to a different data base to do some volume testing. That data base has same table and scheme etc., To do that for your testing purpose, simply go to web.config on the silverlight web project and change the initial catalogue. This is for ad-hoc testing but if you would need to do more frequently, then do it in the server side code based on some parameters.

Friday, 23 July 2010

How to Secure a Wireless Network from Hackers?

The reason we secure a wireless network is to stop people from using the services of our network who don't have permission to utilize them. It is harder to secure a wireless network from hackers as compared to a classic wired network. This is due to the fact that a wireless network can be accessed anywhere inside the range of its antenna.
In order to secure a wireless network from hackers, we should take proper steps to save ourselves against security issues. If you don't secure a wireless network from hackers, you might end up without its service. The consequence might also include the utilization of our network to attack further networks. To secure a wireless network from hackers, you should follow these simple wireless networking tips:
1.       Strategic antenna placement:
The first thing you have to do is to position the access point's antenna in a place which restricts the range of its signal to go further than the required area. You should not put the antenna close to a window because glass can't obstruct its signals. Place it in a central location of the building
2.       Use WEP:
WEP stands for Wireless encryption protocol.  It's a customary technique for encrypting traffic on a wireless network. You should never skip it as that will allow hackers to get instant access to the traffic over a wireless network.
3.       Change the SSID, disable the broadcast of SSID:
SSID stands for service set identifier.  It is the recognition thread utilized by the wireless access point due to which the customers are capable of starting connections. For every wireless access point arranged, select an exclusive as well as unique SSID. Also, if it's attainable, hold back the broadcast of the SSID out over the antenna. It won\t appear in the listing of offered networks, while being able to provide services as usual.
4.       Disable DHCP:
By doing this, the hackers will have to decode the TCP/IP parameters, subnet mask as well as the IP address in order to hack your wireless network.
5.       Disable or modify SNMP settings:
Change the private as well as public community settings of SNMP. You can also just disable it. Otherwise the hackers will be able to utilize SNMP to get significant info regarding your wireless network.
6.       Utilize access lists:
For additional security of your wireless network, and if your access point support this feature, employ an access list. An access list lets us determine precisely which machinery is permitted to attach to an access point. The access points which include the access list can employ trivial file transfer protocol (TFTP) now and then in order to download modernized lists to steer clear of hackers.

Thursday, 22 July 2010

Using LightTPD with XAMPP on windows

I recently setup LighbetTPD on my machine because there is a need for me to use LightTPD server to achieve a video delivery with HTTP Pseudo-Streaming.  I decided to install it on windows since I use windows more often for development. The H264 streaming module works well on Apache but I am working more with the FLV streaming module which works well on LightTPD. I once tried installing mod_flvx.c on RH5 for Apache but it seems not to work well for me.

I had to dive into LightTPD and I think it’s a great decision. Prior to the installation of LightTPD on windows, I use the Apache on XAMPP as my web server. So, I will like to show you how I use the PHP (and MySQL – this will work well anyway, as far as the service is running) in XAMPP for LightTPD. You may be thinking; “why would you wanna do that since there is a WLMP webserver package that has all in one?”. Well the answer is: “I want to keep my Apache server and I don’t want to have two MySQL server or have two instance of php.ini file”. So follow this simple steps:

Firstly, download the Win32 version of LightTPD from the WLMP Project; I prefer using the win32 version, you can use the .zip one if you want to.

Double-click on the downloaded file to install LightTPD on windows. By default, the installation directory is “C:\Program Files\LightTPD” but I mine was installed in D:\LightTPD since my XAMPP is in the same D:\ drive.

After completing the installation, you will need to start the server by going to the LightTPD directory and look for the file ‘TestMode.bat’. Double click on it to start the server; a console window opens to indicate the server has started successfully. If you have port 80 in use, you will come across an error saying: can’t bind to port: 80 Address already in use. The default server.port on LightTPD is 80. Since my Apache is runing on port 80, I will have to modify the lighttpd-inc.conf file for LightTPD to work with an alternative port like 81 or 8080.

Open [LightTPD-Directory]\conf\lighttpd-inc.conf, remove the comment for server.port = 80 and modify the value to whatever port you want to use; as far as it’s not in use. Mine is server.port = 81. Save and run the ‘TestMode.bat’ again. If everything is set properly, the server will start.

Navigate or point your browser to http://localhost/ or to see if LightTPD server is working.

Now you will have to configure the lighttpd-inc.conf to work with PHP. The PHP I used is actually that of XAMPP as I mentioned earlier. So modify cgi.assign value to “.php” => “D:\xampp\php\php-cgi.exe” [D:\xampp\ should be your XAMPP installation directory]

Modify other necessary lines you will/might need.

mod_flv_streaming is need (by me)
mod_rewrite is so need ( by me )
and so on.

To avoid the cygwin warning seen earlier, set the server.document-root value to have a forward slashes without the D: or C: as in “/Inetpub/wwwroot/”

After all modification, save the file; press Ctl+C on the console window to shutdown the server and re-launch, i.e double-click on ‘TestMode.bat’ to start the server again. You can also set LightTPD to run as a service. Open [LightTPD-Directory]\bin\ and double-click on Service-Install.exe to install the service.

You are set and good to go. To test if PHP is working, create a .php file with this content

1   <?php phpinfo(); ?>

Place the file in the htdocs directory, mine is D:\Inetpub\wwwroot\ and navigate to the URL, i.e You should be able to see the standard phpinfo() details.

That’s it!

I hope you’ll get this if you want to install LightTPD this way. Thanks for reading and please leave a comment to let me know how far it goes.

Thursday, 8 July 2010

Order Matters – LINQ

One of my colleague ran into this problem when using LINQ to join two tables. The problem is that he has two tables a & b where he is joining tables on column called key on both the tables. Following is what he had in the beginning

var list = from firstTable in a

              join secondTable in b

              on firstTable.Key == secondTable.Key

              select a;

This is a very straight forward query. On first glace there is nothing wrong with that. But when he tries to enter the above mentioned code, VS 2010 did not let him complete and was give error “The name ‘secondTable’ is not in scope on the left side of ‘equals’”  Couple of things you have to remember when you are using Linq to do joins

  • The order of comparison matters. So always use first table first and compare it against second table.
  • All LINQ joins are equijoins. so instead of using == you should use equals

So the correct LINQ query should be like the following

var list = from firstTable in a

              join secondTable in b

              on firstTable.Key equals secondTable.Key

              select a;

Monday, 5 July 2010

Dynamically change UI Element in Silverlight

I ran into a situation where, based on what grid client wants to see, I need to show them that particular grid of user’s choice. The catch here is that, all the grids are different third party controls so I can not generalize and create one view, instead each grid will be separate view. Here is how I went about doing it. I have main page XAML, which has a combo box which will allow the user to select which grid they want to see. By default, we show the first grid on load. When the grid selection changes I need to replace the current grid with selected grid.

Following is main page XAML.

<Grid x:Name="LayoutRoot" Background="White">
        <RowDefinition Height="5*"/>
        <RowDefinition Height="95*" />

    <ComboBox Name="comboSelection" SelectionChanged="comboSelection_SelectionChanged" Width="300" HorizontalAlignment="Left" Grid.Row="0">
        <ComboBoxItem Content="First" IsSelected="True"/>
        <ComboBoxItem Content="Second"/>
        <ComboBoxItem Content="Third"/>
    <sdk:DataGrid AutoGenerateColumns="False" Grid.Row="1" HorizontalAlignment="Left" Margin="0,0,0,0" Name="dataGrid1" VerticalAlignment="Top" />

Now I create two other XAML with data grid in it call it First and Second. A Sample First XAML looks like this

<Grid x:Name="LayoutRoot" Background="White">
        <sdk:DataGrid AutoGenerateColumns="True" HorizontalAlignment="Left" Name="dataGrid2" VerticalAlignment="Top" />

in the code behind, I load some data and data bind it to datagrid2. The interesting part of the code which replaces the default grid from the main page is as follow

FirstControl first = new FirstControl();
Grid.SetRow(first, 1);

So create the first grid and remove the existing grid from row 1, add the newly created as a child to the Layout Root. Make sure you set which row the newly added grid has to go to. That’s it. Now you can switch in and out of grid as you want.