1

How to retained the session, when i clicked the media url session is null.

I have developed external based authentication, I stored value on session, When i clicked the media url or Pdf url(used iframe to show pdf) session is null, I could not able to find the reason. please help me to resolve the issue.

Note : I used pdfreader and passing media url to override the pdf, that time is session got disturbed.

Configuration :

 <pipelines>
        <httpRequestProcessed>
            <processor patch:after="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"
                       type="FKC.Foundation.EF.Identity.Pipelines.WebGateIdentityProcessor, FKC.Foundation.EF.Identity"/>
            <processor patch:before="processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']"
                         type="FKC.Foundation.EF.Identity.Pipelines.BrowserDetectionProcessor, FKC.Foundation.EF.Identity"/>
        </httpRequestProcessed>
 </pipelines>

public class WebGateIdentityProcessor : HttpRequestProcessor, IReadOnlySessionState
{
    public override void Process(HttpRequestArgs args)
    {
        if (Sitecore.Context.Domain.Name == "sitecore" || Context.Site == null || HttpContext.Current.Request.QueryString["isPdfReader"] != null)
        {
            return;
        }

        var currentUrl = HttpContext.Current.Request.Url;

        var excludedUrls = Settings.IdentityExcludedUrls != null ? Settings.IdentityExcludedUrls.Split('|') : null;
        if ((excludedUrls != null && excludedUrls.Length > 0) && (excludedUrls.Where(w => currentUrl.ToString().ToLower().Contains(w.ToLower())).Any()))
        {
            //Skipping identity check if request is from excluded paths
            return;
        }

        bool Isadmin = false;

        if (Regex.IsMatch(currentUrl.ToString(), "admin"))
        {
            return;
        }

        if (CheckSession())
        {
            RedirectToLandingPage();
        }
        else
        {
            RedirectToLoginPage();
        }


        return;
    }


    #region Private Methods
    /// <summary>
    /// Check user session, if not valid redirect to login page.
    /// </summary>
    private bool CheckSession()
    {
        bool returnValue = false;

        if (HttpContext.Current?.Session?["InternetUser"] != null)
        {
            UserIdentity _userIdentity = HttpContext.Current.Session["InternetUser"] as UserIdentity;

            if (_userIdentity.IsAuthenticated)
            {
                returnValue = true;
            }
        }
        //else
        //{
        //    HttpCookie reqCookies = System.Web.HttpContext.Current.Request.Cookies["UserAuth"];

        //    if (reqCookies != null)
        //    {
        //        if (reqCookies["IsAuthorized"].ToString() == "true")
        //        {
        //            returnValue = true;
        //        }
        //    }
        //}

        return returnValue;
    }


    /// <summary>
    /// If logged-in user trying to open url in browser different window/tab, user will redirect to landing/welcome page
    /// </summary>
    private void RedirectToLandingPage()
    {
        return;
    }


    /// <summary>
    /// If logged-out user trying to open url in browser different window/tab, user will redirect to login page
    /// </summary>
    private void RedirectToLoginPage()
    {
        //args.Context.Response.Redirect("/AuthenticateUser?redirect=" + HttpContext.Current.Request.Url.ToString(), false);

        WebUtil.Redirect(Context.Site.LoginPage, true);

    }

    #endregion Private Methods



}

This third party functionality making session as null,

  var pdfUrl = pdfDownload.Replace(".ashx", ".pdf");
  PdfReader reader = new PdfReader(pdfUrl + "?isPdfReader=" + true);
5
  • When do you execute your code? It seems like you're trying to access the session too early briancaos.wordpress.com/2016/01/15/…
    – Marek Musielak
    Jan 31 at 19:30
  • Im using HttpRequestProcessor only, it was fine except when we are using media Library url and Pdfreader. I will upload my config pls verify
    – Hasanshali
    Feb 1 at 2:11
  • That PdfReader seems to execute backend http call. And that request doesn't have access to session. What do you do that? Why don't you just read file from media library?
    – Marek Musielak
    Feb 1 at 6:33
  • Yes backend http call making session is null. Media have some restriction if bookmarked item need to validate. So i kept it userinfo on sessions.
    – Hasanshali
    Feb 1 at 21:32
  • Not only pdfreader, xdocument also
    – Hasanshali
    Feb 1 at 22:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.