5

I'm working on a scenario that requires I use session state in API calls. I found an article that discusses the setup, https://www.c-sharpcorner.com/UploadFile/dacca2/web-api-with-ajax-handle-session-in-web-api/, but it requires hooking into the Application_PostAuthorizeRequest function of global.asax. I'd rather not have a global.asax modification, and I know it's common to have Application_Start content called using the Initialize pipeline. Does anyone know of a similar pipeline for Application_PostAuthorizeRequest?

4
  • Which Sitecore version you are using? Apr 18 '19 at 12:07
  • Using Sitecore 9.0.2. Modifying the global.asax does work, I'd like to find a cleaner/"Sitecorian" way if possible. Apr 18 '19 at 13:28
  • Sitecore9 httpRequestBegin pipeline fires from OnPostAuthentication HTTP module event. This was previously from OnBegin event, so you should be able to access authenticated user information in the pipeline now. Apr 18 '19 at 14:24
  • Looks like that should do the trick, if you'd like to classify that as an answer, I can give you credit. Thanks! Apr 18 '19 at 20:01
0

In Sitecore 9, the httpRequestBegin pipeline fires from OnPostAuthentication HTTP module event. This was previously from the OnBegin event, so you should be able to access authenticated user information in the pipeline now.

Please keep in mind this will fire for each request.

sample code here:

public class PostAuthentication : HttpRequestProcessor
    {
        public override void Process(HttpRequestArgs args)
        {           
            // Here you can write yours post auth logic

            //check authenticat user i.e. Context.User.IsAuthenticated
        }
    }

You can add config patch as per your requirement:

<sitecore>
    <pipelines>      
      <httpRequestBegin>
        <processor type="xxx.xxx.xxx.Pipelines.PostAuthentication, assemblyName"  patch:after="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"/>
      </httpRequestBegin>
    </pipelines>
</sitecore>

I am not sure if you can access the session. Alternatively you can use custom properties(user profile), e.g. Context.User.Profile.SetCustomProperty("User ID","testuser").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.