【问题标题】:Error 500 browsing to webpage which functions correctly on localhost浏览到在 localhost 上正常运行的网页时出现错误 500
【发布时间】:2013-07-22 09:23:22
【问题描述】:

我在调试部署到 IIS 的 MVC ASP.NET 网页时遇到了可怕的麻烦。该网站在制作它的 PC 上的本地主机上完美运行。但是,当我导航到同一网络上另一台 PC 上的页面时,我收到此错误:

使用 Fiddler2 进行进一步检查会得到以下信息,这是我似乎可以从该解决方案中获得的唯一调试信息:

这是 Layout.cshtml:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title - Intranet Page</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/modernizr")
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/Scripts/application.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
        <header>
            <div class="content-wrapper">
                <div class="float-left">
                    <p class="site-title">@Html.ActionLink("IntranetPage", "Index", "Home")</p>
                </div>
                <div class="float-right">
                 <!--   <section id="login">
                    </div>
                    <div id="logindisplay">
                        Context.User.Identity.Name <strong>@Context.User.Identity.Name</strong>!
                    </section>  This works correctly to get DOMAIN/USERNAME-->
                </div>
            </div>
        </header>
        <div id="body">
            @RenderSection("featured", required: false)
            <section class="content-wrapper main-content clear-fix">
                @RenderBody()
            </section>
        </div>
        @Scripts.Render("~/bundles/jquery")
        @RenderSection("scripts", required: false)
    </body>
</html>

还有相关的索引页:

@model IEnumerable<WhoIs.Models.Employee>
@{
    ViewBag.Title = "Contoso Employees";
}
@section featured {
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1>@ViewBag.Title.</h1>
            </hgroup>
        </div>
    </section>
}

      <label for="filter">Enter employee details here : </label>
      <input type="text" name="filter" value="" id="filter" />

<h2><strong>Users</strong> (<a href="/home/create" style="color: blue;">create new</a>)</h2>
<br />

<div style="min-height: 150px; font-size: 1.25em">
    <div style="margin-bottom: .5em">
        <table><thead><tr><th>Name</th><th>Branch</th><th>Phone No.</th><th>Username</th><th>Email</th></tr></thead>
            <tbody>
            @foreach ( var prod in Model )
                {
                    <tr>
                        <td>@prod.FullName</td> 
                        <td>@prod.Branch</td> 
                        <td>@prod.PhoneNo</td> 
                        <td>@prod.DomainAC</td> 
                        <td>@prod.Email</td> 
                        @if (User.IsInRole(@"Admins") || User.Identity.Name == prod.DomainAC) {
                                <td><a href="/home/edit/@prod.Id"  style="color: blue;">edit</a></td>
                         }else{
                         <td>User => @User.ToString()</td>   
                        }
                    </tr>
                 }
                 </tbody>
            </table>
        </div>
     </div>

这些会呈现一个包含 Contoso 员工列表的简单页面,让管理员和用户自己能够编辑他们的详细信息。谁能在这里看到可能导致我的问题的原因?我对此进行了彻底的调查,但没有任何结果。

我的模型文件夹中添加了一个 .edmx 文件,该文件链接到远程数据库员工。我试图编辑 web.config 以通过添加以下行来提供有关可能是什么问题的更多信息:

但我仍然只收到上面的错误消息。

谁能告诉我可能是什么导致了这个问题?注释掉我从数据库中检索的部分可以消除错误,但我无法解决它。

非常感谢。

编辑:

Web.config 提取:

<system.web>
    <compilation debug="true"/>
    <deployment retail="false" />
    <customErrors mode="Off">
    </customErrors>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxx"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxx"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx">
      <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxx" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

【问题讨论】:

  • 您可以禁用部署到 IIS 的应用程序中的 customErrors,以便查看有关 500 错误的更多详细信息。见这里:stackoverflow.com/questions/101693/customerrors-mode-off
  • 另外:从提琴手输出中,您可以看到 /Scripts/Application.js 找不到(404)。可能 ~/Scrips/Application.js 会起作用。
  • 您是否在另一台计算机上启用了匿名身份验证?如果您使用 Windows 身份验证连接到数据库,那么最常见的原因是您在另一台机器上连接的帐户是 asp_net 身份,它不会获得所需级别的 db 访问权限。
  • @ctrucza 我已经尝试了该问题中的所有内容,但不幸的是仍然没有任何合理的错误消息。在我的 web.config 中,我简单地输入了:“”。感谢您的建议!
  • 意外......只是一个想法(来自同一篇文章):在 machine.config 中你有 吗?

标签: c# sql-server asp.net-mvc razor


【解决方案1】:

我遇到了类似的问题,并且遇到了很多陷阱。我会尽量提供他们的完整列表来帮助你检查他们:

  • 允许在 IIS 中浏览目录
  • 在网站物理保存的文件夹中,查看IUSR和IIS_IUSR是否有读取和浏览权限
  • 检查您是否允许访问防火墙中的端口
  • 检查IP地址是否正确。您的外部 IP 可能不会重定向到内部 IP。或者可能(我犯了菜鸟的错误)您正在尝试浏览内部 IP 而不是外部 IP。

我希望这会有所帮助。如果有任何问题,请不要害怕提问。

【讨论】:

  • 感谢您的回复。不幸的是,我已验证所有这些设置都是正确的,但问题仍然存在。
  • 啊,这让我找到了我的解决方案,谢谢。我最终应用了您建议的所有设置,重新启动 IIS。没有。删除了我的 machine.config 文件,保存了一个新版本,停止了 IIS,重新启动了我的 PC,重新启动了 IIS,将新版本的 machine.config 保存到了相关的配置文件夹中(使用以管理员身份运行的 Visual Studio 12),我现在已经检索到一条错误消息。最后。谢谢 ! :)
猜你喜欢
  • 1970-01-01
  • 2017-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-04
  • 2017-02-17
  • 1970-01-01
相关资源
最近更新 更多