Thursday, April 23, 2015

Redirect http request to https on Microsoft Azure website

If you want force user to use https then you can create a redirect by following steps. Example is giving for Azure websites but it is possible in Azure Cloud app in many other way as it is more flexible.

Step 1:

Open you Azure portal go to you web app and on top menu choose Configure scroll down to certificates as show in figure.
Remember you need a valid SSL certificate for https otherwise it will show in red and it will be not trustworthy. Upload your certificate.
Go to ssl bindings section and select your domain, choose your SSL certificate to for requirement in case of multiple domains and certificates and then choose IP Based SSL.

Step 2:

Go to your web.config. Make sure choose the right one in case of multiple configs available.
Then paste this code.

        <rule name="Force HTTPS" enabled="true">
          <match url="(.*)" ignoreCase="false" />
            <add input="{HTTPS}" pattern="off" />
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />

Step 3:


If you want more detail step by step information please refer to source below.


Monday, March 16, 2015

EPiServer Development Tutorial

Now in EPiServer CMS 7.5 (8) company has changed old way of installation and configuration. In the past older version of EPiServer 5-6 you were suppose to download setup and extract the CMS application file to IIS and configure it. But in EPiServer veriosn 7,x has changed the whole story.

You just need to download Visual Studio extension.
You can create empty or sample template projects and you are ready to do custom development on it. You can also add custom add-ons.

Here are some steps to start EPiServer CMS development.

1- Download VS extension.

2- Add custom packages if needed.

3- Add add-ons if needed

4- Follow documentation

Visual Studio extension.

Download latest version of EPiServer CMS via Nuget

Wednesday, March 4, 2015

Simple Encryption Alogarithm Multiple Language: JavaScript to C#

Some time need encrypt some data on client-side (Javascript) and decrypt it on server-side here is small solution.

function encrypt_str(a, b)

var the_res="";

return the_res;

function decrypt_str(c, a)

var the_res="";//the result will be here


return the_res;

  public static string encrypt_str(int a, string b)
       string c ="";

       for(int i=0;i<b.Length;++i)
                var xor = (char)(a ^ ((int)b[i]));
           c = c + xor;

            return c;

public static string decrypt_str(string c, int a)

       string b ="";

       for(int i=0;i<c.Length;i++)

           var xor = (char) (a ^ ((int) c[i]));

           b = b + xor;


             return b;


Wednesday, January 15, 2014

DateTime validation error in Firefox, Chrome, Safari - IE in ASP MVC Mobile Application

This is common date validation error in Firefox, Chrome, Safari and Internet Explorer when you are creating ASP MVC Mobile Application Here is the solution to solve it.

1- Add follow tag in web.config

 <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="sv-SE" uiCulture="sv-SE"/>

2- Open JQuery file as shown in picture and add following code.

$ = function (value, element) {
        return this.optional(element) || (/^(19[0-9]{2}|2[0-9]{3})-(0[1-9]|1[012])-([123]0|[012][1-9]|31)[ \/T\/t]([01][0-9]|2[0-3]):([0-5][0-9])(?::([0-5][0-9]))?$/.test(value)


MVC Ajax Loading Icon when navigating to a new page/action method

Answered by Chad LaCroix on Stackoverflow

I kept the link on my menu.cshtml page as an @Html.ActionLink rather than an ajax link. But I added an onclick html attribute that called the javacript to show the spinner.
    ViewBag.Title = "Menu";
    Layout = "~/Views/Shared/_Layout.cshtml";

<div class="container" style="text-align:center">
        @Html.ActionLink("Orders", "Index", "Orders", null, new { id = "OrderLink", onclick="showPageLoadingSpinner()" })
I have the scipt for the spinner in my _Layout.cshtml partial view. which is referenced in my menu.cshtml view: Layout = "~/Views/Shared/_Layout.cshtml";
Below is my full _Layout.cshtml page including the ajax div and script references.
    @Content.Script("jquery-1.5.1.min.js", Url)
    @Content.Script("jquery.unobtrusive-ajax.min.js", Url)

    <div id="ajaxLoaderDiv" style="position:fixed; top:40%; left:45%; z-index:1234; display:none;">
    <div class="container">

<script type="text/javascript">
function showPageLoadingSpinner() {
                '<img src="@Url.Content("~/Images/AjaxLoaderImg.gif")" alt="Loading..."class="ajax-loader" />'

 function hidePageLoadingSpinner() {
     setTimeout(function () {
     }, 20000);


Thursday, October 31, 2013

Entity Framework Model SQL datatype Error System.ArgumentException: The version of SQL Server in use does not support datatype 'datetime2

It is common practice we develop applications in latest environment but in production environment we find a downward configuration which lead us to some strange exception in application. If entity framework (EF) is model is created with SQL Server 2008 there are quite a bit chances you will get some datatype exceptions. The most common one is datetime2.

System.ArgumentException: The version of SQL Server in use does not support datatype 'datetime2

It is very easy to fix just right click on your EF Model and select "Open With" and choose XML Editor from list.

In editor find property ProviderManifestToken its value will be 2008 you can change it to 2005, rebuild your application again and you will see your application will work without any exception on your SQL Server 2005 production environment as well.

Wednesday, October 9, 2013

How to import/export data in SQL Server from one to other

Transferring database or data from development machine to production machine is very common thing in deployment stage.

I will show you steps to do that.

Open Microsoft SQL Server Management Studio, select your database, right click on it and select Import Data.

On this step you need to choose a Data Source, give the Server name and authentication and select source database from server. If authentication is correct it will automatically show you the list of databases available on up given server.

Before step you should already create a database where you want to transfer the data. 
Next choose destination where you want to transfer your data again same steps as mentioned above.

Wizard will show table and views available in both databases. Select table you want import from source to destination. Click on Edit Mappings and selection required options. 

Here one thing is notable if you don't have tables created in destination database you still able to transfer and create tables but in case you will loose your all keys and index which you need to setup again on destination database.

Click finish and it will start transferring tables.

Author Qasim Sarfraz