Lions Den

The Code and Times of Hanan Schwartzberg

About Hanan | Hanan's CV | Contact Hanan

January 23, 2015

WordPress blog on Windows not found

Filed under: IIS7,IIS8 — Tags: , , , — Hanan Schwartzberg @ 6:49 am

The Issue

When migrating an existing WordPress blog, instead of creating a new one, the admin section of the blog works fine, but the front-end throws a 404 error.

The Solution

First step is to make sure everything is setup correctly. Japinator has an excellent step by step explanation of how to Create a WordPress blog on Windows Server 2008 R2, IIS 7.5 and MySQL. The tutorial is written for Windows 2008 and IIS7, but it works just as well with Windows 2012 and IIS8.

Once everything is setup correctly, if it’s an existing blog from a Linux environment, the problem will still persist.

Amrit Ray has a WordPress on Windows – Issues & Solutions. He explains that you need to use the Url Rerwiting module for IIS, available here http://www.iis.net/downloads/microsoft/url-rewrite because Linux creates the .htaccess file with the required permalink settings automatically, but in Windows you have to set it up manually.

To do this, after the Url Rewrite module is installed add the following web.config file to folder containing the WordPress blog.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <defaultDocument>
      <files>
        <clear/>
        <add value="Default.htm"/>
        <add value="Default.asp"/>
        <add value="index.htm"/>
        <add value="index.html"/>
        <add value="iisstart.htm"/>
        <add value="default.aspx"/>
        <add value="index.php"/>
      </files>
    </defaultDocument>
    <rewrite>
      <rules>
        <rule name="wordpress" patternSyntax="Wildcard">
        <match url="*"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Rewrite" url="index.php"/>
        </rule></rules>
    </rewrite>
  </system.webServer>
</configuration>

November 18, 2013

ASP.NET Relative Urls (~/) Not Rendering Correctly in a HyperLink ImageUrl

Filed under: ASP.NET,C# — Tags: , , , , , , , , , — Hanan Schwartzberg @ 2:47 pm

The Issue

When using a HyperLink object on masterpage the relative url assigned to the ImageUrl property is not resolving correctly on certain pages. The problem appears to only affect pages where a url rewrite has been used and the level of directories does not match the actual level of directories of the page. For instance, if the url “http://www.mysite.com/categories/book.aspx” actually loads “http://www.mysite.com/products/categories/default.aspx?type=books”, the the below hyperlink will resolve as “../products/images/bbb_logo.gif”. On all other pages it will correctly resolve as “../images/bbb_logo.gif”.

<asp:HyperLink runat="server" ID="hlBBB" Target="_blank" 
        NavigateUrl="http://www.bbb.org" ImageUrl="~/Images/bbb_logo.gif" />

Attempting to resolve the url manually in the code behind doesn’t work either. The following code results in the same incorrect url.

hlBBB.ImageUrl = ResolveClientUrl("~/images/bbb_logo.gif");

The Solution

There are two ways to work around this.

  1. This bug seems to be exclusive to the HyperLink object. Remove the image from the HyperLink and the ImageUrl will resolve correctly. For instance, the above HyperLink should be rewritten as:
    <asp:HyperLink runat="server" ID="hlBBB"
        NavigateUrl="http://www.bbb.org">
        <asp:Image runat="server" ID="imgBBB" ImageUrl="~/Images/bbb_logo.gif" />
    </asp:HyperLink>
  2. If you really want to leave the image in the HyperLing object. You can work around the problem in the code behind. The ResolveClientUrl method doesn’t work because takes into account the page’s location in the site, which between the rewrite and the actual location of the page seems to be inaccurate. Instead use VirtualPathUtility.ToAbsolute to resolve the url. This method can be used anywhere on the site, not just on pages and user controls and will resolve the url with an absolute path (“/images/bbb_logo.gif”).

April 18, 2010

IIS7.5 “HTTP Error 500.19 – Internal Server Error”

Filed under: IIS7 — Tags: , , , — Hanan Schwartzberg @ 10:33 pm


The symptom

After loading an ASP.NET web application on an IIS7.5 server, navigating to the site resulting in the following error:

HTTP Error 500.19 - Internal Server Error


The search for a cause and a solution

The first step was this Microsoft KB Article that breaks down the 500.19 error based on the HResult: http://support.microsoft.com/kb/942055. Unfortunately, for the HResult above, 0x8007000d, the only cause listed is “a malformed XML elemen” in the web.config. After spending some time looking at the web.config I came to the conclusion there were no malformed tags.

The next solution I found was from JohnnyW on ASP.NET, http://forums.asp.net/p/1497910/3536801.aspx#3536801. JohnnyW’s error was evidently caused by Ajax not being properly installed. He includes this link on how to configure AJAX for ASP.NET. Since, due to some old controls we do require the AJAX 1.0 extensions to be installed I made the changes to the web.config it recommends, but still kept getting the same error.

I decided to manually hunt for the cause in the web.config and so I started to remove sections one at a time until the error disapeared and the site loaded.


The actual cause and soluion

The section that was actually causing the error was the rewrite section.

<rewrite>
  <rules>
    <rule name="Redirect to www" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" 
            pattern="^www.mySite.com$" />
        <add input="{HTTP_HOST}" 
            pattern="^mySite.com$" />
        <add input="{HTTP_HOST}" 
            pattern="^mySite.com$" />
      </conditions>
      <action type="Redirect" 
          url="http://www.my_Site.com/{R:0}"
          redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

Searching for information on redirect rules led me to http://geekswithblogs.net/kit/archive/2009/04/19/131291.aspx, where he explains you can use URL Rewrite “by installing the URL Rewrite Module.” This was what actually caused the 500.19 error. The server didn’t have the url rewrite module installed. I solved the issue by downloading the IIS URL Rewrite 2.0 from here: http://www.iis.net/download/URLRewrite and installing it. Instantly the 500.19 error was cleared up.

Home | Site Design | Banner Design | Code Den | Offsite Posts | Downloads | Photography | About Hanan | Hanan's CV | Contact Hanan
Copyright © 2009 Hanan Schwartzberg. All rights reserved.