ASP.NET 在新选项卡中打开 PDF 时出现一般运行时错误 - 停止工作

ASP.NET Generic Runtime Error when opening a PDF in new tab - Stopped working

我正在使用 Windows Server 2012 运行 IIS8 托管我的网站。代码写在VB.NET。

直到昨天,单击 link 按钮后,我的页面会在新选项卡中打开 PDF 以供查看(而非下载)。 link 按钮仅在关联文件存在于数据库中时才有效。

        If (myreader(49) = "" And myreader(52).ToString() = "0") Then
            lnkAttachment.Text = "N/A"
            lnkAttachment.Enabled = False
        Else
            lnkAttachment.Text = "Click Here"
            lnkAttachment.Enabled = True

单击该按钮后,它将在新选项卡中打开 PDF。它停止工作,现在显示一般运行时错误。

生成此页面 link 的代码是:

Protected Sub lnkAttachment_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAttachment.Click
    Dim wdwOpen As String = "window.open('" & "../Attachment/" & Session("ID") & ".pdf" & "','_blank');"
    Response.Write("<script>")
    Response.Write(wdwOpen)
    Response.Write("</script>")
End Sub

我有 web.config 文件和 IIS 错误页面设置应该显示详细的错误信息:

<system.web>
    <customErrors mode="Off"/>
</system.web>

我在此 IIS 站点下设置了多个应用程序。有问题的 (WO) 是唯一一个我无法在其中打开 PDF 的应用程序。我在该站点下有另一个应用程序,显示 PDF 文件没有问题。我想说这是一个 IIS 问题,但我无法确定错误是什么。

我进入了 C:\inetpub\logs\LogFiles\W3SVC1 文件并找到了这一行:

2016-07-20 13:29:22 (server ip address) GET /WO/Attachment/40147.pdf - 443 - 192.168.0.2 Mozilla/5.0+(iPhone;+CPU+iPhone+OS+9_3_2+like+Mac+OS+X)+AppleWebKit/601.1.46+(KHTML,+like+Gecko)+Version/9.0+Mobile/13F69+Safari/601.1 - 500 0 0 31

它显示了 500 错误,但我无法解决这个问题。我通过网络搜索找到了大量信息,但找不到针对特定问题的信息。代码如何一天工作然后在下一天停止,并且仅适用于 IIS 中站点下的一个应用程序。

关于可能出现的问题有什么想法吗?

编辑: 根据 illinoistim 评论摘自事件查看器:

Event code: 3008 
Event message: A configuration error has occurred. 
Event time: 7/21/2016 6:55:26 AM 
Event time (UTC): 7/21/2016 11:55:26 AM 
Event ID: 949451611c784e7695ead3f75ea8d6b5 
Event sequence: 125 
Event occurrence: 3 
Event detail code: 0 

Application information: 
  Application domain: /LM/W3SVC/1/ROOT/WO-15-131135755702094878 
  Trust level: Full 
  Application Virtual Path: /WO 
  Application Path: C:\inetpub\wwwroot\OHAS\WODB\ 
  Machine name: (Machine Name) 

Process information: 
  Process ID: 22580 
  Process name: w3wp.exe 
  Account name: NT AUTHORITY\NETWORK SERVICE 

Exception information: 
  Exception type: ConfigurationErrorsException 
  Exception message: It is an error to use a section registered as    allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS. (C:\inetpub\wwwroot\OHAS\WODB\attachment\web.config line 86)
  at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
  at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
  at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
  at System.Web.Configuration.RuntimeConfig.GetSectionObject(String sectionName)
  at System.Web.Configuration.RuntimeConfig.GetSection(String sectionName, Type type, ResultsIndex index)
  at System.Web.Configuration.RuntimeConfig.get_Identity()
  at System.Web.HttpContext.SetImpersonationEnabled()
  at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)



Request information: 
  Request URL: (site URL)
  Request path: /WO/attachment/40147.pdf 
  User host address: 192.168.20.1 
  User:  
  Is authenticated: False 
  Authentication Type:  
  Thread account name: NT AUTHORITY\NETWORK SERVICE 

Thread information: 
  Thread ID: 57 
  Thread account name: NT AUTHORITY\NETWORK SERVICE 
  Is impersonating: False 
  Stack trace:    at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
  at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
  at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
  at System.Web.Configuration.RuntimeConfig.GetSectionObject(String sectionName)
  at System.Web.Configuration.RuntimeConfig.GetSection(String sectionName, Type type, ResultsIndex index)
  at System.Web.Configuration.RuntimeConfig.get_Identity()
  at System.Web.HttpContext.SetImpersonationEnabled()
  at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)


Custom event details: 

事情就是这样。感谢 illinoistim 关于转到事件查看器的评论,我能够使用内容进行搜索。

显然我不小心将 web.config 文件从根文件夹复制到附件子文件夹中。我打算更改我的 web.config 文件,所以我将它复制到我桌面上的一个临时文件夹中,以防出现意外。我怀疑因为我有一个可编程鼠标,并且文件仍然存储在剪贴板中,所以我一定选择了附件文件夹并点击鼠标上的 "paste" 按钮。两个 .config 文件都有标签。此标签仅允许在应用程序级别使用。