';中的服务器错误/';应用程序4

本文关键字:应用程序 服务器 错误 | 更新日期: 2023-09-27 18:23:40

响应在此上下文中不可用。我该怎么解决这个问题我需要帮助我试图解决它,但我解决不了该网站在我的本地主机上正常工作,但当我将其上传到主机时,它就不工作了有人帮我吗

{
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
}

';中的服务器错误/';应用程序4

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

它在本地机器上工作而不能远程工作的原因可能是,网站在本地运行时处于IIS经典管道模式,而在远程运行时处于集成管道模式

您可以通过切换到经典管道模式来解决这个问题:方法如下。

希望这能有所帮助。

<%@ 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>