Tuesday, January 5, 2021

How to set up an HTTP/HTTPS redirect in IIS

In order to force a secure connection on our website, it is necessary to set up a certain HTTP/HTTPS redirection rule. This way, anyone who enters your site using a link like “domain.com” will be redirected to “https://domain.com” or “https://www.domain.com” (depending on your choice) making the traffic encrypted between the server and the client side.

Steps to setup an IIS HTTPS redirect:

  • Download and install the URL Rewrite module.
  • Open the IIS Manager console and select the website you would like to apply the redirection to in the left-side menu:
  • Double-click on the URL Rewrite icon.
  • Click Add Rule(s) in the right-side menu.
  • Select Blank Rule in the Inbound section, then press OK.
  • Enter any rule name you wish.
  • In the Match URL section:
    • Select Matches the Pattern in the Requested URL drop-down menu
    • Select Regular Expressions in the Using drop-down menu
    • Enter the following pattern in the Match URL section: (.*)
    • Check the Ignore case box
  • In the Conditions section, select Match all under the Logical Grouping drop-down menu and press Add.
  • In the prompted window:
    • Enter {HTTPS} as a condition input
    • Select Matches the Pattern from the drop-down menu
    • Enter ^OFF$ as a pattern
    • Press OK
  • In the Action section, select Redirect as the action type and specify the following for Redirect URL:

    https://{HTTP_HOST}{REQUEST_URI}
  • Un-check the Append query string box.
  • Select the Redirection Type of your choice. The whole Action section should look like this:
    NOTE: There are 4 redirect types of the redirect rule that can be selected in that menu:
    • Permanent (301) – preferable type in this case, which tells clients that the content of the site is permanently moved to the HTTPS version. Good for SEO, as it brings all the traffic to your HTTPS website making a positive effect on its ranking in search engines.
    • Found (302) – should be used only if you moved the content of certain pages to a new place *temporarily*. This way the SEO traffic goes in favour of the previous content’s location. This option is generally not recommended for a HTTP/HTTPS redirect.
    • See Other (303) – specific redirect type for GET requests. Not recommended for HTTP/HTTPS.
    • Temporary (307) – HTTP/1.1 successor of 302 redirect type. Not recommended for HTTP/HTTPS.
    OPTION 2: Specify the Redirect Rule as https://{HTTP_HOST}/{R:1} and check the Append query string box. The Action type is also to be set as Redirect.
  • Click on Apply on the right side of the Actions menu.


The IIS redirect can be checked by accessing your site via http:// specified in the URL. To make sure that your browser displays not the cached version of your site, you can use anonymous mode of the browser.

The rule is created in IIS, but the site is still not redirected to https:// Normally, the redirection rule gets written into the web.config file located in the document root directory of your website. If the redirection does not work for some reason, make sure that web.config exists and check if it contains the appropriate rule.

To do this, follow these steps:
  • In the sites list of IIS, right-click on your site. Choose the Explore option:
  • Explore will open the document root directory of the site. Check if the web.config file is there.
  • The web.config file must have the following code block

    <configuration>
     <system.webServer>
     <rewrite>
     <rules>
     <rule name="HTTPS force" enabled="true" stopProcessing="true">
     <match url="(.*)" />
     <conditions>
     <add input="{HTTPS}" pattern="^OFF$" />
     </conditions>
     <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
     </rule>
     </rules>
     </rewrite>
     </system.webServer>
    </configuration>


    Note: This is a default configuration. If you'd like to change it, you might need to check this server documentat
    ion
    .
  • If the web.config file is missing, you can create a new .txt file, put the aforementioned code there, save and then rename the file to web.config.

Sunday, December 13, 2020

Shopify - Add password protection to your online store

Add password protection to your online store

You can add password protection to your online store.

Steps:

  • From your Shopify admin, go to Online Store > Preferences.
  • Scroll to the Password protection area, and check Enable password.
  • In Password, enter the password that you'll give to the customers who you want to be able to access your online store. Don't use the same password that you use to log into your admin.
  • In Message for your visitors, enter the message that you want to show on the password page. If you don't want to show a message, then leave this field blank.
  • Click Save.

 

Edit your password page settings

You can edit the content that shows on your password page, such as the text, colors, and typography. 

  • From your Shopify admin, go to Online Store > Themes.
  • Find the theme that you want to edit and click Customize.
  • Select Password page from the top bar drop-down menu. If you don't see Password page in the menu, then you need to add password protection to your online store.
  • To edit the sections on the password page, do the following tasks
    •  Click Sections.
    • Click on the section that you want to edit. Most themes have header, content, and footer sections.
    • Make changes to the section settings.
    • Click Save.
  • To edit the theme settings for the password page, do the following tasks:
    • Click Theme settings.
    • Click on the settings category that you want to edit. Most themes have color, typography, social, and favicon settings.
    • Make changes to the theme settings.
    • Click Save.

 

Thursday, September 24, 2020

A generic error occurred in GDI+ while creating image from Base64 string

In a web service, while converting a Base64 string to file, it is sometimes giving error  - "A generic error occurred in GDI+ while creating image from Base64 string".

Solution:

I have used the below code and problem resolved.


[HttpPost]
public ActionResult UploadSignatureTwo(String imageString){     
    var bytes = Convert.FromBase64String(imageString);
    using (var imageFile = new FileStream(Path.Combine(path,"test.jpeg"), FileMode.Create))
    {
        imageFile.Write(bytes, 0, bytes.Length);
        imageFile.Flush();
    }
}

Wednesday, May 27, 2020

svg file not upload in wordpress

Cannot upload SVG files in WordPress


When we upload the SVG file, we recieve the notification “Sorry, this file type is not permitted for security reasons.”

To Resolve this issue, we need to add the below function in the functions.php files

function cc_mime_types($mimes) {
 $mimes['svg'] = 'image/svg+xml';
 return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');

This will resolve the issue.


Tuesday, April 28, 2020

Wordpress, Gravity form - Remove space between currency symbol and amount

Wordpress, Gravity form - Remove space between currency symbol and amount


Remove space between currency symbol and amount

Please use the below WordPress in the theme Function (functions.php) file

add_filter('gform_currencies', 'update_currency');
function update_currency($currencies) {
    $currencies['GBP'] = array(
        'name' => __('Pound', 'gravityforms'),
        'symbol_left' => '£',
        'symbol_right' => '',
        'symbol_padding' => '',
        'thousand_separator' => ',',
        'decimal_separator' => '.',
        'decimals' => 2);
    return $currencies;
}

Change Currency symbol from left to right

Please use the below WordPress in the theme Function (functions.php) file:

add_filter('gform_currencies', 'update_currency');
function update_currency($currencies) {
    $currencies['GBP'] = array(
        'name' => __('Pound', 'gravityforms'),
        'symbol_left' => '',
        'symbol_right' => '£',
        'symbol_padding' => '',
        'thousand_separator' => ',',
        'decimal_separator' => '.',
        'decimals' => 2);
    return $currencies;
}

Wordpress Yoast, Change breadcrumb trail from post to page

WordPress Yoast, Change breadcrumb trail from  to page


Please use the below WordPress in the theme Function (functions.php) file

add_filter('wpseo_breadcrumb_links', 'wpse_post_breadcrumbs');
// $links are the current breadcrumbs
function wpse_post_breadcrumbs($links) {
    // Use is_singular($post_type) to identify a single CPT
    // This assumes your CPT is called "post" - change it as needed 
if(is_singular('post')) {
        // The first item in $links ($links[0]) is Home, so skip it
        // The second item in $links is Projects - we want to change that
        $links[1] = array('text' => 'News', 'url' => '/news/', 'allow_html' => 1);
    }
    // Even if we didn't change anything, always return the breadcrumbs
    return $links;
}

htaccess 301 redirect from one pages to another page

htaccess 301 redirect from one pages to another page

301 Redirect from page1 to page2

please use the below code in the htaccess file:

RewriteEngine On
Redirect 301 /page1/ /page2/
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Saturday, March 7, 2020

Datatable.net - Get Reordering of the columns & Get Column visible

Datatable.net - Get Reordering of the columns & Get Column visible

Please add a button on the form like below
<a class="btn btn-success visiblecheck" href="javascript:void(0);" id="visiblecheck" value="test">visiblecheck</a>

Here is 'table' is variable of Datatable.net like

var table = $('#example').dataTable();


$('.visiblecheck').click(function () {
        alert(table.colReorder.order());
        var columnvisible = '';

        for (i = 0; i < table.columns().count(); i++) {
            if (columnvisible != '') {
                columnvisible += ',';
            }
            if (table.column(i).visible() === true) {
                columnvisible += '1';
            }
            else {
                columnvisible += '0';
            }
        }
        alert(columnvisible);
    });


table.colReorder.order() -  this will return the ordering of columns

Tuesday, January 28, 2020

whats the difference between == and === ?

The difference between == and === is that:


1. == converts the variable values to the same type before performing comparison. This is called type coercion.
2. === does not do any type conversion (coercion) and returns true only if both values and types are identical for the two variables being compared.

Example:

  1. var one = 1;
  2. var one_again = 1;
  3. var one_string = "1"; // note: this is string
  4. console.log(one == one_again); // true
  5. console.log(one === one_again); // true
  6. console.log(one == one_string); // true. See below for explanation.
  7. console.log(one === one_string); // false. See below for explanation

Wednesday, January 15, 2020

System.InvalidCastException: 'Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'

System.InvalidCastException: 'Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'

 The error because the URL is not proper. please pass the proper url containing http:// or https://.

and also check that URL is correct.