Category: Development

HTML Placeholder not working in IE9 and earlier!!

Recently found this very useful jQuery plugin for fixing placeholder issues in old IE browsers. It seems to cover most scenarios and is very easy to  implement 🙂

https://github.com/mathiasbynens/jquery-placeholder

Just add the script after the jQuery and call

$('input, textarea').placeholder();

You will also need to add the placeholder style in your css.

/* Placeholder fix for IE9 for use with jQuery.placeholder plugin */
 .placeholder { color: #aaa; }

If you are a c# razor person, something like this on your impacted pages will do the trick (assuming you something like

@RenderSection("MyJavaScript", false)

in your layout).

@section MyJavaScript
 {
 <script src="@Url.Content("~/Scripts/jquery.placeholder/jquery.placeholder.js")" type="text/javascript"></script>
 <script>
 $('input, textarea').placeholder();
 </script>
 }

How to reset your Remote desktop user account expiry date on your Azure cloud service

If you have not re-deployed your azure cloud service for a while you might just find that your remote access account has expired. Here is a simple way to push out the expiry date without re-deploying.

  1. Login to the Azure Management Console ( https://manage.windowsazure.com ), navigate to you cloud service and select the configure tab
  2. Download the configuration and save to a local temp area.
  3. Open it up in notepad
  4. Find the setting that looks like
    <ns0:Setting name=”Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration” value=”2013-09-07T23:59:59.0000000+01:00″ />
  5. Just change the year to sometime in the future e.g. 2016 and save.
  6. Then from the same configure page in the Azure management console, upload the config file.
  7. Wait a few minutes while the file is process and voila! you can now log in. Of course you must know the original password and usename you used when you last deployed.

How to make a short URL friendly GUID in C#

Been trying my own hack to make a short GUID for a web form submission, but hit issues with incompatible characters. Just before making more changes I came across this excellent blog and code to easily convert GUIDs to Short GUIDs and back.

I have found this especially useful when sending unique vendor transaction refs to the SagePay forms service as they have a 40 character limit.

http://www.singular.co.nz/blog/archive/2007/12/20/shortguid-a-shorter-and-url-friendly-guid-in-c-sharp.aspx

Create a No Hyper-V boot option

There seem to be a number of scenarios where Hyper-V (and it’s many virtual networks and network adapters) can cause problems. My two are running VMware and problems with the Azure emulator with shared cache when debugging in Visual Studio.

To solve this problem you could uninstall the Hyper-V feature, but it’s still important for so many other tasks that this is a real pain.

It is possible to create a simple boot option for Windows 7 and 8 and Windows Server that disables the hypervisor. This is quick and painless, so when you ever need or don’t need Hyper-V, just reboot and select the option you want.

  1. Open a command prompt as Administrator (right-click the start button on the desktop and select ‘Command Prompt (Admin)’
  2. Type
     bcdedit /copy {current} /d "Microsoft Windows 8 - No Hypervisor"

    and press enter.
    This creates a new boot entry identical the the current one.

  3. Type
     bcdedit

    and press enter to list all the boot entries.

  4. Copy the identifier, including curly brackets, for the new boot entry (should be the last in the list)
  5. Now we need to disable the hypervisor on the new entry. Type
     bcdedit /set {the new identifier} hypervisorlaunchtype off

    and press enter.

  6. Now reboot and you will be presented with a nice boot menu option and can choose to boot with or without Hyper-V

.Net MVC 3 Logon does not redirect out the box–quick fix!

It seems that the templates for MVC 3 razor are not quite complete. If you attempt to browse to a page where authentication is required, then you will be redirect to the Logon page with a ReturnUrl query string.

Something like:

http://mysite.com/Account/LogOn?ReturnUrl=%2fThePageIWant

That’s great except, out the box, the Logon page does not make use of this and the destination page is not redirected to after a successful login. The fix is easy.

Add the returnUrl route value into the Html.BeginForm method as shown below.

Html.BeginForm("LogOn", "Account", new { returnUrl = Request.QueryString["ReturnUrl"] })

You should already have some code in the controller that does some sanity checking on the returnUrl before doing the redirect. Somthing like:

if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
       && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
    return Redirect(returnUrl);
}

Make sure this is after the SetAuthCookie line!

How to get ‘Create Unit Test’ shortcut back in Visual Studio 2013

Why the hell Microsoft thought it was a good idea to remove this I have no idea. If they want good reliable code on their platforms you would have thought this would be good to leave in to encourage developers to create unit tests!

Anyway, rant over, this blog explains all the options. The last one being the first one to try!

http://serena-yeoh.blogspot.com.es/2013/02/visual-studio-2012-create-unit-test.html