IIS 7.0 Integrated Mode Configuration Changes

Topics: ASP.NET 2.0, Business Logic Layer, Themes
Jan 28, 2008 at 2:28 AM
Edited Jan 28, 2008 at 2:43 AM
Okay - so maybe the sky isn't quite falling just yet, but still this was an exercise in complete frustration... HOWEVER, it DOES appear that I have successfully gotten this to run under IIS 7.0 without having to rewrite code for the UrlRewrite capabilities. I will pass along these instructions in the sincere hope that nobody else will ever have to feel as completely idiotic as I have the past day and a half... :-|

It has to do with the web.config and how IIS 7.0 expects to see certain elements for use with Integrated Mode - most notably, how HttpModules and HttpHandlers are registered. You will need to make some changes to the ASP.NET configuration, which can be done either through the IIS user-interface, or can be made directly to the web.config. I will post the changes to the web.config since I believe that to be the quickest way to pass along information... oddly enough, if I had a blog I could direct you to that post... (chicken, egg...). Oh well...

The original web.config has the following elements included:

<system.web>
...
<httpModules>
<add name="WwwSubDomainModule" type="BlogEngine.Core.Web.HttpModules.WwwSubDomainModule, BlogEngine.Core"/>
<add name="UrlRewrite" type="BlogEngine.Core.Web.HttpModules.UrlRewrite, BlogEngine.Core"/>
<add name="CompressionModule" type="BlogEngine.Core.Web.HttpModules.CompressionModule, BlogEngine.Core"/>
<add name="ReferrerModule" type="BlogEngine.Core.Web.HttpModules.ReferrerModule, BlogEngine.Core"/>
<!--The CleanPageModule below removes whitespace which makes the page load faster in IE. Enable at own risk -->
<!--<add name="CleanPageModule" type="BlogEngine.Core.Web.HttpModules.CleanPageModule, BlogEngine.Core"/>-->

<!--Remove the default ASP.NET modules we don't need-->
<remove name="PassportAuthentication" />
<remove name="Profile" />
<remove name="AnonymousIdentification" />
</httpModules>

<httpHandlers>
<add verb="*" path="file.axd" type="BlogEngine.Core.Web.HttpHandlers.FileHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="image.axd" type="BlogEngine.Core.Web.HttpHandlers.ImageHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="syndication.axd" type="BlogEngine.Core.Web.HttpHandlers.SyndicationHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="sitemap.axd" type="BlogEngine.Core.Web.HttpHandlers.SiteMap, BlogEngine.Core" validate="false"/>
<add verb="*" path="trackback.axd" type="BlogEngine.Core.Web.HttpHandlers.TrackbackHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="pingback.axd" type="BlogEngine.Core.Web.HttpHandlers.PingbackHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="opensearch.axd" type="BlogEngine.Core.Web.HttpHandlers.OpenSearchHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="metaweblog.axd" type="BlogEngine.Core.API.MetaWeblog.MetaWeblogHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="rsd.axd" type="BlogEngine.Core.Web.HttpHandlers.RsdHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="css.axd" type="BlogEngine.Core.Web.HttpHandlers.CssHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="js.axd" type="BlogEngine.Core.Web.HttpHandlers.JavaScriptHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="rating.axd" type="BlogEngine.Core.Web.HttpHandlers.RatingHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="opml.axd" type="BlogEngine.Core.Web.HttpHandlers.OpmlHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="monster.axd" type="BlogEngine.Core.Web.HttpHandlers.MonsterHandler, BlogEngine.Core" validate="false"/>
<add verb="*" path="blogml.axd" type="BlogEngine.Core.Web.HttpHandlers.BlogMLExportHandler, BlogEngine.Core" validate="false"/>
</httpHandlers>

...
</system.web>

So when you try to run the application in IIS 7.0 under Integrated Mode you may get a couple of different behaviors - I created this application a couple of times and got different results both times. 1) You might seemingly be running the application, but nothing appears to work correctly - for example, you might not get the CSS Themes applied correctly, which was my very first indication that something was wrong. Also, I could not navigate to any page or post because the Url's are generated dynamically and as a result only "static" pages that exist on the file system. 2) You might get a 500 Internal Server Error, which tells you that the HttpModules element needs to be migrated - as well, you will receive a similar error instructing you to migrate the HttpHandlers element.

Okay, so you need to adjust the web.config in the following fashion:

<system.webServer>
<modules>
<add name="UrlRewrite" type="BlogEngine.Core.Web.HttpModules.UrlRewrite" preCondition="managedHandler" />
<add name="ReferrerModule" type="BlogEngine.Core.Web.HttpModules.ReferrerModule" preCondition="managedHandler" />
<add name="CompressionModule" type="BlogEngine.Core.Web.HttpModules.CompressionModule" preCondition="managedHandler" />
<add name="WwwSubDomainModule" type="BlogEngine.Core.Web.HttpModules.WwwSubDomainModule" preCondition="managedHandler" />
<!--The CleanPageModule below removes whitespace which makes the page load faster in IE. Enable at own risk -->
<!--<add name="CleanPageModule" type="BlogEngine.Core.Web.HttpModules.CleanPageModule, BlogEngine.Core"/>-->

<!--Remove the default ASP.NET modules we don't need-->
<remove name="Profile" />
<remove name="AnonymousIdentification" />
</modules>

<handlers>
<add name="FileHandler" verb="*" path="file.axd" type="BlogEngine.Core.Web.HttpHandlers.FileHandler, BlogEngine.Core" />
<add name="ImageHandler" verb="*" path="image.axd" type="BlogEngine.Core.Web.HttpHandlers.ImageHandler, BlogEngine.Core"/>
<add name="SyndicationHandler" verb="*" path="syndication.axd" type="BlogEngine.Core.Web.HttpHandlers.SyndicationHandler, BlogEngine.Core"/>
<add name="SiteMap" verb="*" path="sitemap.axd" type="BlogEngine.Core.Web.HttpHandlers.SiteMap, BlogEngine.Core" />
<add name="TrackbackHandler" verb="*" path="trackback.axd" type="BlogEngine.Core.Web.HttpHandlers.TrackbackHandler, BlogEngine.Core" />
<add name="PingbackHandler" verb="*" path="pingback.axd" type="BlogEngine.Core.Web.HttpHandlers.PingbackHandler, BlogEngine.Core" />
<add name="OpenSearchHandler" verb="*" path="opensearch.axd" type="BlogEngine.Core.Web.HttpHandlers.OpenSearchHandler, BlogEngine.Core" />
<add name="MetaWeblogHandler" verb="*" path="metaweblog.axd" type="BlogEngine.Core.API.MetaWeblog.MetaWeblogHandler, BlogEngine.Core" />
<add name="RsdHandler" verb="*" path="rsd.axd" type="BlogEngine.Core.Web.HttpHandlers.RsdHandler, BlogEngine.Core" />
<add name="CssHandler" verb="*" path="css.axd" type="BlogEngine.Core.Web.HttpHandlers.CssHandler, BlogEngine.Core" />
<add name="JavaScriptHandler" verb="*" path="js.axd" type="BlogEngine.Core.Web.HttpHandlers.JavaScriptHandler, BlogEngine.Core" />
<add name="RatingHandler" verb="*" path="rating.axd" type="BlogEngine.Core.Web.HttpHandlers.RatingHandler, BlogEngine.Core" />
<add name="OpmlHandler" verb="*" path="opml.axd" type="BlogEngine.Core.Web.HttpHandlers.OpmlHandler, BlogEngine.Core" />
<add name="MonsterHandler" verb="*" path="monster.axd" type="BlogEngine.Core.Web.HttpHandlers.MonsterHandler, BlogEngine.Core" />
<add name="BlogMLExportHandler" verb="*" path="blogml.axd" type="BlogEngine.Core.Web.HttpHandlers.BlogMLExportHandler, BlogEngine.Core" />
</handlers>
</system.webServer>

Noticeable differences: In the modules section, you can eliminate the remove element for PassportAuthentication since it doesn't appear to be listed inside of IIS 7.0. The rest of the HttpModules section beginning with the first "<add>" and ending at the last "<remove>" element can be copied in total and pasted inside the new "<modules>" element. Also, there is the "preCondition" attribute which states these should be invoked when executing ASP.NET applications. I have not tested this without this attribute, so I do not know the impact of this particular value. It does appear to work so I am apt to leave it as it is.

For the handlers, there are a couple of more edits to be made: Apparently, the "validate" attribute is no longer a valid attribute for the "<add>" element for HttpHandlers. Also, it is required to provide a "name" attribute for this element.

Once I made these configuration changes, the application began working.

Hopefully, this will keep others from experiencing the same difficulties that I experienced.
Jan 28, 2008 at 11:17 AM
The fastest and painless way I found to make it all work on IIS7 is to create the AppPool in Classic mode to get it all up and running. Once I had the site up I simply migrated the site configuration using the following command:

%systemroot%\system32\inetsrv\APPCMD.EXE migrate config "BlogSiteName/"
Once this was done, I then changed the AppPool to Integrated.
Jan 28, 2008 at 2:48 PM
Smartypants! ;)
Jan 28, 2008 at 4:24 PM
Just trying to help ease the pain... ;-)
Jan 29, 2008 at 3:13 AM
LOL
Apr 14, 2008 at 10:50 PM
This totally had me stuck in debugging hell for hours!

These clues should have told me the I deployed BlogEngine.NET to a server running IIS7:
  • The site worked, but CSS was not applied. I initially thought that turning off Trim Stylesheets solved the problem, but later discovered that it was not the root cause of the error.
  • I got 404 error pages for files that I knew existed, especially .AXD files. It appeared that there is a bug with the httpHandler or that the hosting company had set up IIS with "Verify that file exists" set to true (which would give 404 errors because it would override the ASP.NET httpHandler). My host's support staff told me that the problem was not the "Verify that file exists" setting. (This is because the Verify setting was in IIS6 and not in IIS7.)

If you're new to IIS7, consider reading these pages:

Apr 15, 2008 at 3:50 AM
Not sure why it was so difficult since the error page in IIS7 should show you the command which "lvildosola" mentioned above with user friendly explanation

See the IIS7 error page which comes up 1st time you browse to BE
http://www.awesomeideas.net/photos/iis7-errorpage.png
Apr 24, 2008 at 6:08 PM
For me, it was more difficult because I never got a nice error screen like that. I was getting a 404 error that pages were not being found. I am using a shared hosting plan for my site... meaning that I have a lot less control over the server. I thought that the host was running IIS6 - since I was getting 404 errors, it looked like they were using the IIS6 setting "Verify that file exists." It took 4 rounds with tech support before someone finally told me that my site was on an IIS7 machine.
Sep 19, 2008 at 11:13 PM
Fantastic. Merging the changes into my satarter solved the problem for me.
It's essentially about IIS7 needing a different declaration style for the custom pages .axd that dnbe uses.
Sep 19, 2009 at 12:30 AM

So, I've got a new one for folks and I suspect it isn't just IIS 7 but I have no idea. I keep getting the following error message when I try posting:

A potentially dangerous Request.Form value was detected from the client (ctl00$cphAdmin$txtContent$TinyMCE1$txtContent="<p>Test Post</p>").

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. To allow pages to override application request validation settings, set requestValidationMode="2.0" in the configuration section. After setting this value, you can then disable request validation by setting validateRequest="false" in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. For more information, see http://go.microsoft.com/fwlink/?LinkId=153133.

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ctl00$cphAdmin$txtContent$TinyMCE1$txtContent="<p>Test Post</p>").

Source Error:

Line 60: 		{
Line 61: 			HttpContext context = ((HttpApplication)sender).Context;
Line 62:             if (context.CurrentHandler is System.Web.UI.Page && context.Request["HTTP_X_MICROSOFTAJAX"] == null && context.Request.HttpMethod == "GET")
Line 63: 			{
Line 64: 				CompressResponse(context);


Source File: C:\TFS\BlogEngineAgile\Dev\BlogEngine.Core\Web\HttpModules\CompressionModule.cs    Line: 62

Stack Trace:

[HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (ctl00$cphAdmin$txtContent$TinyMCE1$txtContent="<p>Test Post</p>").]
   System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection) +11097924
   System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection) +179
   System.Web.HttpRequest.get_Form() +186
   System.Web.HttpRequest.get_Item(String key) +56
   BlogEngine.Core.Web.HttpModules.CompressionModule.context_PostReleaseRequestState(Object sender, EventArgs e) in C:\TFS\BlogEngineAgile\Dev\BlogEngine.Core\Web\HttpModules\CompressionModule.cs:62
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +266

<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

Anyone have any idea? There is no requestvalidationMode tag and I can't find anything out about it on the web. Any help would be greatly appreciated.

</font>

 

 

 

Sep 19, 2009 at 12:45 AM

Sigh. Not to worry. It's a .NET 4.0 thing. I set the compatability back to 2.0/3.5 and it worked fine.

Oct 2, 2009 at 10:42 AM

Hi Jeff!

The referred property is a property of the httpRuntime element within the system.web section in web.config. You can add this and it will work fine without setting the compatibility back: 

<font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">

<

</font></font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">

 

</font></font><font face="Consolas" size="2" color="#0000ff">

 

</font>

httpRuntime requestValidationMode="2.0" />

Regarding the web.config schema you can find the commented version in the file at: %windir%\Microsoft.NET\Framework\v4.0.xxxxx\Config\web.config.comments where xxxxx is the build number of the .Net Framework you've installed. The folder can be Framework64 if you've 64 bit OS installed. On the other hand the NetFx40_IIS_schema_update.xml file in the same directory contains the IIS confgurable .Net 4.0 specific properties.

 

Hope this helps,

Attila

May 15, 2010 at 7:02 PM

the above fix worked for me.  don't be concerned if you open the web.config in VS 2008 and it thinks that requestValidationMode isn't a valid attribute...  go ahead with the save and deploy...  also - find the existing httpRuntime element to add the attribute...  so cool :)

May 18, 2010 at 12:32 AM

Hello,

I tried these but I still get an error. I have Microsoft Windows Server 2008, Enterprise x64 Edition
Version 6.0 (Build 6002 : Service Pack 2) (x64) Server Full Installation

BlogEngine Web 1.6.1

the error

��`I�%&/m�{J�J��t��`$ؐ@�������iG#)�*��eVe]f@�흼��{����{����;�N'���?\fdl��J�ɞ!���?~|?"��Ey�')=��y6�����h�����?����2�O.�g]�I�>��Z !x��ۻG���Ɲ��Ȋ�J����jUS�x�x^�WŬ��������v�Ϛ�����%X�^�{G����E�8�(��F�� Ș�g������"+G��sª%�G���2�������ٲ�~�_�ˬ��j��8O#��O�fZ+a��w'G��t��t�$��i�ߥՔf �2[���"��ѷ�t-ߞ�܄м�'i���uN#K_�y����e�_q��%fMۚC�Q�����X�C�\6�֭t�SFؤW��ڴ� b̬%\h*��j����� ���}j��4o��ld误in�������ve[=J?pr�Qy]�k�s�#�0�wˢ汨��?�g:��o�Ku�C��7V��@N�~���&� ��yޛμ������efy��J��@r�O�e:!F���� ֍C���Yl���I�Wd�wc�O�䣏0 ���O/��h��jv�=b�0z����`gggg������3 �L}u6��-���<���ɢn�Y�����y������yz�~��~���s���݃.��j�*JQ�O�E9����E^�?�۟Ļ�᫼Y��ْp\f�P7��IEv��kY�k$�9���!{�����-_�d��Lt?��!�~�h�/�ㆴv���!�����?�!�~��/x�_���:'������ .�uU��)�O7ᾰ�����i1���Z^X�tY��%�{p?��u����bE ?}8���ڍ���e��k�,��ٲh���pۺ��M�J��Y��2�.��r=�I'\�͓�@����r��*�������9a�Zͽ�47��B�t��^RD ��:���gu� ��fu�E1%ά��t���M����UU�M��G{�����{��{;;������2���;<�N�w� ��$����ﺽ�vU��?T�qoY� (����'?4���x��������C��q����z*oCۮ����gW��\~e�P_@��/�zE��q���}��k;�i�d���m~���-����p(q˞�z}���oC�����?kV��������� �Lh}jb��m�ox�,l)ť�����{[!�Kr��~a �S�F�&�O.�uS^S��G

May 18, 2010 at 11:36 PM
Edited May 18, 2010 at 11:55 PM

Hello.. Made changes to the Web.config, still having the problem with the CSS. Website is not loading any kind of CSS. Any kind of help will be appreciated.

May 20, 2010 at 3:44 AM

pcand01.... turn off this setting in your BlogEngine.net settings:

Settings : Advanced : HTTP Compression: Makes the pages load faster (recommended). Changing this will re-start the website.

Then it will throw the error in a readable form.  Doesn't solve the error but it will unencrypt it for you.

Jared Nielsen

blog.NielsenData.com

 

Aug 11, 2010 at 1:23 PM

attilah,

Thank you.  This is an elegant solution to a problem that has been hounding me.

Dogulas

 

Aug 11, 2010 at 2:35 PM
Edited Aug 11, 2010 at 2:35 PM

You're welcome Dogulas :-)

Jan 20, 2011 at 3:23 AM
attilah wrote:

Hi Jeff!

The referred property is a property of the httpRuntime element within the system.web section in web.config. You can add this and it will work fine without setting the compatibility back: 

<font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">

<

</font></font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">

 

</font></font><font face="Consolas" size="2" color="#0000ff">

 

</font>

httpRuntime requestValidationMode="2.0" />

 

Regarding the web.config schema you can find the commented version in the file at: %windir%\Microsoft.NET\Framework\v4.0.xxxxx\Config\web.config.comments where xxxxx is the build number of the .Net Framework you've installed. The folder can be Framework64 if you've 64 bit OS installed. On the other hand the NetFx40_IIS_schema_update.xml file in the same directory contains the IIS confgurable .Net 4.0 specific properties.

 

Hope this helps,

Attila

Thanks, I had the same problem as jefflevinson, and this fixed it