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? Commented Apr 18, 2019 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. Commented Apr 18, 2019 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. Commented Apr 18, 2019 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! Commented Apr 18, 2019 at 20:01

1 Answer 1

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 and acknowledge you have read our privacy policy.

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