Monday, April 11, 2011

The biggest legal danger for open source?

The biggest legal danger for open source? | ITworld

Web 3.0, The New Information Age

The New Information Age: "Web 3.0 will be real identities generating massive amounts of data.”"

How to verify address by Microsoft Bing map geo service?

Add  GeocodeService webserivice into your project
        private bool GeocodeAddress(string address)
        {
            GeoLocation results = null ;
            string key = "Bing map key";
            GeocodeRequest geocodeRequest = new GeocodeRequest();
 
            // Set the credentials using a valid Bing Maps key
            geocodeRequest.Credentials = new Credentials();
            geocodeRequest.Credentials.ApplicationId = key;
 
            // Set the full address query
            geocodeRequest.Query = address;
 
            // Set the options to only return high confidence results 
            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = Confidence.High;
 
            // Add the filters to the options
            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;
 
            // Make the geocode request
            Registration.GeocodeService.GeocodeService geocodeService = new  GeocodeService.GeocodeService();
            GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
 
            if (geocodeResponse.Results.Length > 0)
            {
                Return true;
            }
            Return false;
        }


Reference:



How to verify US postal code by regular expression?


        public static bool IsValid (string postcode)
        {
            if (postcode == ""return true;
            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"^(\d{5}-\d{4}|\d{5}|\d{9})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)$");
            return r.IsMatch(postcode.ToUpper());
        }

How to verify Canada postal code by regular expression?

        public static bool IsValid (string postcode)
        {
            if (postcode == ""return true;
            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$");
            return r.IsMatch(postcode.ToUpper());
        }

How to implment a dynamic robots.txt in ASP.NET MVC

http://www.iwantmymvc.com/2011-03-29-crawler-access-multi-target-deploy

Controller:
using System.Configuration;
using System.Web.Mvc;

namespace Website.Controllers
{
    public class CrawlerController : Controller
    {
        public ActionResult RobotsTextFile()
        {
            string content;
            if(ConfigurationManager.AppSettings["RobotTextAccess"].ToLower() == "private")
            {
                content = "User-agent: *\r\nDisallow: /";
            }
            else
            {
                content = "User-agent: *\r\nAllow: /";
            }
            Response.ContentType = "text/plain";
            Response.Write(content);
            return null;
        }
    }
}
Routing
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Robots.txt",
        "Robots.txt",
        new { controller = "Crawler", action = "RobotsTextFile" }
    );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );

}