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>

October 19, 2010

Visual Studio 2008 – ASP.NET “System.Runtime.InteropServices.COMException”

Filed under: ASP.NET,IIS7 — Tags: , — Hanan Schwartzberg @ 4:01 pm

The Issue

When openning an existing ASP.NET project for the first time in Visual Studio 2008 it returns the error “System.Runtime.InteropServices.COMException” without any HRESULT code. The problem I experienced was specificly on a Windows 7 machine, but the same solutions should work on Vista as well.

System.Runtime.InteropServices.COMException

(more…)

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.

February 17, 2010

IIS7 Sessions Getting Crossed / Mixed Up / Copied

Filed under: ASP.NET,IIS7 — Tags: , , — Hanan Schwartzberg @ 10:25 pm


The symptom

Users reported seeing data that did not belong to them when they logged into their accounts. Logs showed that nearly 10% of our users were being assigned copies of other users’ sessions. The entire session object was copied, including the sessionVariables and sessionID. Once duplicated the individual sessions could be modified without affecting the other (i.e. abandoning one did not kill the other).

To spot instances of the problem I stored the Request.RemoteHost (The IP address of the computer making the request) in a sessionVariable. At the beginning of each request I checked to make sure the session’s IP matched the current request’s IP.


What is was not

It is possible that the IP would change naturally, most simply if a user reset his router/modem. This was not the case because it was happening way too often. Further, there were confirmed instances of one user’s data being crossed with another’s. Finally, some of the pairs of IPs weren’t just on different computer, but were in different countries.

It is also possible, and was often suggested, that sessionVariables can stop being unique if they are used with static/shared variables within the WebApp. This was not the case either, because the IP address I stored in the session was only written to once, from the request and afterwards was only read to compare back to the request. This was also ruled out because the SessionID was also duplicated and that is a read only value.


What is was

It is a feature/bug in IIS7. This latest version of IIS introduced some new caching features.

  1. IIS7 automatically caches static content, such as HTML pages, images, and style sheets.
  2. IIS7 now has the ability to cache dynamic content as well.

Caching dynamic content is great if it is a page such as a dynamically generated image gallery, or a page that is generated dynamically based on the browser’s culture. However, in this thread, http://forums.iis.net/t/1154347.aspx?PageIndex=2, Anil Ruia, a Senior Software Design Engineer on the IIS Core, explains, “You should not be enabling output caching for any response which depends on session state.”

If the page generating the content depends on the session state, it caches the session object along with the rest of the page. The next user to come through ends up pulling the cached session, instead of getting a new one. When I checked our settings I found it was set to cache all .aspx pages for three minutes, including many pages that access the session.


The solution

Edit Cache Rule

In IIS7, disable the caching for .aspx pages in any directory with an asp.net page that depends on the session state. To do this:

  1. Run the Server Management console.
  2. Navigate to Roles -> Web Server (IIS) -> Internet Information Services.
  3. Select the site you wish to modify.
  4. Select the folder that contains the .aspx pages you need to turn caching off for.
  5. In the Feature View, double-click “Output Caching”.
  6. If there is a rule there already for the .aspx extension double click it. Otherwise right click and select “Add…”
  7. Enter .aspx for the “File name extension”
  8. Check “User-mode caching”
  9. Select “Prevent all caching”
  10. Check “Kernel-mode caching”
  11. Select “Prevent all caching”
  12. Click OK
  13. Close the Server management Console
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.