Skip to content
djMax edited this page Sep 14, 2010 · 3 revisions

This page is a Twitter-inspired set of what I’ve been putting into AlienForce so that The Google can pick it up and help some poor soul looking for some simple object.


ZipFileHttpHandler allows you to put a zip file in your web project (e.g. Ext JS) and have the server act as if all the contained files were at that point in the tree.

source


RequireHttps and Authorize MVC attributes are nice, but can be annoying in a development environment. So the AlienForceMvcApplication base class now supports “environment tags” in appSettings (usually I put these in a separate config file not in the source tree) and then two new attributes (EnvironmentRequireHttps and EnvironmentAuthorize) allow you to set your controller or action method to conditionally require those things.

AlienForceMvcApplication
EnvironmentAuthorizeAttribute
EnvironmentRequireHttpsAttribute


StringLengthAttribute is only allowed once on a property/field/parameter. This is dumb in the case of ASP.Net MVC, because I want to say separately “your nickname is too long” or “your nickname is too short.” Makes the site look dumb when it doesn’t. So AlienForce has two tiny utility versions of this attribute MaxLengthAttribute and MinLengthAttribute. Used like so:


		[Required(ErrorMessage = "Required")]
		[MaxLength(32, ErrorMessage="TooLong")]
		[MinLength(6, ErrorMessage="TooShort")]
		public string password { get; set; }

source


Put in a CreditCardNumber object that handles validating/sanitizing and determining card type, as well as an ExpirationDate class that manages reading expiration dates (M/yy, M/yyyy, M/d/yy, M/d/yyyy). In concert with their TypeConverters, this makes it easy to use them in MVC models and have all the validation stuff work properly.


		// in your model
		[DisplayName("Credit Card Number")]
		[Required(ErrorMessageResourceName="CC_MissingNumber")]
		[CreditCard(ErrorMessageResourceName="CC_InvalidNumber")]
		public CreditCardNumber cardNumber { get; set; }

		[DisplayName("Expiration Date (MM/YY)")]
		[DateRange(true, ErrorMessageResourceName="CC_ExpiredError", DatePatterns="M/yy|M/yyyy")]
		public ExpirationDate cardExpDate { get; set; }

source


I like the System.ComponentModel.DataAnnotations stuff for doing MVC model validation. But I don’t like that I have to specify the resource type every time. I made some versions of the built in attributes that have a static resource type. Should handle most cases and make the code a little more readable. All you have to do is replace the “using” with AlienForce.Utilities.DataAnnotations.Resources. I also added a DateRangeAttribute for validating date ranges including “now or later” and “now or before.”

source


I can’t stand having a project for every little command line utility I might need. So I wrote a “Launcher” program that basically takes an assembly and a class name and calls Main(args) on it.

source


Added an easy way to have a config section in your web.config or application config with private data (using DPAPI/ProtectedData for encryption) and provided command line tool and runtime class to set new values.

source

Clone this wiki locally