【问题标题】:Server Error in '/' Application 4 [duplicate]“/”应用程序 4 中的服务器错误 [重复]
【发布时间】:2013-07-18 06:10:54
【问题描述】:

响应在此上下文中不可用。 我该如何解决这个问题我需要一些帮助 我试图解决它,但我不能 该网站在我的本地主机上正常工作,但是当我将其上传到主机时它不起作用 有人请帮帮我

{

Response is not available in this context.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Response is not available in this context.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[HttpException (0x80004005): Response is not available in this context.]
   System.Web.HttpContext.get_Response() +8820296
   ASP.global_asax.Application_Start(Object sender, EventArgs e) +54

[HttpException (0x80004005): Response is not available in this context.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +2731054
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +128
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +188
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +295
   System.Web.HttpApplicationFactory.GetPipelineApplicationInstance(IntPtr appContext, HttpContext context) +56
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +231

[HttpException (0x80004005): Response is not available in this context.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8929163
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +85
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +333
}

【问题讨论】:

  • 你高估了我们读心的能力。
  • 附加代码,提供更多关于你的页面的信息,多尝试解释你的问题
  • 可能会有不同的场景,只需考虑部署环境并分享您的代码。如果可能,通过引入 try catch 块来修改代码并写入文件并将其发送到生产环境
  • @MichaelPerrenoud 这里没有证据可以这么说。问题没有提供任何适当的信息。
  • @VeeKayBee,请注意系统在识别重复项时自动生成的文本 - 可能重复。此外,如果它在本地工作,但在部署时不能工作,那么显然存在围绕 Web 服务器配置的问题。我发现 Darin 的答案是配置网站时非常常见的错误。很简单。

标签: c# asp.net


【解决方案1】:

正如错误所说,您无法访问Application_Start 中的Response 对象。 在 Global.asax 中检查(最好发布)Application_Start 方法的代码。

【讨论】:

  • 我的代码太长了,不能在这里发布我该怎么办?
  • @VeeKayBee,你真的要发布那个链接吗?你只是反对它。
  • @MichaelPerrenoud 我并不反对这一点。如果您感到非常抱歉,我的意思是在另一个问题中我们可以看到代码,其他人可以识别正在发生的事情。我只是说如果他可以检查问题并分享代码会更有帮助。如果发生这种情况,我们可以确定两者是相同的。答案也指向了你提到的同样的问题。
  • @VeeKayBee 我读了那个代码,但它没有给我任何帮助我的 global.asax 中有另一个完全不同的代码你能给我任何帮助吗?
【解决方案2】:

它在您的本地机器上工作而不能远程工作的原因可能是因为该网站在本地运行在 IIS经典管道模式下,而远程 - 在 集成管道模式下时间>。

您可以通过切换到经典管道模式来解决问题:here's how

希望这会有所帮助。

【讨论】:

    【解决方案3】:
    <%@ Application Language="C#" %>
    
    <script runat="server">
    
        void Application_Start(object sender, EventArgs e) 
        {
           Application.Add("Visitor",0);
          HttpContext.Current.Response.Redirect("Default.aspx");
            // Code that runs on application startup
            //string MyCounter = ConfigurationManager.AppSettings["Counter"];
            //Application.Add("Count",MyCounter);
           // Counter.UpdateAddOneRecord("VisitorCounter");
        }
    
        void Application_End(object sender, EventArgs e) 
        {
            //  Code that runs on application shutdown
          //  ConfigurationManager.AppSettings["Counter"] = Application["Count"].ToString();
    
    
        }
    
        void Application_Error(object sender, EventArgs e) 
        { 
            // Code that runs when an unhandled error occurs
    
        }
    
        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started
            int visitor = int.Parse(Application.Get("Visitor").ToString());
            visitor++;
            Application.Set("Visitor", visitor);
            Counter.UpdateAddOneRecord("VisitorCounter");
            // Arabic
            //Session.Add("Lng", "ar-IQ");
            //Session.Add("Theme", Neaimy_MSB.Neaimy_Lib.getTheme());
            //Session.Add("MrqDir", "Left");
            //Session.Add("Dir", "rtl");
            //Session.Add("MrqDirInverse", "ltr");
            //Session.Add("AddComment", "flase");
    
            //Session.Add("Lng", "ar-IQ");
            Session.Add("Lng", "en-GB");
            Session.Add("Theme", Neaimy_MSB.Neaimy_Lib.getTheme());
            Session.Add("MrqDir", "Right");
            Session.Add("Dir", "ltr");
            Session.Add("MrqDirInverse", "rtl");
            Session.Add("AddComment", "flase");
    
            //  int count =int.Parse(Application.Get("Count").ToString());
            //int count =int.Parse(Application.Get("Count").ToString());
            //count++;
            //Application.Set("Count",count);
        }
    
        void Session_End(object sender, EventArgs e) 
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.
            int Visitor = int.Parse(Application.Get("Visitor").ToString());
            Visitor--;
            Application.Set("Visitor", Visitor);
    
    
        }
    
    </script>
    

    【讨论】:

    • 这是我的 global.asax
    • 有人帮忙吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    相关资源
    最近更新 更多