Category: Visual Studio

How to connect to an AD Domain Secured SQL Server from a non-domain PC

The following are instructions for setting up a connection to an Active Directory (AD) Domain secured SQL Server using either SQL Server Management Studio or Visual Studio. This is especially applicable when not using a domain attached PC.

Step-by-step guide

Continue reading “How to connect to an AD Domain Secured SQL Server from a non-domain PC”

Unit Test Class ReSharper Template and Snippets for nUnit and MS Test

Quick helper boiler plates for setting up your Unit Test.

I have included ReSharper Template here that you can import directly Resharper Templates. Also thanks you to Alessandro Aeberli for making the these Visual Studio Snippets

After importing the ReSharper Templates then you can use ‘uTestBoiler’ or ‘uTestnUnitBoiler’ shortcuts to add the code below into any test class.

If you want to make your own snippets you can use the Visual Studios Snippet Manager by following the instructions here https://msdn.microsoft.com/en-us/library/ms165394.aspx

Continue reading “Unit Test Class ReSharper Template and Snippets for nUnit and MS Test”

Getting access to and using Visual Studio code snippets with Resharper installed

When you first install Resharper, your Visual Studio code snippets are imported into Resharpers ‘Live Templates’. This is all very well until you install, update or create new Visual Studio code snippets.

If you have ever wondered how to use the Visual Studio code snippets when you have Resharper installed then here is the quick solution.

Press CTRL+J and then start typing the code snippet shortcut you are after. You will now see the list of available Visual Studio code snippets.

You can find this mentioned here http://www.jetbrains.com/resharper/webhelp/Templates__Applying_Templates__Inserting_Imported_Code_Snippets.html

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!