IIS7 js.axd returning blank page

Topics: ASP.NET 2.0
Mar 1, 2009 at 9:03 PM
I pulled the source from codeplex's svn connection, setup my local IIS7 on vista to have a site called vs-blogengine and hit it. It works fine.

Then, I upload that same code to mosso.com's hosting and the js.axd returns an empty document response. Here is my system.webServer section...

<

 

system.webServer>
<
validation validateIntegratedModeConfiguration="false" />
<
modules>
<
remove name="Profile" />
<remove name="AnonymousIdentification" />
<
remove name="ScriptModule" />
<
add name="WwwSubDomainModule" preCondition="managedHandler" type="BlogEngine.Core.Web.HttpModules.WwwSubDomainModule, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" />
<
add name="UrlRewrite" preCondition="managedHandler" type="BlogEngine.Core.Web.HttpModules.UrlRewrite, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" />
<
add name="CompressionModule" preCondition="managedHandler" type="BlogEngine.Core.Web.HttpModules.CompressionModule, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" />
<
add name="ReferrerModule" preCondition="managedHandler" type="BlogEngine.Core.Web.HttpModules.ReferrerModule, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" />
<
add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</
modules>
<
handlers accessPolicy="Read, Write, Script, Execute">
<
remove name="WebServiceHandlerFactory-Integrated" />
<
remove name="ScriptHandlerFactory" />
<
remove name="ScriptHandlerFactoryAppServices" />
<
remove name="ScriptResource" />
<
remove name="PageHandlerFactory-Integrated" />

 

<

 

add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

 

<

 

add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

 

<

 

add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

 

<

 

add name="PageHandlerFactory-Integrated" verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />

 

<

 

add name="HtmlFiles" verb="*" path="*.html" type="System.Web.StaticFileHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" resourceType="Unspecified" preCondition="" />

 

<

 

add name="FileHandler" verb="*" path="file.axd" type="BlogEngine.Core.Web.HttpHandlers.FileHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="ImageHandler" verb="*" path="image.axd" type="BlogEngine.Core.Web.HttpHandlers.ImageHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Syndication" verb="*" path="syndication.axd" type="BlogEngine.Core.Web.HttpHandlers.SyndicationHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Sitemap" verb="*" path="sitemap.axd" type="BlogEngine.Core.Web.HttpHandlers.SiteMap, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Trackback" verb="*" path="trackback.axd" type="BlogEngine.Core.Web.HttpHandlers.TrackbackHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Pingback" verb="*" path="pingback.axd" type="BlogEngine.Core.Web.HttpHandlers.PingbackHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="OpenSearch" verb="*" path="opensearch.axd" type="BlogEngine.Core.Web.HttpHandlers.OpenSearchHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="MetaWeblog" verb="*" path="metaweblog.axd" type="BlogEngine.Core.API.MetaWeblog.MetaWeblogHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="RSD" verb="*" path="rsd.axd" type="BlogEngine.Core.Web.HttpHandlers.RsdHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="CssHandler" verb="*" path="css.axd" type="BlogEngine.Core.Web.HttpHandlers.CssHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Javascript" verb="*" path="js.axd" type="BlogEngine.Core.Web.HttpHandlers.JavaScriptHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Rating" verb="*" path="rating.axd" type="BlogEngine.Core.Web.HttpHandlers.RatingHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Opml" verb="*" path="opml.axd" type="BlogEngine.Core.Web.HttpHandlers.OpmlHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="BlogML" verb="*" path="blogml.axd" type="BlogEngine.Core.Web.HttpHandlers.BlogMLExportHandler, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="SIOC" verb="*" path="sioc.axd" type="BlogEngine.Core.Web.HttpHandlers.Sioc, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Apml" verb="*" path="apml.axd" type="BlogEngine.Core.Web.HttpHandlers.Apml, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

<

 

add name="Foaf" verb="*" path="foaf*.axd" type="BlogEngine.Core.Web.HttpHandlers.Foaf, BlogEngine.Core, Version=1.4.5.14, Culture=neutral" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />

 

</

 

handlers>

 

<

 

staticContent>
<
clientCache cacheControlMode="DisableCache" />
</
staticContent>

 

<

 

security>

 

<

 

authentication>

 

<

 

basicAuthentication enabled="false" />

 

</

 

authentication>

 

</

 

security>

 

<

 

defaultDocument>

 

<

 

files>

 

<

 

clear />

 

<

 

add value="default.aspx" />

 

</

 

files>

 

</

 

defaultDocument>

 

<

 

httpRedirect enabled="false">

 

<

 

clear />

 

</

 

httpRedirect>

 

</

 

system.webServer>


Any ideas???

 

Coordinator
Mar 1, 2009 at 9:34 PM
Edited Mar 1, 2009 at 9:35 PM
What is the exact URL or "src" for js.axd?  If I do a View Source, the "src" attribute for my js.axd is:

src="/js.axd?path=%2fblog.js&amp;v=1.4.5.14"

Make sure you have a blog.js file in the root of your blog.

I'm pretty sure the js.axd handler is working, because if it wasn't then you would get a 404 error or some other server error.  If js.axd is working, but it cannot find the blog.js file specified in the "path" querystring parameter, then it returns a blank page.
Mar 1, 2009 at 9:58 PM
I checked that the blog.js is there.

http://blog.animalthink.com/js.axd?path=/blog.js&v=1.4.5.14

I cannot get to it via this url though, which is curious...

http://blog.animalthink.com/blog.js
Coordinator
Mar 1, 2009 at 11:15 PM
These types of problems usually occur when you're doing some type of URL rewriting with a subdomain.  Is the "blog" subdomain pointing to a sub-folder?

This may or may not be your case, but often times when web hosting companies offer sub-domains that point to sub-folders, there can be these types of pathing problems depending on how the URL rewriting technology the hoster uses is implemented.

If possible, the easiest solution is to try and avoid using subdomains and instead use a subfolder ... e.g. www.yourdomain.com/blog instead of blog.yourdomain.com.

If you need to stick with the "blog" subdomain, one option you can do is modify the BlogBasePage.cs file in the BE core and recompile the core.  In it, you'll see this line:

AddJavaScriptInclude(Utils.RelativeWebRoot + "blog.js");

If you change that to:

AddJavaScriptInclude(Utils.AbsoluteWebRoot + "blog.js");

Then the JS.AXD src will look like:

/js.axd?path=http://blog.animalthink.com/blog.js&v=1.4.5.14

And this should work.  You would probably want to make similar modifications to these other 2 links below in BlogBasePage.cs ... changing RelativeWebRoot to AbsoluteWebRoot:

AddJavaScriptInclude(Utils.AbsoluteWebRoot + "admin/widget.js");
AddStylesheetInclude(Utils.AbsoluteWebRoot + "admin/widget.css");
Mar 2, 2009 at 8:14 AM

this

 

.AddJavaScriptInclude(string.Format("{0}blog.js", Utils.AbsoluteWebRoot));

 

 

So I switched it up to this for the 3 lines you mentioned. We'll see if that clears it up. This shouldn't care if I'm on a subdomain though. The subdomain is its own site root, not a folder inside the main domain as you suggested. I would consider this a bug in the code or design of the code that checks for the root application path.

BlogEngine

I'm now getting something out of it, but it still has several undefined errors which I think are related to this junk that is getting stuck before the beginning of the blog.js content. Any ideas where that's coming from?
Coordinator
Mar 2, 2009 at 5:28 PM
Edited Mar 2, 2009 at 5:29 PM
I tested using AbsoluteWebRoot and am also seeing the garbage characters you are getting.  This can be corrected in the JavaScriptHandler.cs file.  In the RetrieveRemoteScript() method, there's this code below.  If you add the bolded line, it should eliminate the garbarge characters and will probably also eliminate the other errors you're seeing (I too was getting about 9 errors while the bad characters were returned by js.axd).

using (WebClient client = new WebClient())
{
    client.Encoding = Encoding.UTF8;
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    script = client.DownloadString(url);
    script = StripWhitespace(script, HardMinify(file));
    HttpContext.Current.Cache.Insert(file, script, null, Cache.NoAbsoluteExpiration, new TimeSpan(3, 0, 0, 0));
}

Regarding the original problem where js.axd returned a blank document, you can test why this might be happening.  When your URL for js.axd was using the RelativeWebRoot, you had:

http://blog.animalthink.com/js.axd?path=/blog.js&v=1.4.5.14

The "path" querystring is "/blog.js" which is a local file.  In that case, the JavaScriptHandler is using the line of code below in RetrieveLocalScript() to map the file:

string path = HttpContext.Current.Server.MapPath(file);

You could try seeing what this is resolving to.  If you add the line below somewhere in your site.master file, you can see if the physical location MapPath is returning is the correct location where the blog.js file exists.

<%= HttpContext.Current.Server.MapPath("/blog.js") %>

If you pull up any page in your blog, you should see the output of the line above somewhere on the page in your browser.
Apr 27, 2009 at 8:07 AM
I'm pretty sure that the cause is this:
  http://peterkellner.net/2008/09/06/iis7-httphandlers-handlers-integrated-mode-webfarm/
Apr 27, 2009 at 8:25 AM
It was actually an encoding issue as BenAmada said. The MIME mapping may fix it, but it is not a proper fix, just a work around. The real problem had to do with the encoding differences in the output.
Coordinator
Apr 27, 2009 at 8:20 PM
As William mentioned, this particular problem is an encoding problem.

The blog.js file is in UTF-8 encoding -- which is the preferred encoding.  When I debug the code in the RetrieveRemoteScript() method, it shows that WebClient is using SBCSCodePageEncoding encoding.  It reports this encoding before it actually downloads blog.js, and also after it has downloaded blog.js.  This is obviously not the correct encoding.  Explicitly setting the encoding to UTF-8 tells the WebClient what the correct encoding of the blog.js file is.