Click here to Skip to main content
16,013,747 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I wrote this code in the global.asax following the classical code. Each time I start the website it shows this error. After i refresh the page, it goes the correct page.I don't understand why.

<script runat="server">
    void Application_Start(object sender, EventArgs e) 
    {
        try
        {
            if (Roles.RoleExists("Administrators") == false)
                Roles.CreateRole("Administrators");
            if (Membership.FindUsersByName("ken").Count == 0)
            {
                Membership.CreateUser("ken", "123", "ken@jobpost.com");
                Roles.AddUserToRole("ken", "Administrators");
            }
            if (Membership.FindUsersByName("dan").Count == 0)
                Membership.CreateUser("dan", "123", "dan@jobpost.com");
            
                     
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
   }
    
  
       
</script>




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: 
Line 26:         catch (Exception ex) 
Line 27:         { 
Line 28:             Response.Write(ex.ToString()); 
Line 29:         }
Posted
Updated 24-Mar-11 20:38pm
v2

Since it cannot have server side coding use some other option.
 
Share this answer
 
Comments
Bhavna v 25-Mar-11 6:38am    
could be a reason
Try using System.Web.HttpContext.Current.Request
 
Share this answer
 
check the session value in the application end ,and check weather response.redirect or server.transfer in the session_end block or application_end events
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900