0

Response is not available in this context. how can i solve this problem i need some help please i tried to solve it but i couldnt the website work properly on my local host but when i upload it to the host its doesnt work anybody help me please

{

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
}
Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
Lelo
  • 11
  • 1
  • 4
    You overestimate our ability to read your mind. – Mr Lister Jul 17 '13 at 12:37
  • 1
    Attach code, give more informations about your page, try a bit more to explain your problem – Kamil Budziewski Jul 17 '13 at 12:37
  • there might be different scenario, just think about the deployment environment and share your code. If possible, modify the code by introducing a try catch block and write to file and send that to production environment – kbvishnu Jul 17 '13 at 12:44
  • @MichaelPerrenoud Here there is no proof to say that. Question doesn't give any proper information. – kbvishnu Jul 17 '13 at 12:47
  • 1
    @VeeKayBee, take note to the text automated by the system when identifying a duplicate - **possible duplicate of**. Further, if it works locally, but not when it's deployed, there's clearly an issue surrounding the configuration of the web server. I found an answer by Darin that is **really common mistake** when configuring websites. Simple. – Mike Perrenoud Jul 17 '13 at 12:52
  • @MichaelPerrenoud agreed your argument,but I said we can clarify if we get some more information. – kbvishnu Jul 17 '13 at 13:00

3 Answers3

3

As the error says, you can not access the Response object in Application_Start. Check (and preferably post) the code in Global.asax for the Application_Start method.

Erik Schierboom
  • 16,301
  • 10
  • 64
  • 81
AUSteve
  • 3,238
  • 21
  • 36
  • my code is to long to be post here what should i do ? – Lelo Jul 17 '13 at 12:45
  • @hussein check this http://stackoverflow.com/questions/6624210/response-is-not-available-in-this-context – kbvishnu Jul 17 '13 at 12:46
  • @VeeKayBee, you're seriously going to post that link? You just argued against it. – Mike Perrenoud Jul 17 '13 at 12:54
  • @MichaelPerrenoud I am not arguing against that. I am very sorry if you feels, what I meant is in the other question we can see the code and others can able to identify what is happening. I just said that if he can check the question and share the code it will be more helpful. If it happens we can be sure about both are same. The answer also points to the same issue you mentioned. – kbvishnu Jul 17 '13 at 12:58
  • @VeeKayBee i read that code but it didnt give me any help i have another code in my global.asax that totally different can you give me any help ? – Lelo Jul 17 '13 at 13:20
0

The reason why it works on your local machine and doesn't work remotely is probably because locally the website is running under IIS classic pipeline mode while remotely - under integrated pipeline mode.

You can solve the problem by switching to classic pipeline mode: here's how.

Hope this helps.

volpav
  • 5,090
  • 19
  • 27
0
<%@ 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>
Lelo
  • 11
  • 1