Forcing Retrieval of Images in ASP.NET/MVC

Posted: June 3rd, 2015 | Author: | Filed under: .Net, ASP.NET MVC, Web | No Comments »

Browsers cache images in order to speed up page load times. If an action on a controller generates dynamic images, this can be a problem, since the user will only see the first image fetched by the browser. One way to force the browser to by-pass its cache and actually retrieve the image is to append a random parameter to the URL for the action.
For example: A user uploads an image to the server and the server subsequently returns some HTML showing the image. The user then performs an action which triggers the server to alter the image in some way (for example cropping or resizing), and returns the HTML once again. However, the browser sees that the link to the image is the same, and therefore it simply shows the initial image which it has already cached.

So, instead of generating the image URL with razor syntax like this:

<img src="@Url.Action("GetPhoto")" />

Simply add some random parameter (or just anything the browser has not seen before) to force it to download the image again:

<img src="@Url.Action("GetPhoto", new {ticks = DateTime.UtcNow.Ticks})" />

Extracting Image Files from SQL Server

Posted: April 11th, 2014 | Author: | Filed under: .Net, MSSQL, Visual Studio | Tags: , , , , | No Comments »

There are a number of different plugins and tools which can export image data in hex format from an MS SQL server to an actual file on the harddrive. If you have Visual Studio installed, however, the easiest way is to just write a small console program to select the data from the image column and save it to a file. For example:

static void Main(string[] args)
SqlConnection thisConnection = new SqlConnection(@"Server=,1433;database=MyDb;User id=sa;Password=JdjdUD78!;");
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT ImageData FROM [MyDatabase].[dbo].[Images] where ID = 1";
byte[] imgBytes = (byte[]) thisCommand.ExecuteScalar();
FileStream fs = new FileStream(@"C:\temp\image.jpg", FileMode.CreateNew, FileAccess.Write);
fs.Write(imgBytes, 0, imgBytes.Length);
catch (SqlException e)

Basic SQL Server Query in C#

Posted: April 11th, 2014 | Author: | Filed under: .Net | Tags: , | No Comments »

If you need to access a database on an MSSQL server programmatically (in C#) just to do some quick and dirty data extraction and perhaps manipulation, the following code snippet will get you started. Replace the connection string, table and columns names with whatever is appropriate for your task.

static void Main(string[] args)
SqlConnection thisConnection = new SqlConnection(@"Server=,1433;database=NorthWind;User id=sa;Password=HIUHFuhf8;");
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT [ID], [Name] FROM Customers";
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
Console.WriteLine("\t{0}\t{1}", thisReader["ID"], thisReader["Name"]);
catch (SqlException e)

Subversion revision number in AssemblyInfo.cs

Posted: July 23rd, 2013 | Author: | Filed under: .Net, Subversion, Visual Studio | Tags: , , , , , , | No Comments »
Pre-requisites: Tortoise SVN, Visual Studio
  • Exclude the existing “AssemblyInfo.cs” file from Subversion
  • Rename “AssemblyInfo.cs” to “AssemblyInfo.template
  • Add the Subversion revision keyword to the template file. For example: [assembly : AssemblyVersion(“1.0.0.$WCREV$“)]
  • Add SubWCRev.exe from the TortoiseSVN bin directory to the project (or add the Tortoise SVN bin folder to your path)
  • In the pre-build event for your project, add the following line (You may need to adjust it to your own project structure): "$(SolutionDir)\lib\SubWCRev\subwcrev.exe" "$(SolutionDir)." "$(ProjectDir)Properties\AssemblyInfo.template" "$(ProjectDir)Properties\AssemblyInfo.cs"
  • Done! The “AssemblyVersion.cs” file should now be auto-generated on every build and the $WCREV$ keyword is replaced with the current SVN revision number on the solution directory.

General OpenELEC Configuration

Posted: January 10th, 2013 | Author: | Filed under: Uncategorized | No Comments »

Shutdown function should suspend:

System -> Settings -> System Powersaving -> Shutdown function: Suspend

XBMC + TVHeadEnd + HDHomeRun

Posted: December 28th, 2012 | Author: | Filed under: Uncategorized | No Comments »


How to install and configure TVHeadend and HDHomerun on an OpenELEC machine.


HDHomerun Driver


Configure HDHomerun Driver

Change directory to /storage/.xbmc/addons/driver.dvb.hdhomerun/config
Make a copy of dvbhdhomerun.sample to dvbhdhomerun.conf

Open \\xbmc\Userdata\addon_data\driver.dvb.hdhomerun\adapters and copy the IDs of the two tuners to dvbhdhomerun and set their types (just follow the instructions in the config file.). Alternatively, run userhdhomerun to get the IDs.


Configure TVHeadend

Go to webpage of TVHeadend: http://:9981
Go to Configuration -> DVB Inputs -> TV Adapters

Select the first adapter.
Click “Add DVB Network by Location”
Choose your location
Click “Enabled”
Click “Save”
TVHeadend now starts scanning for channels. You can monitor its progress in the pane to the right. When “Muxes awaiting initial scan” is zero, it’s done.
Click “Map DVB Services to Channels”.
The mapping will also take some minutes to complete depending on how many channels are present.

In the web config in Configuration -> TV Adapters: After all channels have been configured, disable “Autodetect Muxes” and “Idle Scanning“. Having these enabled completely destroyed the stream from TVHeadEnd, making the image look garbled and stuttering. It looked like a low bandwidth connection or bad signal.

Resume from Suspend (S3) in XBMC

Posted: October 4th, 2012 | Author: | Filed under: Linux, XBMC | Tags: , , | No Comments »

In XBMC Eden, the power to the USB ports is cut when S3 is entered. It is therefore impossible to wake the system using the MCE remote or any other device connected via USB.

The following two fixes in combination resolves this problem:

Getting power to usb when in sleep
HOW-TO:Enable Wake-On-Device for Ubuntu

Samba Sharing in XBMCbuntu

Posted: October 4th, 2012 | Author: | Filed under: Linux, XBMC | Tags: , , , , | 4 Comments »

Samba is not included with XBMCbuntu (at least in 11.10), so first we have to install it:
sudo apt-get install samba
Open Samba’s configuration file in an editor
sudo nano /etc/samba/smb.conf
Scroll down to the bottom of the file and add the following sections, which will create a public share with read/write access without password validation:

workgroup = Workgroup
netbios name = XBMC
server string = XBMC Server
log file = /var/log/samba/log.%m
max log size = 50
map to guest = bad user
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
local master = no
dns proxy = no

path = /media
public = yes
only guest = yes
writable = yes
force user = xbmc

The above configuration example shares everything under the /media directory in a folder called “public”. The “force user” property must be set to a user with write access to the directory being shared. All files and directories will appear to have been created by this user.
Run “testparm” to check if your Samba configuration is parseable. For configuration changes to take effect, the Samba daemon can be restarted with
sudo /etc/init.d/smbd restart
The following screenshot shows my XBMC box sharing the /media directory which contains mount points for two harddrives (ingeniously named according to their capacities…):

XBMC Setup

Posted: July 29th, 2012 | Author: | Filed under: Uncategorized, XBMC | No Comments »

The following articles describes my XBMC setups.

Resume from Suspend (S3) in XBMC
Samba Sharing in XBMCbuntu

OpenELEC 2.0

Configure audio device

HDHomeRun + TVHeadEnd

DD-WRT on Linksys E2000

Posted: April 30th, 2012 | Author: | Filed under: Linux | Tags: , , , | No Comments »

These are the steps I took to flash a Linksys E2000 router with a DD-WRT firmware.

Background information

Steps Taken

– 30/30/30 Reset
– Upload dd-wrt.v24-18024_NEWD-2_K2.6_mini-e2000.bin via Linksys firmware upgrade page from
– Wait 5 minutes after upload completed.
– Web interface for DD WRT appears.
– Do a 30/30/30 reset again.
– Wireless > Advanced Settings enter 50 in the Tx Power entry. This should make for less Tx/Rx Errors and help the unit run cooler.


– Initital DD WRT firmware flash must be a trailed build. A trailed build has “*e2000.bin” in its name. Following flashes must have “*e2k-e3k.bin” in their name.