Posts tagged with 'c#'

  • Love them or hate them, the humble CAPTCHA is a tried and trusted approach to mitigating spam content from infiltrating your beautifully crafted application and flooding it with adverts selling all kinds of nefarious goods. Whilst their effectiveness is debatable and the frustration that they bring about in some high, they are relatively simple to use and catch the bulk of user defined content one would want to filter from their site.

    Read more…

  • I'm a fan of the Data Annotation Validation attributes to validate user input on both the client and server side for ASP.NET MVC applications. I'm also a fan of Inversion of Control and Dependency Injection to create loosely coupled and flexible applications. There are certain situations where one would wish to inject services into a validation attribute to use during validation; a (somewhat contrived and security cautious) example of this might be providing the user with a <select> element and ask them to choose an option from it and then validate that the option that they have chosen is one that actually exists for the type of items represented in the dropdown. Sure, the RemoteAttribute would allow you to call a server side method via AJAX to perform validation but it does not provide any server side validation, making it more of a convenience solution than a complete and robust one. What would be good is if we could

    1. provide services to a validation attribute that could be used in the process of validation
    2. Not have to explicitly resolve services from the container à la the Service Locator (Anti-)Pattern

    Read more…

  • Having a good url routing scheme is extremely important when developing an application. Urls should be canonical to aid in search engine optimization and discoverable in order to aid users in learning where to find application functionality for particular tasks. But there are points in an applications lifecycle where one wishes to change the url routing scheme in order to employ a better one. In such instances, URL redirection can be used to preserve search engine rankings, user bookmarks to specific pages or to allow more than one URL to serve up the same content, as is the case when employing URL shortening.

    Read more…

  • UPDATE: I've added a simple example project up on bitbucket to demonstrate the ColorPicker attribute

    ASP.NET MVC 3 introduces a new interface, IMetadataAware, for providing additional values to the model metadata at creation time:

    /* ****************************************************************************
     *
     * Copyright (c) Microsoft Corporation. All rights reserved.
     *
     * This software is subject to the Microsoft Public License (Ms-PL). 
     * A copy of the license can be found in the license.htm file included 
     * in this distribution.
     *
     * You must not remove this notice, or any other, from this software.
     *
     * ***************************************************************************/
    
    namespace System.Web.Mvc {
        // This interface is implemented by attributes which wish to contribute to the
        // ModelMetadata creation process without needing to write a custom metadata
        // provider. It is consumed by AssociatedMetadataProvider, so this behavior is
        // automatically inherited by all classes which derive from it (notably, the
        // DataAnnotationsModelMetadataProvider).
        public interface IMetadataAware {
            void OnMetadataCreated(ModelMetadata metadata);
        }
    }

    Read more…