Login failed for user IIS APPPOOL\AppPool4.5 or APPPOOL\ASP.NET

The error ‘Login failed for user 'IIS APPPOOL\AppPool4.5’ usually occurs when you configure a new website in IIS or move an existing website to a newer version of IIS.

A simple solution to the error is to add a login to SQL Server for IIS APPPOOL\ASP.NET v4.5 and grant appropriate permission to the database.

Open SQL Server Management Studio > Right click ‘Security’ > New > Login

iis-apppool-login

Action Filters in ASP.NET MVC

Continuing with our MVC 101 series today we look at an important MVC feature, Filters. Filters in ASP.NET MVC are a way to apply cross-cutting logic at the controller level. Some examples of cross-cutting logic is Security and Logging.

Security is a cross cutting concern because, once enabled, we need to apply it for all incoming requests in the web Application. Imagine a world where you don’t have filters, in such case for every request that comes in, you Action method in controller will have to check if the user was Authorized to perform the action and view its result.

This not only violates single responsibility principle of the Action Method (it’s doing two things, evaluating security and computing the Action’s output) but is also an extremely verbose and repetitive work that we’ve to do irrespective of what the Action is supposed to do. Moreover, writing Authentication Code in action method cannot be guaranteed. There is no certainty that a developer may or may not miss out on implementing the code!

C# (Csharp) Switch Case Statement with Example

A C# switch case statement defines multiple groups of statements, and then executes one of these statement; depending on the value of a constant or test expression.

Let us understand this concept with an example.

string siteName = "DevCurry";
switch (siteName) {
    case "DotNetCurry":
    Console.WriteLine("This website is DotNetCurry.com");
    break;

    case "DevCurry":
    Console.WriteLine("This website is DevCurry.com");
    break;

    default:
    Console.WriteLine("Default Website");
}

As you can see, we start by defining a constant at the top:

Getting Started with NUnit in ASP.NET MVC

Visual Studio 2012 comes with a perfectly capable Unit Testing system in MS Test. However if your team’s skills require you to use alternate Testing frameworks like NUnit, Visual Studio is game to play along. In this article, we’ll see the how we can setup NUnit to work with Visual Studio’s Test Explorer and run Unit tests in our project.

Setting up NUnit

There are two parts to NUnit setup for use in Visual Studio. First part is to install the framework, we can do this in two ways.

1. Download the 2.6.2 (latest at the time of writing) msi installer from http://www.nunit.org. Ensure Visual Studio is not running while the installer is running. This installs NUnit globally along with the NUnit test runner. However the test runner needs .NET 3.5 to run.

2. Another way to include NUnit in your project is to download it using the following Nuget Package Manager command

PM> install-package NUnit

Second part is to setup the NUnit Test Adapter so that Visual Studio recognizes the Test Cases in our project and allows us to Run them from the Test Explorer.

Debugging Parallel Code in Visual Studio

.NET 4.0 introduced the Task Parallel Library (TPL) and Parallel LINQ (PLINQ) in an attempt to make parallel programming simpler and making best use of multi-core processors easier.

Recently I was playing around with the Parallel.Foreach and the new Enumerator APIs for the File System in System.IO trying to build a Fast Folder Scanner when I chanced upon the Parallel debugging options in Visual Studio. After fiddling around a little bit, I was able to make sense of the information and it was kind of a ‘brain explode’ moment.

Let me share the things that I figured out.

The Harness Code

- Let’s create a Console Application called FastFolderScanner

- Next we put together the following code to scan folders for a particular type of file and split them out.

C# : Cannot implement an interface member because it is not public

If you've written a class that has implemented an interface, you've probably encountered a requirement where a method you are implementing, must be public. The error thrown is usually “Cannot implement an interface member because it is not public”.

If an interface member method is implemented in your class without an access modifier, it is by default private.

But methods have to be either public so that they can be called through the interface, or they need to be explicit. Let us assume your interface is implemented as follows:

public interface ITest 
{
bool IsTest();
}

To change the visibility, you can either change the interface from public to internal.

Using Custom Directive in AngularJS to create reusable JavaScript components for your ASP.NET MVC app

In our previous three articles on Angular JS, we have seen how we could get started by building a small Twitter Client. We have explored the view model, Modules and Services in Angular JS and in our last article saw how to post data using the $resource Service.

Today we’ll see how to use a feature called Directives in Angular JS. Directives allow you to encapsulate custom behavior in an HTML element, attribute, classes and even comments. For example, the ng-app attribute that we use to define the scope of our Angular App is in fact a Directive, because there are no HTML5 attributes by that name! It’s Angular who interprets the attribute at runtime.

Apart from helping add custom attributes, directives can also be used to create the server side equivalent of ‘tag-libraries’ on the client. Those familiar with WebForms or JSP development will remember you could create server side components with custom Tags like <asp:GridView>…</asp:GridView> where the GridView rendering logic was encapsulated in a server component. Well, Directives allow you build such components, but on the client.

In fact today we’ll define a ‘Retweet’ button on our Tweet Reader that will enable us to encapsulate the function in a custom directive.

Reading a Local File using HTML5 and JavaScript

One area where the web has lacked for some time is the lack of a true file system.  HTML5 fills this void by providing a standard way of interacting with local files using the FIle API specification.

These APIs are used to read file locally, handling images etc. Some of the specifications are as listed below:

1. File: Provides read-only information about the file like name, filesize, mimetype etc.

2. FileList: Represents an array of individually selected files from the local system

3. Blob: Represents the raw binary data and allows access to range of bytes within the data which can be used for slicing file

4. FileReader: Provides methods to read data from file or Blob