locked
Access UserName in the BeginRequest RRS feed

  • Question

  • User-1925390108 posted
    Is there anyway to find out if the user is authenticated and what's his/her UserName in BeginRequest?
    Saturday, February 24, 2007 7:46 AM

Answers

  • User1448892898 posted
    as you know we have no access to user object on Application_BeginRequest. there is different solutions based on different scenarios. for example you can save your username on a HttpCookie and the user object on a Cache named the value of the HttpCookie. you should have your username on a cookie because Cache object is application level. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 24, 2007 1:33 PM
  • User1564875471 posted

     in the begin request  the user doesnt exists ,so you can't access it ...

    the user become available after authenticateRequest Event Processed...

    Is It possible here  to write your code in  authenticateRequest function  ?

    if not possible ...  put the user in the cache i your code (eg:in page Load Event Handler )like this

     HttpRuntime.Cache("User")=UserEntity

    and retrieve it it from Your HttpModule like this

      Private Sub OnBeginRequest(ByVal sender As Object, ByVal arg As EventArgs)
            Dim cach As Caching.Cache = HttpRuntime.Cache
            Dim usr As Model.UserInfo = cach("User")
        End Sub
     

     

    see also  Application Life Cycle http://msdn.microsoft.com/en-us/library/ms178473.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 25, 2007 5:18 AM

All replies

  • User1448892898 posted
    as you know we have no access to user object on Application_BeginRequest. there is different solutions based on different scenarios. for example you can save your username on a HttpCookie and the user object on a Cache named the value of the HttpCookie. you should have your username on a cookie because Cache object is application level. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 24, 2007 1:33 PM
  • User1564875471 posted

     in the begin request  the user doesnt exists ,so you can't access it ...

    the user become available after authenticateRequest Event Processed...

    Is It possible here  to write your code in  authenticateRequest function  ?

    if not possible ...  put the user in the cache i your code (eg:in page Load Event Handler )like this

     HttpRuntime.Cache("User")=UserEntity

    and retrieve it it from Your HttpModule like this

      Private Sub OnBeginRequest(ByVal sender As Object, ByVal arg As EventArgs)
            Dim cach As Caching.Cache = HttpRuntime.Cache
            Dim usr As Model.UserInfo = cach("User")
        End Sub
     

     

    see also  Application Life Cycle http://msdn.microsoft.com/en-us/library/ms178473.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 25, 2007 5:18 AM
  • User-1925390108 posted

    In my case I used the authentication cookie to access the user name:

    FormsAuthenticationTicket ticket = 
    (FormsAuthenticationTicket)FormsAuthentication.Decrypt(OrigContext.Request.Cookies[FormsAuthentication.FormsCookieName].Value);
    string userName = ticket.Name;
     
    Sunday, February 25, 2007 2:33 PM