RadCaptcha not displaying when ImageStorageLocation is set to session

12 posts, 0 answers
  1. Brian Farnhill
    Brian Farnhill avatar
    10 posts
    Member since:
    Dec 2009

    Posted 24 Mar 2010 Link to this post

    Hi guys,

    I am having an issue with the RadCaptcha control. We need to set the ImageStorageLocation to CaptchaImageStorage.Session in order to make the control work in our environment (we are not using persistent load balancing). My problem is that when the property is set this way the Captcha image is always broken (the URL returns a 404 error). If I set it back to cache the image displays fine on my local box (but has the same issues that you would expect to see across the farm environment with the gray box and not validating correctly).

    From what I can tell this is being caused by a null reference exception that is coming out of the ProcessRequest method of the CaptchaImageHandler class, but from what I can see on my end I'm not exactly sure what is causing this.

    I'm using the web part as part of a web part for a MOSS 2007 website. Below is the code I am using to add the control to the page inside the CreateChildControls method

    Controls.Add(new RadCaptcha  
    {  
        Display = ValidatorDisplay.Static,  
        EnableRefreshImage = true,  
        ErrorMessage = "The code you entered is not valid",  
        IgnoreCase = true,  
        CaptchaTextBoxLabel = "Please enter the code from the above image.",  
        ImageStorageLocation = CaptchaImageStorage.Session  
    }); 

    Can anyone help me shed any light on why this is happening? We need to take our solution to production in the next week or two at latest and I would really like to keep the Captcha control on the form

    Cheers,

    Brian Farnhill
    SharePoint Server MVP
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 27 Mar 2010 Link to this post

    Hello Brian,

    Thank you for reporting this problem. It seems that, when the ImageStorageLocation property is being set dynamically, it does not get applied correctly to the CaptchaImage. For the time being, use the following workaround, that sets the correct URL to the Image:

    protected void Page_Load(object sender, EventArgs e)
    {
        RadCaptcha1.ImageStorageLocation = CaptchaImageStorage.Session;
        RadCaptcha1.EnableRefreshImage = true;
     
        ///Workaround when ImageStorageLocation set dynamically
        #region Workaround
        Image img = RadCaptcha1.Controls[1].Controls[1] as Image;
        UpdatePanel up = RadCaptcha1.Controls[1].Controls[0] as UpdatePanel;
        Image img1 = up.ContentTemplateContainer.Controls[0] as Image;
     
        string imgURL = img.ImageUrl;
     
        imgURL = imgURL.Substring(0, imgURL.IndexOf("&guid"));
        imgURL = imgURL + "&guid=" + Convert.ToString(RadCaptcha1.CaptchaImage.UniqueId);
     
        if (RadCaptcha1.ImageStorageLocation == CaptchaImageStorage.Session)
        {
            imgURL = imgURL + ("&isc=" + "false");
        }
     
        img.ImageUrl = imgURL;
        img1.ImageUrl = imgURL;
        #endregion Workaround
     
     
    }

    Place this code, right after the one that creates the RadCaptcha object. Please let me know if you have any problems with the workaround (or anything else).

    The issue will be fixed for the next official release of RadControls for ASP.NET AJAX.

    I have updated your account with 500 Telerik points, for bringing this problem to our attention.


    Sincerely yours,
    Pero
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brian Farnhill
    Brian Farnhill avatar
    10 posts
    Member since:
    Dec 2009

    Posted 28 Mar 2010 Link to this post

    Hi there,

    Thanks for the info - I'm having some issues with the work around on this one though, here is the code that is now in my CreateChildControls() method.

                        RadCaptcha captcha = new RadCaptcha  
                        {  
                            Display = ValidatorDisplay.Static,   
                            EnableRefreshImage = true,  
                            ErrorMessage = "The code you entered is not valid",  
                            IgnoreCase = true,  
                            CaptchaTextBoxLabel = "Please enter the code from the above image.",  
                            ImageStorageLocation = CaptchaImageStorage.Session  
                        };  
     
                        Controls.Add(captcha);
                        #region Workaround  
                        Image img = captcha.Controls[1].Controls[1] as Image;  
                        UpdatePanel up = captcha.Controls[1].Controls[0] as UpdatePanel;  
                        Image img1 = up.ContentTemplateContainer.Controls[0] as Image;  
     
                        string imgURL = img.ImageUrl;  
     
                        imgURL = imgURL.Substring(0, imgURL.IndexOf("&guid"));  
                        imgURL = imgURL + "&guid=" + Convert.ToString(captcha.CaptchaImage.UniqueId);  
     
                        if (captcha.ImageStorageLocation == CaptchaImageStorage.Session)  
                        {  
                            imgURL = imgURL + ("&isc=" + "false");  
                        }  
     
                        img.ImageUrl = imgURL;  
                        img1.ImageUrl = imgURL;
                        #endregion Workaround 

    When I debug it all I can see that the URL that is being generated from the imgURL string there is actually the URL that is hitting the page, which leads me to believe that your code is doing what is supposed to do, but I am still getting the error when trying to load the image. The URL that is being generated looks like this:

    http://servername/Telerik.Web.UI.WebResource.axd?type=rca&isc=false&guid=ec8a4cd6-2208-443f-8b1b-55389b5118da&isc=false

    Any ideas on what I can try next?

    Regards,

    Brian Farnhill
    SharePoint Server MVP
  5. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 29 Mar 2010 Link to this post

    Hello Brian,

    Looking at the URL of the image, I can see that the problem is not caused by an incorrect URL (the isc=false appears twice in the imageURL, which suggests that the storage location of the image is applied correctly). So, please discard the workaround I send you in the previous post.

    • Please provide more information about the application environment:
      1. Are you using WebGarden (more than one worker processes are used to run the web site)?
      2. Are you using WebFarm - more than one web server?
      3. Is your Session state shared among different servers or different processes?
      4. Is your Cache shared among different servers or processes?
    • Are you using any kind of user authentication or authorization? If yes, you need to grant access to all users to Telerik.Web.UI.WebResourceSession.axd

    If possible, please isolate the problem in a separate sample project, and send it back to us. This will enable us to observe the issue locally. You need to open a support ticket to attach files.

    All the best,
    Pero
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Jason Zam
    Jason Zam avatar
    18 posts
    Member since:
    Aug 2009

    Posted 26 Apr 2010 Link to this post

    Hello,

    Has this been resolved?

    We are running a web farm production environment so I will have to use the ImageStorageLocation attribute value of "session" and would like to know if I will run into any problems.

    Thanks!
    Jason
  7. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 29 Apr 2010 Link to this post

    Hi Jason,

    There should be no problem as long as the Session is shared among the different web servers, and the HttpHandler of RadCaptcha is correctly registered in the web config (i.e. type="Telerik.Web.UI.WebResourceSession").

    Greetings,
    Pero
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Virgil Carroll
    Virgil Carroll avatar
    3 posts
    Member since:
    Dec 2005

    Posted 23 Jul 2010 Link to this post

    Pero,

    We are trying to use the Captcha in a MOSS Webpart as well, can you please provide info on what you mean by this statement:

    "Are you using any kind of user authentication or authorization? If yes, you need to grant access to all users to Telerik.Web.UI.WebResourceSession.axd"

    Right now we are getting an error until we take out the Captcha control.

    Thanks. 
  9. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 27 Jul 2010 Link to this post

    Hi Virgil,

    When using (for example) "Forms" mode for user authentication and authorization, and when access to the web-site's resources has been granted to the registered users only, a broken image link will be rendered on the place of the CaptchaImage. This means that the handler which serves the CaptchaImage is a restricted resource for the anonymous users, and if a registered user logs in s/he will see the CaptchaImage. To overcome this issue, access needs to be granted to the handler that serves the image, using the <location> element, similarly as shown below:

    1.
    <location path="Telerik.Web.UI.WebResourceSession.axd">
      <system.web>
        <authentication mode="None"></authentication>
      </system.web>
    </location>

    or

    2.
    <location path="Telerik.Web.UI.WebResourceSession.axd">
      <system.web>
        <authorization>
          <allow users="*"/>
        </authorization>
      </system.web>
    </location>

    I hope this was helpful.

    Best wishes,
    Pero
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Scott
    Scott avatar
    15 posts
    Member since:
    Aug 2012

    Posted 28 Jan 2011 Link to this post

    This is giving me some pain when I have a page that initially hides (Visible="false") the RadCaptcha control. If a user fails to submit the form in 6 tries, it then sets the visibility property to true in server-side code. However, the first time it sets the visibility property to true, the box is ALWAYS gray. Then the next time it is submitted, the text displays correctly. I am considering removing the RadCaptcha and go with another CAPTCHA control. Let me know if you have a fix. My settings are below. Thank you for your help.

    Telerik.Web.UI version: 2010.2.826.35
    Sitefinity Version: 3.7 SP 4

    Web.config settings:
    <!-- This block needs to be in place specifically for the RadCaptcha control. Otherwise it will show up completely grayed out. -->
    <location path="Telerik.Web.UI.WebResourceSession.axd">
      <system.web>
         <authentication mode="None"></authentication>
      </system.web>
    </location>
     
     
    ...
    <add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResourceSession" validate="false"/>
     
     
    ...
    <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResourceSession, Telerik.Web.UI"/>



    ASPX section:
    <telerik:RadCaptcha runat="server" ID="captchaControl" Visible="false" Display="None"
                ImageStorageLocation="Session"
                ErrorMessage="Your CAPTCHA entry was not correct. Please try again.>
    </telerik:RadCaptcha>

    C# section:
    //If we've exceeded the number of allowed incorrect attempts, display the CAPTCHA control.
    if (this.CurrentIncorrectLoginAttempts > this.incorrectAttemptsAllowed)
    {
           this.captchaControl.Enabled = true;
    }

  11. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 31 Jan 2011 Link to this post

    Hello Scott,

    I tried to reproduce the issue locally but to no avail. Please find my test project attached to the thread.
    Would it be possible to send us a sample project that reproduces the issue, so we can observe it locally? I suspect that the problem is related to the page life cycle, so could you please tell me when do you set the Visible property of the Captcha to true.

    All the best,
    Pero
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  12. Scott
    Scott avatar
    15 posts
    Member since:
    Aug 2012

    Posted 31 Jan 2011 Link to this post

    Pero,

    Thanks for your help. I am setting the Visible property to 'true' in a button click event handler (when the user tries to login after 6 attempts). As I said, the box displays when I set its visible and enabled properties, but the first time it shows gray. Then if I click submit again, it shows with the appropriate characters. 

    Could Sitefinity play into this at all?

    Thanks,

    Scott
  13. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 01 Feb 2011 Link to this post

    Hello Scott,

    I integrated the code from my previous ticket in a Sitefinity 3.7 SP4 page, and everything seems to be working properly. I am not sure what might be causing this issue on your side. Is it possible that your application runs in a web farm environment, and the Session is not shared among the different processes?
    Note, that the CaptchaImage is added to the Session/Cache before Page's Render method is run (i.e. OnPreRender), and if the Visible property is set to false, an image will not be added. But, you are setting Visible="true" to the RadCaptcha when a button is clicked, which is executed before Page.PreRender.

    Another thing you could try is always have the RadCaptcha visible, but use display: none to hide the Captcha, and use Enabled to enable/disable validation.

    //hide
    RadCaptcha1.Style.Add(System.Web.UI.HtmlTextWriterStyle.Display, "none");
    //show
    RadCaptcha1.Style.Add(System.Web.UI.HtmlTextWriterStyle.Display, "");

    Best wishes,
    Pero
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017