2016-02-25

[Solved] MVCApplication Parser Error

I have this problem because I have to develop with VS running as administrator in order to use Local IIS hosting. When files are added (or generated by compiling) I think VS was setting the owner as Administrator, which IIS then cannot read. Start a command prompt as Administrator and type in the following
icacls c:\devpath\yourwebsite /grant everyone:(OI)(CI)F /T

2016-02-24

How to Create a Self Signed Certificate in IIS 7

I know I am going to want this link again in the future!

2016-02-04

VSTO Office plugin not appearing in Office 2007

If you have an office VSTO plugin that is working in other versions of Office but not appearing in Office 2007 then try setting the following registry value

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Common\General\

Name = EnableLocalMachineVSTO
Value (DWORD) = 1


2016-02-01

Watching a single property in an array in AngularJS

A typescript example that converts the array's property into a single string that can be watched.
        $scope.$watch(
            () => this.someArray.map(x => x.selected ? "1" : "0").join(""),
            (newValue, oldValue, scope) => this.onSelectionChanged(this.getSelectedItems()));

Getting an AngularJS directive to call back a method on its parent's controller

Here is a TypeScript example of how to call back a method on the controller from an embedded directive. The most important thing to note is that the directive's parameter name for your callback uses a & when defined, and when calling that callback you should not use positional parameters but instead use an object with properties having the names of the parameters in the target.
Register the directive when you create your app module:
module MyApp {
    var app: angular.IModule = angular.module("MyApp");
    MyApp.Directives.FileUploader.register(app);
}
The registration code is as follows:
module MyApp.Directives.FileUploader {
  class FileUploaderDirective implements angular.IDirective {
      public restrict: string = "E";
      public templateUrl: string = "/app/Directives/FileUploader/FileUploaderDirective.html";

      //IMPORTANT - Use & to identify this as a method reference
      public scope: any = {
        onFileItemClicked: "&"
      };
      public controller: string = "MyApp.Directives.FileUploader.Controller";
      public controllerAs: string = "controller";
      public bindToController: boolean = true;
      public transclude: boolean = true;
      public replace: boolean = true;
  }

  export function register(app: angular.IModule) {
      app.controller("MyApp.Directives.FileUploader.Controller", Controller);
      app.directive("fileUploader", () => new FileUploaderDirective());
  }
}
The directive's controller would look like this
module MyApp.Directives.FileUploader {
    export class Controller {
        public files: string[] = ["One", "Two", "Three"];
        //The callback specified in the view that created this directive instance
        public onFileItemClicked: (fileItem) => void;

        // This is the controller method called from its HTML's ng-click
        public fileItemClicked(fileItem) {
            //IMPORTANT: Don't use comma separated parameters,
            //instead use an object with property names to act as named parameters
            this.onFileItemClicked({
                fileItem: fileItem
            });
        }
    }
}
The directive's HTML would look something like this
  • ng-repeat="item in controller.files" ng-click="controller.onFileItemSelected(item)"> {{ item }}
  • The main view will have an instance of your directive like so
     ng-app="MyApp" ng-controller="MainController as controller">
       on-file-item-clicked="controller.fileItemClicked(fileItem)"/>
    
    Now all you need on your MainController is a method
    public fileItemClicked(fileItem) {
      alert("Clicked " + fileItem);
    }

    2016-01-29

    AngularJs - binding HTML

    The directive ng-bind will escape HTML to avoid data acting maliciously. If you want to output html you need to use ng-bind-html

    <div ng-bind-html="someHtmlBody"/>

    The important step to getting this working is to ensure the script angular-sanitize.js is referenced on your page, and it is specified as a dependency when creating a module....

    var app = angular.module("MyApp", ["ngSanitize", "OtherDependencies"]);

    AngularJS routes with ASP MVC Forms authentication

    The ASP MVC app I am working on uses forms authentication with a timeout. This means that when the session has timed out and the user clicks refresh they get redirected to a login page, and after that they get directed back to the original page without the deep-linked client-side # part of the url. 

    The solution to this is as follows:

    The first thing to do is to have the ASP MVC server side capture any URLs that should related to your client-side angular routing and return the single-page app HTML. When registering your ASP MVC routes add the following rule
            routes.MapRoute(
                name: "Angular",
                url: "x/{*clientPath}",
    Where the "x/" is the base part of your client app, of course you can do without the "x" in the URL if your entire app is a single-page angular app, in which case you will need to add a preceding rule to render your ASP MVC server side account-login page.
    Then in your Angular app make sure you use Html5 mode, like so
    app.config(["$locationProvider", "$routeProvider", function ($locationProvider, $routeProvider) {
    
        $locationProvider.html5Mode({
            enabled: true,
            requireBase: false,
            rewriteLinks: true
        });
    
        $routeProvider.when("/x/docs/upload", {
            ......
        });
        $routeProvider.when("/x/docs/view", {
            ......
        });
        $routeProvider.otherwise({
            redirectTo: "/x/docs/upload"
        });
    }]);
    When you open your browser and navigate to http://mysite/x/what/ever/you/like the server side will use XController.Index to render Views\x\Index.cshtml, which will load your single page app, and then ngRoute will take over and present the relevant view for the "x/what/ever/you/like" part.