locked
Unhandle exception on Global.asax page about FormsAuthentication.SignOut() (I guess) RRS feed

  • 問題

  • Hi

     

    I have received the following message on the event Error Log in my test Web server("WEB-TEST"). That error occur every time when people access the web site, it generate that error on the Event Log.

     

    #########################################################
    Event code: 3005
    Event message: An unhandled exception has occurred.
    Event time: 01/07/2008 12:03:07
    Event time (UTC): 01/07/2008 11:03:07
    Event ID: 287c6311019846ab8e6064134c4a6e41
    Event sequence: 9
    Event occurrence: 1
    Event detail code: 0
     
    Application information:
        Application domain: /LM/W3SVC/1/Root/webtest-2-128593837829380484
        Trust level: Full
        Application Virtual Path: /webtest
        Application Path: C:\Websites\webtest\
        Machine name: WEB-TEST
     
    Process information:
        Process ID: 1444
        Process name: w3wp.exe
        Account name: NT AUTHORITY\NETWORK SERVICE
     
    Exception information:
        Exception type: HttpException
        Exception message: Response is not available in this context.
     
    Request information:
        Request URL:
        Request path:
        User host address:
        User:
        Is authenticated: False
        Authentication Type:
        Thread account name: NT AUTHORITY\NETWORK SERVICE
     
    Thread information:
        Thread ID: 1
        Thread account name: NT AUTHORITY\NETWORK SERVICE
        Is impersonating: False
        Stack trace:    at System.Web.HttpApplication.get_Response()
       at ASP.global_asax.Session_End(Object sender, EventArgs e)
     
     
    Custom event details:

    For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
    #########################################################

    Here it is the code on my Global.asax page

     

    Code Snippet

    <%@ Application Language="VB" %>

    <script runat="server">

        Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs on application startup
            Dim customer As New CustomerClass
            Application("customer") = customer.getCustomer()
           
            myCounty = Nothing
       
        End Sub
       
        Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs on application shutdown
        End Sub
           
        Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            Dim objErr As Exception = Server.GetLastError().GetBaseException()
            Dim err As String = ""
          
            err = err & "Error Message:" & objErr.Message.ToString()

        End Sub

        Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs when a new session is started
        End Sub


        Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
               
          if not Session("sessionID") is nothing then
                Dim myLog As New logDB()
                myLog.Updatelog(Session("sessionID"))
            End If

            FormsAuthentication.SignOut() 'I guess this is where it cause the problem

            Response.Redirect("login.aspx")
        End Sub
       
        Private Sub Global_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.BeginRequest
            Response.AddHeader("P3P", "CP=""NOI DSP COR ADMa IVDa OUR NOR""")
        End Sub


          
    </script>

     

     

    Could you give me some suggestion on how to prevent that error, it is quite annoying as every time when people access the web site, it generate that error on the Event Log.

    Thanks in advance.

    2008年7月1日 上午 11:43

解答

  • Hello ChiYau,
              I'm sorry for not replying you immediatly,I think this exception is caused by the code written in Session_End region.There is no need to add FormAuthentication.Signout() function here,you can use LoginStatus Control in your webpage to perform logout function.
              Perhaps if you remove "FormsAuthentication.SignOut()" field, I think you may get a good result.

    2008年8月4日 上午 02:47
  • Hello ChiYau

     

    Don't be so modest like this. I think there is no need to add  "FormsAuthentication.SignOut()"  elseware in your webpage, by the way, if you want to call "FormsAuthentication.SignOut()" , you should not add these code in Global.asax, this file is mainly used to  initialize and finalize the usage of session,applicion and viewstate.

    I hope these words would be helpful.   : )

     

     

     

    2008年8月4日 上午 07:56

所有回覆

  • FormsAuthentication? What is this object type?

     

    2008年7月30日 上午 04:42
  • Hi Ken

    Thanks for your reply, FormsAuthentication is a class under System.Web.Security namespace.

    FYI: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.signout.aspx

    Not sure what I always receive Unhandle exception on my global.asax page.

    Thanks in advance


    2008年7月30日 上午 07:38
  • Hello ChiYau,
              I'm sorry for not replying you immediatly,I think this exception is caused by the code written in Session_End region.There is no need to add FormAuthentication.Signout() function here,you can use LoginStatus Control in your webpage to perform logout function.
              Perhaps if you remove "FormsAuthentication.SignOut()" field, I think you may get a good result.

    2008年8月4日 上午 02:47
  • Hi Hansan

    Thanks for your reply. I am sorry I am quite stupid. What I am trying to do is to ensure the user get log out whenever the session get timeout and the use click on the Logout button. I already have a LoginStatus control on the sitemaster page. Does it mean I do not need to have a code "
    FormsAuthentication.SignOut()" any where on the web site?


    Thanks very much for your help.
    2008年8月4日 上午 07:44
  • Hello ChiYau

     

    Don't be so modest like this. I think there is no need to add  "FormsAuthentication.SignOut()"  elseware in your webpage, by the way, if you want to call "FormsAuthentication.SignOut()" , you should not add these code in Global.asax, this file is mainly used to  initialize and finalize the usage of session,applicion and viewstate.

    I hope these words would be helpful.   : )

     

     

     

    2008年8月4日 上午 07:56
  • Hi Hansen,

    Thanks very much for your quick reply, I understood it now.

    Thanks a lot.
    2008年8月4日 上午 08:11