“在这种情况下,响应不可用”-运行Application_Start

问题描述

当我在本地运行它时,它工作正常。但是,在测试服务器上运行它时,在index.aspx上出现500错误,提示“在此情况下响应不可用”。

在堆栈跟踪中,我可以看到这与Application_start中的代码某种程度上有关。 Global.asax中的第16行引用了application_start中的Call CheckAppPaths()。尝试注释掉该行,并且在下一行代码中有相同的错误。

堆栈跟踪:

[HttpException (0x80004005): Response is not available in this context.]
   System.Web.HttpContext.get_Response() +9931738
   KeyAccidentsWeb.Global_asax.Application_Start(Object sender,EventArgs e) in C:\Users\josephd\source\repos\KeyAccidentsWeb\Global.asax.vb:16

[HttpException (0x80004005): Response is not available in this context.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context,HttpApplication app) +10103063
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext context,MethodInfo[] handlers) +123
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state,MethodInfo[] handlers,IntPtr appContext,HttpContext context) +181
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext context) +228
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +314

[HttpException (0x80004005): Response is not available in this context.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10083304
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context) +263

Global.asax中的相关代码:

Sub Application_Start(ByVal sender As Object,ByVal e As EventArgs)

        Try
            Call CheckAppPaths()
            Call GetSettingsDIF()
            Call CheckTable()

            If Dif Is Nothing Then
                Context.Response.Write("DIF not configured")
            End If
        Catch ex As Exception
            Context.Response.Write(ex.Message & "</br>")
        End Try
        Try
            Call ClearUp()
        Catch ex As Exception
        End Try
End Sub

Private Sub CheckAppPaths()
        Dim x As New WebFunctions.WebAppPaths()
        If Not IO.Directory.Exists(x.HiddenAppPath) Then
            IO.Directory.CreateDirectory(x.HiddenAppPath)
        End If
        Dim xmlFile As String = IO.Path.Combine(x.HiddenAppPath,"settings.xml")
        If Not IO.File.Exists(xmlFile) Then
            IO.File.Copy(IO.Path.Combine(x.ActualAppPath,"settings.xml"),IO.Path.Combine(x.HiddenAppPath,"settings.xml"))
        End If
    End Sub

Private Sub CheckAppPaths()
        Dim x As New WebFunctions.WebAppPaths()
        If Not IO.Directory.Exists(x.HiddenAppPath) Then
            IO.Directory.CreateDirectory(x.HiddenAppPath)
        End If
        Dim xmlFile As String = IO.Path.Combine(x.HiddenAppPath,"settings.xml"))
        End If
    End Sub

Index.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title runat="server" id="pageTitle"></title>
    <script type="text/javascript" src="scripts/jquery-1.12.3.min.js"></script>
    <script type="text/javascript" src="scripts/Bootstrap/js/bootstrap.js"></script>
    <script type="text/javascript" src="scripts/bootstrap-switch-master/dist/js/bootstrap-switch.js"></script>
    <script type="text/javascript" src="scripts/jquery-ui-1.10.4.custom.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.fileupload.js"></script>
    <script type="text/javascript" src="scripts/jquery.iframe-transport.js"></script>
    <script type="text/javascript" src="default.js"></script>

    <link href="scripts/Bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="scripts/bootstrap-switch-master/dist/css/bootstrap3/bootstrap-switch.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
    <link href="Styles.css" rel="Stylesheet" />
</head>
<body>
<form id="form1" runat="server" onsubmit="return false;">
    <div>
        <nav id="navbar-example" class="navbar navbar-inverse navbar-static">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" id="title" href="#">Key Accidents Web</a>
                </div>
                <div id="nbTB" class="collapse navbar-collapse bs-example-js-navbar-collapse">
                    
                    <button id="btnBack" title="Back" type="button" class="btn btn-primary navbar-btn"><i class="fa fa-arrow-left fa-lg"><span class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span></i></button>
                    <button id="btnHome" title="home" type="button" class="btn btn-primary navbar-btn navbar-right"><i class="fa fa-home fa-lg"><span class="glyphicon glyphicon-home" aria-hidden="true"></span></i></button>
                </div>
            </div>
        </nav>

        <div class="container">
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title"></h4>
                        </div>
                        <div class="modal-body">
                            <p id="modal-p"></p>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div><!-- /.modal -->
            <div class="col-md-7 page-body">
                <div class="col-md-3">
                    <span class="btn btn-primary fileinput-button" id="fileuploadbutton">
                        <span>Select File(s)</span>
                        <input id="fileupload" type="file" multiple="multiple" name="files[]" data-url="fileupload.ashx" style="height:34px;"/>
                    </span>
                    <button class="btn btn-primary fileinput-button" id="removebutton">Remove</button>
                </div>

                <div class="col-md-9">
                    <div>
                        <ul id="fileslist" class="list list-unstyled"></ul>
                        <div class="col-md-9">
                            <p id="uploadcomplete"></p>
                        </div>
                        <div class="col-md-3">
                            <button class="btn btn-primary fileinput-button" id="sendbutton">Submit</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-md-5 page-body">
                <div>
                    <h4>Accident Count: <span id="AccidentCount"></span></h4>
                    <h4>Casualty Count: <span id="CasualtyCount"></span></h4>
                    <h4>Vehicle Count: <span id="VehicleCount"></span></h4>
                    <h4>Start Date: <span id="StartDate"></span></h4>
                    <h4>End Date: <span id="EndDate"></span></h4>
                    <br />
                    <div class="checkbox-box">
                        
                        <input class="checkbox switch-mini" type="checkbox" id="my-checkbox"/>
                        <h5 class="checkbox">Overwrite (if file has previously been loaded)</h5>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
</body>
</html>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...