Joseph Michael Pesch
VP Programming

Restart IIS Web Site from C# Code

by 24. April 2016 04:58

In some cases I have setup caching on the website for items such as menus, header, footer, etc.  However, when there is a CMS in place on the site and a user changes any of that relevant content there needs to be a way to reset the web cache.  One easy way is to force the IIS web site to restart by making a benign change in the web.config file, which will automatically force the restart.  Below is a sample version of code to do this, where I update an otherwise unused entry in the web.config that just indicates the last date/time of restart request by the user.  In the case of an MVC application I put this into a controller with some specific route provided to the CMS users so they can navigate to that route after making CMS changes that need to be updated in the cache.  As a side note, using this method will require granting write access to the web.config file for the IIS application pool user (by default "IIS AppPool\WebSiteName" user).

    public static void RestartWeb()
      var configuration = WebConfigurationManager.OpenWebConfiguration("~");
      var section = (AppSettingsSection)configuration.GetSection("appSettings");
      section.Settings["LastRestart"].Value = 
        DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();


ASP.Net | C#

Change the "SharePoint" Text in the Ttop Left Corner of SharePoint 2013 Site

by 20. April 2016 11:04

To change the text you can use PowerShell with the sample code snippet shown below.  NOTE: To use PowerShell for SharePoint make sure add the snapin (Add-PSSnapIn Microsoft.SharePoint.Powershell).

PowerShell Script Sample:

$webApp = Get-SPWebApplication http://MySiteUrlHere; $webApp.SuiteBarBrandingElementHtml = "<a href='/'>My Site Title Here</>"; $webApp.Update(); 



BlogEngine.Net Using TinyMCE Allow User to Paste Image Directly Onto Page

by 2. April 2016 09:18

By default the TinyMCE configuration in a standard BlogEngine.Net implementation may not be setup to allow users to paste images directly from their clipboard onto the page.  To make sure this feature is enabled, go to the "admin/editors/tinymce/editor.js" and add the two lines listed below into the tinymce.init method (sample of a full view of the method also shown below):

browser_spellcheck: true,
paste_data_images: true,

For any editor customization, check TinyMce website for plugins:

    selector: '#txtContent',
    plugins: [
        "advlist autolink lists link image charmap print preview anchor",
        "searchreplace visualblocks code fullscreen textcolor imagetools",
        "insertdatetime media table contextmenu paste sh4tinymce filemanager"
    toolbar: "styleselect | bold underline italic | alignleft aligncenter alignright | bullist numlist | forecolor backcolor | link media sh4tinymce | fullscreen code | filemanager",
    autosave_ask_before_unload: false,
    max_height: 1000,
    min_height: 300,
    height: 500,
	browser_spellcheck: true,
	paste_data_images: true,
    menubar: false,
    relative_urls: false,
    browser_spellcheck: true,
    setup: function (editor) {
        editor.on('init', function (e) {
            if (htmlContent) {



Setup Git Repo on Digital Ocean Droplet

by 2. April 2016 06:38

This tutorial will show you how to set up a fully fledged Git server using SSH keys for authentication. It will not have a web interface, this will just cover getting Git installed and your access to it set up. We'll use the host "" in place of the domain you will use for your VPS.

This can be a great option if you want to keep your code private while you work. While open-souce tends to be the status quo, there are some times when you don't want to have your code freely available. An example would be if you are developing a mobile app, especially a paid one. Keep in mind this code can be read by anyone if they know the URL address to use for a clone, but that is only if they know it.

There is one major concern for many and that is a web interface to your repositories. GitHub accomplishes this amazingly well. There are applications that you can install such as Gitosis (, GitList (, and Goblet ( We don't go over those in this tutorial, but if you rely heavily on a graphic interface then you may want to look over those and think about installing one of them as soon as you done installing your Git server.

Next, the VPS will need a user specifically for Git. Most people will simply create a user called "Git", and that is what we'll do for this tutorial but feel free to name this user whatever you'd like.


Setup a Git User and Install Git on your VPS

Log into your VPS, and gain root*:


su -

*Some people feel uncomfortable using root in this manner. If your VPS is set up to use sudo, then do so.


Add the Unix user (not necessarily Git user names) to handle the repositories:


useradd git

Then give your Git user a password:


passwd git

Now it's as easy as:


CentOS/Fedora: yum install git

Ubuntu/Debian: apt-get install git

Add your SSH Key to the Access List

At this point, you'll want to be logged in as the Git user. If you haven't already logged in to that user, use this command to switch to it:


su git

Now you need to upload your file to your Git user's home directory. Once you have done that, we need let the SSH daemon know what SSH keys to accept. This is done using the authorized keys file, and it resides in the dot folder "ssh". To create this, input:


mkdir ~/.ssh && touch ~/.ssh/authorized_keys

Note: Using the double '&' in your command chains them, so it tells the system to execute the first command and then the second. Using the 'tilde' at the beginning of the path will tell the system to use your home directory, so '~' becomes /home/git/ to your VPS.


We are going to use the 'cat' command, which will take the contents of a file and return them to the command line. We then use the '>>' modifier to do something with that output rather than just print it in your console. Be careful with this, as a single '>' will overwrite all the contents of the second file you specify. A double '>' will append it, so make sure you know what you want to do and in most cases it will be easier to just use ">>" so that you can always delete what you append rather than looking to restore what you mashed over.


Each line in this file is an entry for a key that you wish to have access to this account. To add the key that you just uploaded, type the following, replacing :


cat .ssh/ | ssh user@ "cat >> ~/.ssh/authorized_keys"

Now you can see the key there if you use cat on the authorized key file:


cat ~/.ssh/authorized_keys

If you want to add others to your access list, they simply need to give you their key and you append it to the authorized keys file.


Setup a Local Repository

This is a pretty simple process, you just call the Git command and initialize a bare repository in whichever directory you'd like. Let's say I want to use "My Project" as the project title. When creating the folder, I'd use all lower case, replace any spaces with hyphens, and append ".git" to the name. So "My Project" becomes "my-project.git".


To create that folder as an empty Git repository:


git init --bare my-project.git

Thats it! You now have a Git repository set up on your VPS. Let's move on to how to use it with your local computer.


Using your Git Server from your Local Computer

On Linux or Mac OS, you need to change the remote origin to your newly created server. If you already have a local repo that you want to push to the server, change the remote using this command:


git remote set-url origin

If this is a new repository you are setting up, use this:


git init && git remote add origin

Now you may add, push, pull, and even clone away knowing that your code is only accessible to yourself.


But what if you want a few trusted people to have access to this server and you want to keep things simple by sorting them by the names of your users? A simple and effective way to do that is to create a folder named after each person, so in the home folder for your Git user list, input:


mkdir user1 user2

Now when you specify the remote repository, it would look like this:


git remote add origin 

Step 1: Create SSH Public/Private Key Using PuTTY 

1. Download and start the puttygen.exe generator (download location:

2. In the "Parameters" section choose SSH2 DSA and press Generate.

3. Move your mouse randomly in the small screen in order to generate the key pairs.

4. Enter a key comment, which will identify the key (useful when you use several SSH keys).

5. Type in the passphrase and confirm it. The passphrase is used to protect your key. You will be asked for it when you connect via SSH.

6. Click "Save private key" and then "Save public key" to save both keys to your disk.