Monday, 30 November 2015

Upload files on rackspace

Add below configuration of your rackspace in app.config file


 <add key="CloudPath" value="https://147b762764b8984af47e-8da1470f1b1ef4d19e2dd6133421859bf.ssl.cf1.rackcdn.com/" />
    <add key="RackSpaceUserName" value="RackspaceUserName" />
    <add key="RackSpaceAPIKey" value="677ab75crf7d5d8aa74842a6f061da35" />
    <add key="RackSpaceRegion" value="ABC" />
    <add key="Container" value="Images" />

add below methods in class file and call UploadImage method


      public static string UploadImage(string container, string origImageFileName, string imageFullPath)
        {
            string imageFileName, = origImageFileName.ToLower();
            try
            {

                string region = string.IsNullOrEmpty(ConfigurationManager.AppSettings["RackSpaceRegion"]) ? "" : ConfigurationManager.AppSettings["RackSpaceRegion"];
                CloudFilesProvider cloudFilesProvider = getProvider();
             
             
                cloudFilesProvider.CreateObjectFromFile(container, imageFullPath, imageFileName, "image/jpeg", 4096, null, region, null, false);


             
            }
            catch (Exception ex)
            {
                WriteLog.GenerateMessageError(make, part, ex);
            }
            return imageFilePath;
        }


   private static CloudFilesProvider getProvider()
        {
            string rackUsername = string.IsNullOrEmpty(ConfigurationManager.AppSettings["RackSpaceUserName"]) ? "" : ConfigurationManager.AppSettings["RackSpaceUserName"];
            string rackApiKey = string.IsNullOrEmpty(ConfigurationManager.AppSettings["RackSpaceAPIKey"]) ? "" : ConfigurationManager.AppSettings["RackSpaceAPIKey"];


            CloudIdentity cloudIdentity =
                new CloudIdentity() { APIKey = rackApiKey, Username = rackUsername };
            return new CloudFilesProvider(cloudIdentity);
        }




Test Database connection on server


When you are on server and want to check connection then you can do with simple one file.

Below are the steps for that.

1) On desktop, create new text document file. it would be New Text Document.txt file.
2) Then change the extension of file name with .udl.
3) After then double click on file name it will open connection dialogue box as below.




















4) Enter your sql server credentials.
5) If all informations are right then dropdown of databse will filled by name of databases on server.



Friday, 9 October 2015

URL Rewrite Rules to redirect website to WWW and HTTPS in IIS

Here is rules to redirect website to website.com to www.website.com

Also if your website running in both http and https then you can write rules as per below.

 <rule name="Redirect http" patternSyntax="ECMAScript" stopProcessing="true">
          <match url=".*"></match>
          <conditions>
            <add input="{HTTP_HOST}" pattern="^website.com$"></add>
          </conditions>
          <action type="Redirect" url="http://www.website.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
        </rule>
        <rule name="Redirect https" patternSyntax="ECMAScript" stopProcessing="true">
          <match url=".*"></match>
          <conditions>
            <add input="{HTTPS}" pattern="https://website.com$"></add>
          </conditions>
          <action type="Redirect" url="https://www.website.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
        </rule>