About .NET, ASP.NET, MVC, C#, WPF, WCF and everything related to .NET and more.

Captcha Mvc [Storage provider]

To store captcha values ​​used interface IStorageProvider, its definition is:

/// <summary>
/// Represents the storage to save a captcha tokens.
/// </summary>
public interface IStorageProvider
{
    /// <summary>
    /// Adds the specified token and <see cref="ICaptchaValue"/> to the storage.
    /// </summary>
    /// <param name="captchaPair">The specified <see cref="KeyValuePair{TKey,TValue}"/></param>
    void Add(KeyValuePair<string, ICaptchaValue> captchaPair);

    /// <summary>
    /// Gets the <see cref="ICaptchaValue"/> associated with the specified token.
    /// </summary>
    /// <param name="token">The token of the value to get.</param>
    /// <returns>When this method returns, contains the value associated with the specified token,
   ///if the token is found; otherwise, return <c>null</c> value.</returns>
    ICaptchaValue GetDrawingValue(string token);

    /// <summary>
    /// Gets the <see cref="ICaptchaValue"/> associated with the specified token.
    /// </summary>
    /// <param name="token">The token of the value to get.</param>
    /// <returns>When this method returns, contains the value associated with the specified token, 
    /// if the token is found; otherwise, return <c>null</c> value.</returns>
    ICaptchaValue GetValidationValue(string token);
}
Add method is responsible for adding value captcha.
GetDrawingValue method returns a value for rendering captcha for a given token.
GetDrawingValue method returns a value of captcha validation for a given token.
By default, in all implementations values deleted after the first of its request.

You are available the two implementations:
  • CookieStorageProvider - uses a cookie to store the ​​captcha values.
  • SessionStorageProvider - uses the session to store the captcha values.
An example of how to set the provider to store the captcha:
protected void Application_Start()
{
    CaptchaUtils.CaptchaManager.StorageProvider = new CookieStorageProvider();
    ..............

Comments

Hi,

Where does the captcha store state? In local cache? If i want to change the storage, from local cache to distributed cache, is there a way to configure it or do I have to implement the IStorageProvider?

Thanks,
Martin

Leave a Reply
*bold*
_italics_
+underline+
* Bullet List
** Bullet List 2
# Number List
## Number List 2
{"Do not apply formatting"}
{code:language} code here {code:language}.
Supports: aspx c#, c#, c++, html, sql, xml
[url:http://www.example.com]