web.config Redirect non-www to www

That often looked for website redirect from the non-www version of the website URL, address, to the www version.

In this case the redirect is for a Windows hosted website, using the web.config file to set the redirect rules.

I wish to avoid adding the redirect within the website coding. By taking advantage of the redirect rules within the web.config file. This will make them readily available and can be edited without recompiling the website code.

Access your website either using FTP or the editor/manager within the housing website control panel.

The file to be edited is located at the root of the website. This may be a directory down. Check if you have a directory such as public_html.

It’s easier to edit the content of the web.config file of is laid out correctly and colour coded. An HTML editor will make your life easier when editing.

Shown below is the code to add the redirect of the non-www address to www to be added to the web.config asp.net website configuration file:

<rewrite>    
    <rules> 
        <rule name="Canonical" stopProcessing="true"> <match url=".*" /> 
            <conditions> 
                <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> 
            </conditions> 
            <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" /> 
        </rule> 
</rewrite>

The above is to be added within the section <system.webserver>

As as a bonus below is the HTTPS version too!

<rewrite>    
    <rules> 
        <rule name="Redirect to HTTPS" stopProcessing="true"> 
            <match url="(.*)" /> 
            <conditions> 
                <add input="{HTTPS}" pattern="^OFF$" /> 
            </conditions> 
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> 
        </rule> 
    </rules> 
</rewrite>

Putting this all together gives:

<rewrite>    
    <rules> 
        <rule name="Canonical" stopProcessing="true"> <match url=".*" /> 
            <conditions> 
                <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> 
            </conditions> 
            <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" redirectType="Permanent" /> 
        </rule> 
        <rule name="Redirect to HTTPS" stopProcessing="true"> 
            <match url="(.*)" /> 
            <conditions> 
                <add input="{HTTPS}" pattern="^OFF$" /> 
            </conditions> 
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> 
        </rule> 
    </rules> 
</rewrite>    

Technically it’s a 301 or 302 redirect. Looking at the code above it can be seen that I’ve used the redirectType parameter value of permanent showing the redirect to be of type 301. web.config rewrite rules to permanently redirect non-www to www.

Change Windows 2008 User Password Lost Current Password

Having lost the current password for a Windows 2008 server user account. How do I change the password?

If I follow the control panel link to the user and look to reset the password, a part of the dialogue requires entry of the current password. Which I didn’t have!

Its possible to get around this requirement from a command prompt.

Right click on command prompt, from the menu, and select to run as administrator

Enter

net user username *

When asked, enter the new password, and re enter for confirmation.

Obliged to confirm that the password change is correct and the anticipated value has been entered I once more tried logging in with a remote desktop session from another computer.

Using the command prompt as opposed to the user control panel I was able to reset a user password without the knowledge of the current password.

 

Install ExpressMaint SQL Backup utility

ExpressMaint is a utility which may be used to automate the backup of SQL Server databases.

It can be used to create and save a backup of each of the databases within an SQL Server. Better still it can be set to age the files, deleting all those older than, say, a month.

The ExpressMaint project home page is here: https://expressmaint.codeplex.com/

Download a copy of the zip file ExpressMaint.zip. Extract the ExpressMaint.exe file contained within to your scripts directory.

I’ll assume that the exe file has been added to the folder as: z:\ExpressMaint.exe.

I use a batch file to call the exe file, passing the relevant parameters.

And I have created a backup directory for the databases at z:\backup.

The batch file for running ExpressMaint is located at: z:\expmaint.cmd.

Contents of which are given below

 "z:\expressmaint.exe" -S webserver\SQLserver -D ALL_USER -T DB -R "z:\dbBackup" -RU WEEKS -RV 4 -B "z:\dbBackup" -BU WEEKS -BV 4 -V -TO 20

In the above change the name of the server webserver and Sqlserver as appropriate.

shows example for individual database location

I created a scheduled task to run daily.

On Windows Server 2012 I found that expressmaint.exe wasn’t running as a scheduled task.

Searching for more information about the cause of the issue. I found this on stack exchange, which recommend using a later version of ExpressMaint:

I am actually using expressmaint with sql server 2012 express so u shouldn’t have any problems. make sure u use

https://expressmaint.codeplex.com/downloads/get/91612 which is version 2.0.0.1 and NOT 2.0.0.0

 

Stack Exchange article reference is:

http://dba.stackexchange.com/questions/24750/is-it-possible-to-use-expressmaint-with-sql-server-2012-express/120387

Following the referenced link and using that version of ExpressMaint worked.

Where’s the Windows 10 Control Panel?

Accessing the Control Panel in Windows 10 is one of those of course how obvious moments.

I found that the main control panel home page in Windows 10 was access by simply right clicking on the Windows logo at the bottom left hand corner of the screen.

Right click on the Windows logo to show a menu of admin related options.

Windows 10 open the control panel

The control panel is listed here amongst the other admin actions.

Where is the Windows 10 Services Control Panel?

In Windows 10 the Services control panel is to be found grouped on the Task Manager.

To access the services list begin by opening the Task Manager – right click on the Windows icon in the bottom left of the screen

Windows 10 open task manager

Clicking on Task Manager from this list opens the grouped Task Manager control panel.

Windows 10 task manager

Onto this panel has been grouped a number of the previously discrete individual views including the Services control panel.

Windows 10 task manager services

Click on the last tab to show the Services.

Taking Screenshots on Windows 10

Taking a screenshot of the display on a computer can be a great way to convey the configuration settings or an error message.

Preparing the article Install IIS on Windows 10 I was interested in taking screenshots of my progress through the various screens.

I looked at using the pnt scr key.The choices associated with this option are more limited. Having taken the screenshot it requires a document to paste into. I wished to be able to do a simple save to a jpg file. Further, its a simple screen capture, rather than the capture of a selected window or a rectangular area of the window.

I chose to use the  Snipping tool.

To start this I began typing the word snipping in the search box at the bottom left of the screen until the word snipping was presented as an option.

Using the snipping tool I found it convenient to select the New>Window option. I was then able to select from the open windows and click on capture.

Having captured the window, with a trigger delay if it helps, I saved the file for use.

The saved file is of a quality and file size greater than will be required on a website. A smaller file size is downloaded quicker making the page load faster giving happier website visitors and better search engine results.

I used the Gimp to edit my images, reducing the saved image quality. If I had more images to adjust them a program such as XnConvert may have been more appropriate.

Screenshots on Windows 10 continue to support the use of the prt scr key.

Install IIS on Windows 10

For testing and development it’s convenient to install IIS on a Windows computer. In this case Windows 10.

IIS is installed through the Windows features control panel.

To access the Windows features, begin by opening the control panel by right clicking on the Windows logo. From the control panel home select the Programs and then Turn Windows features on and off.

Or if you prefer type the name of the control panel appwiz.cpl into the search box and press enter.

This will open the first stage, the Programs and features control panel.

Windows 10 install IIS programs and features

Click on Turn Windows features on or off in the left hand menu column. This will open a popup showing the list of features available.

Windows 10 install IIS Windows features

From the list select entries pertaining to IIS.

Windows 10 install IIS Windows features IIS options

You may wish to select the outer element allowing it to populate a typical set of options.

Once done click on OK at the bottom

Windows 10 install IIS Windows features applying changes

The new additions will be added.

Windows 10 install IIS Windows features changes completed

Until all is installed.

Checkout your installation of IIS by navigating to http://localhost.

Windows10 install IIS localhost confirmation

 

web.config Redirect http to https

Windows server with IIS allows website redirects to be configured in the web.config file, located at the root of the website files directory.

I wished to add the following rule to redirect http web pages to https

<rule name="Redirect to HTTPS" stopProcessing="true">
  <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>

The web.config file provides the main configuration and settings for asp.net server application framework and the website server.

The file is organised as a series of settings within a nested structure. Each item is wrapped within a less than and greater than pair.  Shown below is an example web.config file:

<?xml version="1.0"?>
<configuration>
   <system.web>
     .. existing text ..
     .. existing text ..
   </system.web>
   <system.webServer>
      <defaultDocument enabled="true">
         <files>      
            <clear/>              
            <add value="index.html"/>
            <add value="default.aspx/>
         </files>
      </defaultDocument>
   </system.webServer>
</configuration>

The rule is added to the rewrite section within the system.webserver section.

Open the web.config file with an HTML editor. I use Geany or Bluefish if using an Apple Mac.

Scroll down the file looking for the web.server section. It begins <system.webserver>.

If there are already redirect rules configured there’ll be a section for these. The wrappers for the rules begins:

<rewrite>
  <rules>

Its possible that rules have not previously been configured and will need to be added.

Shown below is the same basic web.config file with the redirect rules for http to https added:

<?xml version="1.0"?>
<configuration>
   <system.web>
     .. existing text ..
     .. existing text ..
   </system.web>
   <system.webServer>
      <defaultDocument enabled="true">
         <files>      
            <clear/>              
            <add value="index.html"/>
            <add value="default.aspx/>
         </files>
      </defaultDocument>
      <rewrite>
        <rules>
          <rule name="Redirect to HTTPS" stopProcessing="true">
            <match url="(.*)" />
              <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
              </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
          </rule>
        </rules>
      </rewrite>
   </system.webServer>
</configuration>

Wikipedia has a rather short entry for the web.config file.

IIS Adding Support for Font Families

By default IIS doesn’t support all of the font family types used in CSS. Additional media support entries may be required.

Below is a typical font family definition, as used within a CSS file.

@font-face {font-family: 'my-font';src:
    url(inc/fonts/my-font.otf) format('truetype'),
    url(inc/fonts/my-font.eot) format('eot'),
    url(inc/fonts/my-font.woff) format('woff');}

Whilst configuring a website hosted on Windows server I found that Internet Explorer wasn’t adopting the specified font family.

I checked the HTML and CSS on a Linux server with Apache. All was well and Internet Explorer was showing the correct font, confirming that my definitions were correct, no spelling errors or missing characters.

Using Firebug on Firefox I was able to see that the woff file was being requested but not downloaded.

By adding the media type for woff to IIS I was able to resolve this problem.

Add font Media Type

Font media types are added to IIS as per any media type.

IIS adding font familiy support

From within the IIS manager select the server root in the left menu to show its home menu, with options for IIS, management and not shown in this view, ASP.NET, FTP.

IIS adding font familiy support mime types

Click on the MIME Types, within the IIS section to show a list of those configured.

IIS adding font familiy support add mime type

At the top right corner click on Add.

IIS adding font familiy support add mime type woff

To add a new MIME type enter the extension and the MIME type within the Add MIME Type popup window:

IIS adding font familiy support mime types includes woff

The addition of the woff font added to the list of installed MIME Types.

IIS Media Types

The table below gives the media types for the common font types

Extension Media Type
.eot application/vnd.ms-fontobject
.ttf application/octet-stream
.otf application/font-sfnt
.svg image/svg+xml
.woff application/font-woff
.woff2 application/font-woff2

Looking at the IIS mime support for the font types I observed the following default font support:

Media Type Extension Configured by default
TrueType .ttf Yes
Embedded OpenType .eot Yes
OpenType .otf No
Web Open Font Format .woff No

Windows RDP change user password

In a remote desktop session (RDP) accessing the account password settings with <CTRL> + <ALT + <DELETE> is not available. An alternative method is required.

On a Windows computer pressing <CTRL> + <ALT> + <DELETE> provides access to profile settings such as the user password.

From within remote desktop the <CTRL> + <ALT> + <DELETE> key combination is transferred back to the parent computer, with loss of control from the active remote desktop session.

Therefore a different key combination to the usual ctrl alt del is required to access the user password configuration when used from within a remote desktop session.

I found that using the key combination <CTRL + <ALT> + <END> leaves the remote desktop active, focus is not withdrawn back to the parent computer. The active screen is replaced by a summary action  screen showing the options:

  • Lock this computer
  • Log off
  • Change a password…
  • Start Task Manager

Click on Change a password. On the following screen enter the existing password, followed by the new password and a second entry to ensure that it was typed correctly. Click on OK to complete.

From within a Windows RDP I am able to update an expired password. However, for Android and Linux originated sessions I find that access to the server is not given.

Regularly updating your password is good security practice and ensures that Windows doesn’t lock you out following the expiry of the current password.