Showing posts with label IIS. Show all posts
Showing posts with label IIS. Show all posts

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.

Thursday, December 27, 2018

IIS, Registering the ASP.Net with IIS server


  1. You need to start command prompt by typing cmd at the Run command and then execute the command prompt with Administrator rights by right clicking and choosing Run as administrator from the context menu.
     
  2. Then on the command prompt you need to navigate to the Directory that has the aspnet_regiis.exe file for that you need to type

      CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
     
  3. Then you need to type the following command and hit enter to register ASP.Net with IIS

      aspnet_regiis -i
     

Tuesday, December 25, 2018

IIS, There was an error when trying to connect. Do you want to retype your credentials and try again?

IIS 8 error on windows server 2012 insufficient permission

There was an error when trying to connect. Do you want to retype your credentials and try again?

Details:

Filename: \?\C:Windows\system32\inetsrv\config\redirection.config Error: Cannot read configuration file due to insufficient permissions

screenshot:

Solution:

Steps to short out this issue:

  1. go to C:\Windows\Microsoft.Net\Framework64\v2.0.50727\CONFIG\machine.config
  2. here you got the redirection tag like the below

    <configurationredirection enabled="true" password="[enc:IISCngProvider:X0ObCWwZ4+PrTHiFVPtzFeCcL8u5P6KUOYfo1/0QrgZWATA5pKWqHvD8nL2crNJKyyqr4z/rBdLPjdRcaLxAMMj4l+lvp5EXXKSXueolvyGa34F4QZfbBVCM6oVNcq3M368TOTVjJv4POVFQWvu0MDVlGgReglXB+Lw5BRI4Htw=:enc]" path="C:\Windows\System32\inetsrv\config\import\" username="Administrator"> </configurationredirection"></li">

    you need to change this to

    <configurationRedirection />

  3. This will resolve the issue.
if you have missed your configuration in IIS then please follow the following steps:
  1. Open the IIS server and open the shared configuration, please check the below screenshots:
     

     
  2. please check the "Enable Shared Configuration" and select the path specified in the your configurationredirection (please check with yelow backgound)

    <configurationredirection enabled="true" password="[enc:IISCngProvider:X0ObCWwZ4+PrTHiFVPtzFeCcL8u5P6KUOYfo1/0QrgZWATA5pKWqHvD8nL2crNJKyyqr4z/rBdLPjdRcaLxAMMj4l+lvp5EXXKSXueolvyGa34F4QZfbBVCM6oVNcq3M368TOTVjJv4POVFQWvu0MDVlGgReglXB+Lw5BRI4Htw=:enc]" path="C:\Windows\System32\inetsrv\config\import\" username="Administrator"> </configurationredirection"></li"> 
  3. Then go to the machine.config file and revert the configurationredirection to previous setup that is

    <configurationredirection enabled="true" password="[enc:IISCngProvider:X0ObCWwZ4+PrTHiFVPtzFeCcL8u5P6KUOYfo1/0QrgZWATA5pKWqHvD8nL2crNJKyyqr4z/rBdLPjdRcaLxAMMj4l+lvp5EXXKSXueolvyGa34F4QZfbBVCM6oVNcq3M368TOTVjJv4POVFQWvu0MDVlGgReglXB+Lw5BRI4Htw=:enc]" path="C:\Windows\System32\inetsrv\config\import\" username="Administrator"> </configurationredirection"></li"> 
  4. Then go to Shared configuration and export the configuration 
  5. after this again change the machine.config configurationredirection  tag to

    <configurationRedirection />
  6. Now again import the Configuration from the Shared configuration from the Shared configuration in IIS.
This will also fix the IIS settings.

Saturday, December 30, 2017

Redirect incoming requests to specific URLs in IIS 7


The Rule "aboutus" is redirect a specific page to a another page.

The Rule "legal" is to redirect the all html files from a folder to a specific page.
<system .webserver="">
        <rewrite>
          <rules>
            <rule name="aboutus">
              <match url="^about-us.html$"></match>
              <action type="Redirect" url="/index.html"></action>
            </rule>
            <rule name="Legal">
              <match url="^Legal/(.*).html$"></match>
              <action type="Redirect" url="/index.html"></action>
            </rule>
          </rules>
        </rewrite>
     </system>