在这种情况下,响应不可用. Response.Write(ex.ToString()); [英] Response is not available in this context. Response.Write(ex.ToString());

查看:72
本文介绍了在这种情况下,响应不可用. Response.Write(ex.ToString());的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照经典代码在global.asax中编写了此代码.每次我启动网站时,都会显示此错误.刷新页面后,页面转到正确的页面.我不明白为什么.

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>





在这种情况下,响应不可用.说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息.





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

推荐答案

由于无法进行服务器端编码,请使用其他选项.
Since it cannot have server side coding use some other option.


尝试使用System.Web.HttpContext.Current.Request


在应用程序端检查会话值,并在session_end块或application_end事件中检查天气response.redirect或server.transfer
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


这篇关于在这种情况下,响应不可用. Response.Write(ex.ToString());的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆