"Response is not available in this context" - 500 error when running Application_Start

0

This works fine when I run it locally. However, when running it on the test server I get a 500 error on index.aspx saying "Response is not available in this context".

In the stack trace I can see that that this is somehow related to the code inside Application_start. Line 16 in Global.asax refers to Call CheckAppPaths() in application_start. Tried commenting out that line and had the same error but on the next line of code.

Stack trace:

[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

Relevant code in 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")
        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

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>
asp.net
vb.net
.net-4.7.2
asked on Stack Overflow Sep 1, 2020 by NickyLarson

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0