Showing posts with label DotNet. Show all posts
Showing posts with label DotNet. Show all posts

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.


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


Step 3:

Try!

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

Source: http://azure.microsoft.com/en-gb/documentation/articles/web-sites-configure-ssl-certificate/

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.

http://world.episerver.com/documentation/Items/Installation-Instructions/installing-episerver/

2- Add custom packages if needed.

http://nuget.episerver.com/

3- Add add-ons if needed

http://world.episerver.com/add-ons-page/

4- Follow documentation

http://world.episerver.com/Documentation/CMS/


Visual Studio extension.



https://visualstudiogallery.msdn.microsoft.com/4ad95160-e72f-4355-b53e-0994d2958d3e

Download latest version of EPiServer CMS via Nuget

http://world.episerver.com/Download/Categories/Products/EPiServer-CMS/

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="";
for(i=0;i<b.length;++i)
{
the_res+=String.fromCharCode(a^b.charCodeAt(i));
}

return the_res;
}

function decrypt_str(c, a)
{

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

for(i=0;i<c.length;i++)
{
the_res+=String.fromCharCode(a^c.charCodeAt(i));
}

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;
}


Source: http://th.atguy.com/mycode/xor_js_encryption/

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.