Friday, April 29, 2016

Web Platform Installer and IIS Recommended Configuration

I was recently trying to install "IIS Recommended Configuration" on Windows Server 2016 only to discover that this no longer works!

Instead, I get the following error message:

Therefore, unfortunately, you have to manually configure IIS 10.0 on your Windows 10 and Windows Server 2016 systems until Microsoft fixes their Web Platform Installer configurations!

Monday, April 25, 2016

Authorize.Net SIM using ASP.NET MVC

If you need to integrate with Authorize.Net as your Payment Gateway, you might already know that there are multiple methods to integrate with Authorize.Net and one of the many methods available is the SIM method (Server Integration Method).

Unfortunately, Authorize.Net has removed most of their SIM code samples in favor of their new API implementation.

If you are using ASP.NET Web Forms and need to provide some additional server-side logic and processing, unfortunately, you will have to "re-create" the entire form post or form submission manually in server-side code to accomplish this.

But the good news is that someone has provided sample code on how to do just that!

In this article (, you can find sample code on how to perform a "Remote Post".

This basically allows you to re-construct the form as well as all of the form field values and then re-post the form to the Url of your choosing.  In this case, you will either be posting to or

Unfortunately, the code sample provided in the article addresses ASP.NET Web Forms and does not address how to accomplish the same task using ASP.NET MVC!

Well, using ASP.NET MVC, the solution can be modified to perform the post via the HttpPost method of the Controller as follows:

public ActionResult Index(AuthNetSIMModel model)
    //Validate the model values
    if (ModelState.IsValid)
        RemotePost remotePostForm = new RemotePost();

        remotePostForm.Url = AuthorizeNetSIM.GetPaymentUrl();

        return View("Success");

    ModelState.AddModelError("", "Model State is invalid");
    return View(model);

This then provides a suitable solution for ASP.NET MVC as well!

Authorize.Net Error Message: (270) Line item 1 is invalid

I was recently working on using the SIM Authentication method with Authorize.Net, when I suddenly encountered the following error message:

Well, after I consulted the Authorize.Net SIM guide for Itemized Order Information, then I discovered that I needed to provide 5 values in each of my x_line_item values as follows:

paymentModel.x_line_item = string.Format("{0}<|>{1}<|>{2}<|>{3}<|>{4}<|>{5}", model.MembershipTypeID, model.MembershipType, model.MembershipType, 1, model.MembershipCost, "N");

That was all that was needed to fix my issue!

Saturday, April 23, 2016

Precompilation of Razor View in Sitefinity Feather

I was recently making changes to my Bootstrap Layout templates as part of Sitefinity Feather when I noticed that my changes were not being applied!

Well, fortunately, I came across this Sitefinity Feather Forum post:

After I turned this off and then applied changes to my Razor Layout view, I could then observe my Layout changes!

Friday, April 22, 2016

Removing the Brand text in the Bootstrap Navigation widget for Sitefinity Feather

If you have started working with Sitefinity Feather, you may know that they ship a Bootstrap Resource Package which includes a Navigation widget.

However, the problem with this navigation widget is that it maintains the text "Brand" at the beginning of the navigation bar with no easy way within the Administrative User Interface to override this text.

Well, fortunately, this can be done readily using some basic CSS!

 display: none !important;

That is all that is needed to hide the "Brand" text from the Bootstrap navigation!

Thursday, April 21, 2016

WebForms UnobtrusiveValidationMode requires a ScriptResource mapping for 'jquery'

I was recently working with an ASP.NET Web Forms application and encountered the following error message:

Well, as it turns out, I had to add the following element to my appSettings element:

<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> 

That was all that was needed to resolve this error message!

SharePoint 2016 Webinar

If you are interested in learning more about SharePoint Server 2016, then I would encourage you to register for the free webinar coming up on May 4th, 2016!!

FREE Sitefinity Developer Certification!

Telerik is currently offering the Sitefinity Developer Certification for FREE!!!

The Sitefinity Developer Certificate is FREE until August 1st, 2016, after which the exam will cost $200.

In addition, if you need to re-take the exam, you have to wait a minimum of 14 days before re-taking, so register as soon as possible!

If you have a PluralSight subscription, you can prepare for the exam using these 2 sets of videos:

In addition, when you register for the Sitefinity exam on the Progress Education Community Portal, you also get 10 modules of training videos to review in preparation for your exam!  How cool is that??

Injecting string arguments using Ninject

I recently had a requirement to inject strings into a constructor argument using an IoC container such as Ninject.

Unfortunately, I had always used Ninject in the past to inject dependencies that were based on interfaces, so how was I supposed to inject primitive types such as strings?

Well, fortunately, using Ninject, it is surprisingly simple!!

I just used the following code:

kernel.Bind<IHttpClientWrapper>().To<HttpClientWrapper>().WithConstructorArgument("userName", "johndoe"); 

That was all that was needed!!

Wednesday, April 20, 2016

Deleting or expiring cookies

If you ever have a need to delete or expire a Cookie that you create through ASP.NET or ASP.NET MVC, fortunately, MSDN has just an article on how to accomplish that!

if (Request.Cookies["UserSettings"] != null)
    HttpCookie myCookie = new HttpCookie("UserSettings");
    myCookie.Expires = DateTime.Now.AddDays(-1d);

Pretty simple, right??

Tuesday, April 19, 2016

Changing the Assembly Version using Jetbrains TeamCity

If you are using a process outside of Jetbrains TeamCity to manage your assembly version information, then you may end up using a process that leverages MSBuild to alter AssembyInfo.cs files or GlobalAssemblyInfo.cs files.

In the past, I have used MSBuild Extension Pack with the AssemblyInfo task to accomplish this:

However, since I am using Jetbrains TeamCity as part of my CI build processes, I can use the AssemblyInfo Patcher Build Feature instead!

This can be done as follows:

Since this runs before the 1st build step it requires no changes to your existing build steps and configuration!

Pretty awesome, huh??

Mocking HttpContext in Unit Tests

One of the banes of writing Unit Tests is dealing with HttpContext which does not have an interface which can be easily Mocked like most other custom classes.

Fortunately, though, Microsoft has created a base class called HttpContextBase!

In my particular case, I needed to figure out how to mock HttpContext to use it in Unit Testing HttpCookie creation and retrieval.  I followed this article for guidance on just how to accomplish this task:

Mock<HttpContextBase> HttpContextMock = new Mock<HttpContextBase>();
Mock<HttpRequestBase> RequestMock = new Mock<HttpRequestBase>();
Mock<HttpResponseBase> ResponseMock = new Mock<HttpResponseBase>();

HttpContextMock.Setup(x => x.Request).Returns(RequestMock.Object);
HttpContextMock.Setup(x => x.Response).Returns(ResponseMock.Object);
ResponseMock.Setup(r => r.Cookies).Returns(new HttpCookieCollection());

Using this Mock Setup code, I could now Unit Test my code which was dependent on HttpContext as well as the Request and Response objects for my HttpCookies!!

Monday, April 11, 2016

Injecting HttpContext into an ASP.NET MVC Web Application using Ninject

If you have ever struggled with using HttpContext in your ASP.NET MVC Web Applications in regards to developing applications that can be easily tested, then you will be happy to know that this problem can be readily solved using HttpContextBase and an IoC container such as Ninject!

In my particular situation, I needed to use Cookies in my application therefore I created a class similar to the following:

public class CookieManager : ICookieManager
        private HttpContextBase _context;

        public CookieManager(HttpContextBase context)
            _context = context;

        public HttpCookie GetCookie(string cookieName)
            HttpCookie cookie = null;

            if (_context != null)
                cookie = _context.Request.Cookies[cookieName];

            return cookie;
        }//method: GetCookie()

Now the problem arose as to how to use an IoC container such as Ninject to handle injecting the proper HttpContext?

First of all, if you do not inject your HttpContext, you will receive an error something like shown below:

Well, there are 2 possible ways of accomplishing this:

kernel.Bind<HttpContextBase>().ToMethod(context => new HttpContextWrapper(HttpContext.Current));

The above method will inject HttpContext into any class that is dependent on HttpContextBase, therefore, making your development relatively easy to maintain going forward.

If you want to be more explicit about your HttpContextBase dependencies, you can instead do something like the following:

kernel.Bind<ICookieManager>().To<CookieManager>().WithConstructorArgument("context", ctx => new HttpContextWrapper(HttpContext.Current));

Therefore, as you can see, now you can easily inject an instance of HttpContext using HttpContextBase as well as easily Unit Test your applications using a Mocking Framework such as Moq by leveraging an interface such as the ICookieManager interface I have used in my above code samples.

That is all there is to it!!

Sunday, April 10, 2016

Application Insights for log4Net and other .NET Loggers

I was recently working inside Visual Studio when I was suddenly presented with the following dialog box:

After clicking on the "Learn more" link, I was directed to this website:

Based on a brief review of the article, it seems that I could capture my logs using a variety of .NET logging libraries such as log4Net and then have them sent to Windows Azure where I can then easily browse these error logs!

I have yet to try this feature out, but it certainly seems intriguing and I am eager to see how well it works!

Friday, April 8, 2016

Using the Copy-Item Cmdlet to exclude files

I recently began switching over some of my command line tasks over to their PowerShell equivalents.

Of course, the Copy-Item cmdlet is the PowerShell replacement to xcopy or RoboCopy.

Of course, the TechNet article provides the available switches and numerous examples, but does not provide a specific example for EXCLUDING FILES!!

When I had previously used robocopy, I had used the /XF switch to exclude files, however, I could not achieve the same result when using this PowerShell command:

$ExclusionFiles = @("packages.config", "connectionStrings.config")

    #Copy over the items
    Copy-Item -Path $SourcePath -Destination $DestinationPath -Exclude $ExclusionFiles -Recurse -Force

Well, as it turns out, my $SourcePath variable needed to append a wildcard character to the end of the path in order for the Exclude switch to properly work as follows:

$ExclusionFiles = @("packages.config", "connectionStrings.config")

    #Copy over the items
    Copy-Item -Path "$SourcePath\*" -Destination $DestinationPath -Exclude $ExclusionFiles -Recurse -Force

That was all that was needed to get my PowerShell script to work in the same way as RoboCopy!!

Wednesday, April 6, 2016

psake and curly braces

I was recently writing a psake script with its corresponding tasks and I decided to do some formatting of my tasks by moving the curly braces ({) onto a separate line consistent with what I follow when I am writing my C# code similar to this:

$testMessage = "This is from psake"

task Test  
    Write-Host $testMessage

Unexpectedly, this caused psake to no longer function correctly!

Since I had always seen psake formatted like this, I reverted it to this format:

$testMessage = "This is from psake"

task Test  {
    Write-Host $testMessage

Once I reverted the script back to the curly braces on the same line as the task, my psake scripts once again began working correctly!

Therefore, when you are working with your own psake scripts, make sure you keep your curly braces on the same line!!

Red Hat Linux and Microsoft.NET Framework--together at LAST!

If you haven't heard about the recent announcement at BUILD 2016, Red Hat Linux has a brand new website dedicated to the .NET platform on Red Hat Linux:

In addition, there was a recent announcement for a FREE Red Hat Linux Developer Subscription now available!

Tuesday, April 5, 2016

WRN: Assembly binding logging is turned OFF.

I recently was working on troubleshooting an ASP.NET MVC Web Application when I suddenly encountered this error message:

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

After doing some digging, I wanted a convenient method of enabling Assembly Logging that would not require me to manually edit the registry.

Of course, my standard go-to for automating tasks is PowerShell!

Therefore, I came up with this PowerShell script to enable Assembly Logging as follows:

$FusionLogDirectory = "C:\FusionLog"

Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name ForceLog         -Value 1               -Type DWord
Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogFailures      -Value 1               -Type DWord
Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogResourceBinds -Value 1               -Type DWord
Set-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogPath          -Value $FusionLogDirectory -Type String

If at some point in time, you need to disable Assembly Logging, you can do so with this script:

Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name ForceLog
Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogFailures
Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogResourceBinds
Remove-ItemProperty -Path HKLM:\Software\Microsoft\Fusion -Name LogPath

Friday, April 1, 2016

psake and MSBuild - Better together

I was recently introduced to an alternative method of building projects using a tool called psake.

This is basically a project which leverages PowerShell to do the heavy lifting of tasks that would normally require custom .NET tasks or extensions to MSBuild to accomplish normally.

The documentation for psake can be found here:

Psake is also conveniently available as a NuGet package:

For a quick tutorial on getting started with psake, you can check out this blog post:

Since psake is built on PowerShell which itself is built on the .NET Framework, it opens up a lot of possibilities to accomplish things which are not readily built into MSBuild.

Of course, now that MSBuild is open source, the number of built-in MSBuild tasks will probably grow over time, but psake will be able to easily fill those gaps in the interim!!

This app can't be activated by the Built-In Administrator

I recently started playing around with Windows Server 2016 to begin familiarizing myself with the platform when I suddenly encountered this error message:

I had never seen this error message before, but figured it might be caused by User Account Control so I proceed to the UAC settings to turn off UAC:

However, even after changing these UAC settings, I encountered yet another related error message:

Well, this seemed to indicate a much more involved solution, so a quick search on the Internet returned this article:

UAC Group Policy Settings and Registry Key Settings

Of course, since I absolutely LOVE PowerShell, I decided to write a script that would solve this issue for me!

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name FilterAdministratorToken -Value 1

That was all that was necessary to get my system working as expected!!  Pretty simple, huh??

Why I still hate the Windows 10 Start Menu

With the release of Windows 10 and the re-introduction of the Windows 10 Start Menu, I was thinking I might be able to get used to the new Windows 10 Start Menu, but, unfortunately, I was VERY VERY WRONG!

Windows 10 provides a new "Search Web and Windows" Search icon or Search bar (depending on your settings/preferences).

However, even after installing an application such as "Microsoft Web Platform Installer" and attempting to search my machine for this application, these are the results of my findings:

As you can see from the screenshot above, Windows 10 is not finding the application that I have installed on the machine.  Instead, it is attempting to search the Web for this application!

 However, if I simply jump into the "All apps" section, I can quite readily find the installed application as shown below:

In contrast, if I use Classic Shell ( to search Windows 10, the search results are remarkably different:

As you can see from the screenshot above, the results are accurately discovering the installed application on Windows 10 rather than attempting to search the Web for this application.

Therefore, as you can probably guess by now, I am sticking with using Classic Shell for the foreseeable future!!

Windows Server 2016 Technical Preview 4 First Look

After a great deal of disappointment with the earlier releases of Windows Server 2016, I finally decided to install Technical Preview 4 to see if it differed from prior releases of Windows Server 2016.

As I had read earlier, based on customer feedback, it seemed that Microsoft re-introduced the Desktop Experience to the Windows Server platform, so I was expecting to see something similar to the Windows 10 User Interface.

Aside from the Windows 10 Start Menu, the overall server looks pretty much the same as Windows Server 2012/Windows Server 2012 R2!!