【问题标题】:IIS Express does not assume localhost/index.html when accessing localhost/IIS Express 在访问 localhost/ 时不假定 localhost/index.html
【发布时间】:2013-12-17 17:28:50
【问题描述】:

如何让 localhost/ 指向 localhost/index.html?

直接访问 index.html 可以正常工作,但是访问站点根目录时,出现以下错误:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.33440

我查看了 IIS Express 配置文件 (%userprofile%\documents\iisexpress\config\applicationhost.config),但看不出有什么问题。

这是我项目的虚拟目录信息:

<site name="MySite" id="12">
            <application path="/" applicationPool="Clr4IntegratedAppPool">
                <virtualDirectory path="/" physicalPath="C:\Users\username\path\to\project\projectname" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:90210:localhost" />
            </bindings>
        </site>

&lt;system.webServer&gt;部分,它包括:

<defaultDocument enabled="true">
        <files>
            <add value="Default.htm" />
            <add value="Default.asp" />
            <add value="index.htm" />
            <add value="index.html" />
            <add value="iisstart.htm" />
            <add value="default.aspx" />
        </files>
    </defaultDocument>

【问题讨论】:

    标签: visual-studio iis visual-studio-2013 iis-express


    【解决方案1】:

    我添加了 routes.IgnoreRoute("");在 RouteConfig.cs 中允许 localhost/ 服务于 localhost/index.html。有人知道为什么会这样吗?

    【讨论】:

    • 它可以工作是有道理的——你告诉 MVC 不要尝试将该路径映射到特定的控制器,而是让它回退到标准的 ASP.NET 路径映射——这表示它将尝试加载 IIS 指定的默认文件。
    【解决方案2】:

    检查 globalModules 列表中是否有 defdoc 模块。

    <globalModules> 
    <add name="DefaultDocumentModule" image="...\defdoc.dll" />
    ......
    </globalModules>
    

    【讨论】:

    • defdoc.dll 在那里并且没有被注释掉。看起来像&lt;add name="DefaultDocumentModule" image="%IIS_BIN%\defdoc.dll" /&gt;
    猜你喜欢
    • 1970-01-01
    • 2017-11-05
    • 1970-01-01
    • 2013-11-20
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    相关资源
    最近更新 更多