3
0
I have deployed an ASP.NET 4 web site to IIS 7 on Windows Server 2008. When I browse to the root folder, or any other folder in the site, the server responds by delivering the default page Default.aspx
as you would expect. However, when I request a specific page with an .aspx
extension, I get a 404 error.
For example, when I request:
http://localhost/MyWeb/
the server successfully delivers http://localhost/MyWeb/Default.aspx
. However, if I explicitly request:
http://localhost/MyWeb/Default.aspx
then IIS responds with a 404 error.
The error details are as follows:
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error code: 0x80070002
The .NET framework is obviously installed and working, since I can get to default pages. By the way, I have observed that when the server fails and shows a 404 error page, the URL that I entered (such as http://localhost/MyWeb/Default.aspx
) drops the extension (and reads http://localhost/MyWeb/Default
).
I have tried running aspnet_iisreg -i
and restarting the server, but things haven't changed.
What am I missing? Thank you.
UPDATE. I am posting here the web.config
of my site. There are no other config files that apply to it.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="DatabaseServer" value="CONWAY\SQLEXPRESS"/>
<add key="DatabaseName" value="KaleidoScape"/>
<add key="User" value="KaleidoScapeUser"/>
<add key="Password" value="Scape1!"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
<pages>
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
<add tagPrefix="uc" tagName="FileGallery" src="~/Controls/FileGallery/FileGallery.ascx" />
</controls>
</pages>
<authentication mode="Forms">
<forms defaultUrl="~/App" loginUrl="~/Default.aspx" slidingExpiration="true" timeout="120" name="Incipit.KaleidoScape" />
</authentication>
<authorization>
<allow users="*" />
</authorization>
</system.web>
<location path="App">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
UPDATE. The IIS log entries for a failed request are as follows:
2016-10-23 21:13:22 127.0.0.1 GET /MyWeb/MyPage.aspx - 80 - 127.0.0.1 Mozilla/5.0+(compatible;+MSIE+9.0;+Windows+NT+6.0;+WOW64;+Trident/5.0) 301 0 0 46
2016-10-23 21:13:22 127.0.0.1 GET /MyWeb/MyPage - 80 - 127.0.0.1 Mozilla/5.0+(compatible;+MSIE+9.0;+Windows+NT+6.0;+WOW64;+Trident/5.0) 404 0 2 0
Note that there are two entries. The first one corresponds to MyPage.aspx
, which is the page I requested by typing on the URL field. This results in a 301 (moved permanently) error. Immediately after, there is an entry for the same page without the .aspx
extension, which results in a 404 error with substatus 0. I don't understand why the full URL gets a 301, and why the server then tries to deliver (and fails) a page without the extension.
UPDATE. I've just run an interesting experiment. I created a new web application on my server, having a single Test.aspx
file. It worked as expected, i.e. the server delivers the page when you request it explicitly. Then I copied all the contents from the web site that is giving me headaches, and Test.aspx
stopped working! Then, I deleted everything from this web except for the Test.aspx
file, and it didn't revert back to working, but stayed failing. In conclusion, there's something in the web content that screws things up, and which persists after you delete the content. This is a web site I created with Visual Studio 2015 by using a project template that comes with Bootstrap and a few other things. I am utterly confused.
I guess you also noticed "Handler: StaticFile" which would be wrong. In case it helps people debug: what if you add a plain HTML file named
Default
(without extension) to the file system? – Arjan – 2016-10-23T11:15:33.857@Arjan: Yes, I know StaticFile is wrong. Somehow the server is not handling ASPX files properly. But I don't know why. – CesarGon – 2016-10-23T11:25:33.677
So, is a file called
Default
served if it exists, when explicitly requestinghttp://localhost/MyWeb/Default.aspx
? "Somehow the server is not handling ASPX files properly" -- or it is redirecting to the non-.aspx-extension version before even trying. – Arjan – 2016-10-23T11:27:11.493No. The server still gives the 404 error. – CesarGon – 2016-10-23T11:31:29.790
Have you configured ASP.NET for localhost or only for MyWeb? – harrymc – 2016-10-23T16:25:34.860
@harrymc: ASP.NET has been installed on the server for ages. Other web sites on that machine are running fine. It's only this particular web site which fails. – CesarGon – 2016-10-23T16:26:32.050
Does this website has its own web.config? Can you post the config files that may apply to the website? – harrymc – 2016-10-23T16:33:48.280
There is only one web.config affecting the site. I have added it now to the OP. Don't worry about the credentials there; they are fake ;-) – CesarGon – 2016-10-23T16:41:57.657
Does the
Default.aspx
file contain any executable code? (Or is it just plain HTML? In that case: add some code and check it's parsed.) And do other websites have a<compiler>
defined for the.aspx
extension? – Arjan – 2016-10-23T17:22:33.537Default.aspx has code, and it gets parsed and executed when served as a default file (i.e. when requesting a folder). However, it is not parsed or executed when a 404 error is shown. – CesarGon – 2016-10-23T17:25:30.927
Add the
– harrymc – 2016-10-23T20:46:31.830sc-substatus
field to the IIS log to distinguish between about 20 different 404 variations. Check for what is different for this one website on the server, such as extra configuration, handlers, application pools, folder permissions etc.@harrymc: I am posting the log entries for a 404 error. – CesarGon – 2016-10-23T21:15:15.073
Hmmm, with the new logs I don't understand why a file
Default
without any extension is not served whenDefault.aspx
is requested, as the301
suggests an explicit redirect and the next line shows the browser is indeed trying to fetch that. Anyway: so, the redirect to the URL without the.aspx
suffix is the culprit, which is not configured in theweb.config
but somewhere in the ISS setting screens, I guess? – Arjan – 2016-10-23T21:25:17.920HTTP redirection is disabled as far as I can see. – CesarGon – 2016-10-23T21:33:10.827
Is
default.aspx
added to the list of default files? – Burgi – 2016-10-23T21:38:55.390Yes, of course. At the top. – CesarGon – 2016-10-23T21:48:31.247
I have now added a third update about an experiment I just run. Very odd. I'm off to bed till tomorrow. Thanks all who helped. – CesarGon – 2016-10-23T22:42:09.410
Are you using any extensions or ISAPI modules besides ASP.NET? Remark: If no alternative URL is returned with the 301 response, then normally some URL redirection is set up incorrectly. Does the ASP.NET code of this website somehow create a .config file or add redirection/rewrite rules (check in IIS Manager)? – harrymc – 2016-10-24T08:16:26.323
I am not using any third-party ISAPI modules or extensions as far as I know. The ASP.NET code in the web site is pretty standard: it uses Bootstrap and a few javascript dependencies, but that's all. I have other similar web sites that work fine. – CesarGon – 2016-10-24T10:33:48.760
The problem apparently arrives after running the website one time and then stays. If you cannot find anything special about this website after this run, for example in IIS Manager or some config file, it's unlikely that we will find it from here. The only advice to locate the problem that I can give is to restart from zero and add files until you find the one that causes it, then selectively edit the file (starting a new website every time, ouch). – harrymc – 2016-10-24T12:09:14.047
@harrymc: I agree with your advice. I will do that, and I will report when/if I find anything. Thank you for your time. – CesarGon – 2016-10-24T16:19:34.153