10

I'm trying to understand why my default document doesn't come up when I browse the virtual directory. If I browse to the site like I should be able to, I get this:

enter image description here


However, if I add the page to the URL, it comes up:

enter image description here


One SO answer suggested removing all of the default documents (in IIS) except the real one. I tried that (image below) but it didn't help.

enter image description here


Why won't IIS serve that page when using the root URL (http://localhost/SignalRChat)?

This is the relevant part of the web.config after removing the default docs:

<defaultDocument>
    <files>
        <remove value="default.aspx" />
        <remove value="iisstart.htm" />
        <remove value="index.html" />
        <remove value="index.htm" />
        <remove value="Default.asp" />
        <remove value="Default.htm" />
        <add value="ChatPage.cshtml" />
    </files>
</defaultDocument>

This is the handlers section:

<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*."
       verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
       modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
       preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*."
       verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
       modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
       preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*."
       verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler"
       preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
Bob Horn
  • 33,387
  • 34
  • 113
  • 219

6 Answers6

2

Another possible reason of the 404 error when your request doesn't point to a specific file name at the end of URL is that your IIS Request Filtering rules deny extensionless requests.

To know it for sure, figure out the subcode of the 404 error. Usually, it's 404.7, but there may be some variations,

Also, you can try to allow extensionless requests explicitly by adding <add fileExtension="." allowed="true" /> to your web.config as below:

  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions>
          <add fileExtension="." allowed="true" />
        </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>

Please let me kniw if it helped or post your exact 404 error with the subcode.

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
  • Fixed it for me! Thanks a lot. Is request filtering enabled by default on IIS 8? (as I didn't have to do this on windows 7/IIS 7.5) – Sudhanshu Mishra Jan 28 '16 at 04:55
1

From your tags it looks like you use MVC and a view using the razor view engine (cshtml). In MVC an URL does not map to a document directly. So the discussion should not be about default documents, handlers and IIS configuration.

An URL must match a defined route, which invokes an action on a controller. This action will then render the view (*.cshtml).

Try to fix your routes to be able to handle the request. If you need more help, you should update your question with more information about the controller and your routes.

studert
  • 137
  • 4
0

You can made a web Site/Application installer. it has option to set the start up page selection.

So set the ChatPage.cshtml as your start up page in installer and after installing if you type localhost/SignalIRChat

you will see the content of ChatPage.cshtml without showing the "ChatPage.cshtml" name in address bar.

It will resolve your problem.

Rezoan
  • 1,745
  • 22
  • 51
  • Thanks, but I don't want to have to use an installer for this. I'm just using the Publish option from VS. Now, if you knew what the installer did to cause this to be fixed, that would be helpful. – Bob Horn Jun 03 '13 at 13:11
0

You need to add this Handler at the end of your handlers section:

<add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />

Update:

Since .cshtml files are blocked by default, you need:

    <handlers>
        <remove name="cshtml-ISAPI-4.0_64bit" />
        <remove name="cshtml-ISAPI-4.0_32bit" />
        <remove name="cshtml-Integrated-4.0" />
        <remove name="cshtm-ISAPI-4.0_64bit" />
        <remove name="cshtm-ISAPI-4.0_32bit" />
        <remove name="cshtm-Integrated-4.0" />
    </handlers>

    <staticContent>
        <mimeMap fileExtension=".cshtml" mimeType="text/html" />
    </staticContent>

Remove the StaticFile handler suggested (if still there).

haim770
  • 48,394
  • 7
  • 105
  • 133
  • After adding that handler (without the type attribute, because the IDE complained about it), I get an error: `Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'StaticFile'` I don't know why; there isn't another element with the name StaticFile. – Bob Horn Jun 04 '13 at 00:20
  • I revised my answer. please take a look – haim770 Jun 04 '13 at 05:10
  • I tried your suggestion. I still get: `The resource cannot be found.` Thanks for trying. I'm ready to give up and just name it Index or something. – Bob Horn Jun 05 '13 at 00:57
0

This could be an MVC issue.

You may need a redirection from the index to this other action in your SignalRChat controller.
Something like this:

public ViewResult Index()
{
    return View("ChatPage");
}
RacerNerd
  • 1,579
  • 1
  • 13
  • 31
-4

It seems your directory browsing is disabled in IIS. Just enabled the directory browsing in your IIS. it will solve your problem.

visit http://technet.microsoft.com/en-us/library/cc731109%28v=ws.10%29.aspx for more details.

Hope this will help.

  • 1
    I really don't think this should be the answer. First, it didn't work. Second, the link you provided states: `Enable directory browsing when you want client browsers to display a Web page that lists the contents of a directory when a request does not specify a document name and IIS cannot return a default document. A default document cannot be returned when IIS does not find a file in the directory that matches a file name specified in the IIS default document list, or when the Default Document feature is disabled in IIS.` I don't want to display contents and I have specified a default doc. – Bob Horn Jun 02 '13 at 13:56
  • And I have not disabled the default document feature. – Bob Horn Jun 02 '13 at 13:57