Monday, November 17, 2008

Creating RESTful Web Service Using System.Web.Routing Part 1


  1. Created new ASP.NET web site using VS 2008

  2. Deleted default .aspx page

  3. Added Global Application File (Global.asax)

  4. Added following code to Application_Start() method in Global.asax

    Route route = new Route("students", new StudentsRouteHandler());
    RouteTable.Routes.Add(route);

  5. Added following class:

    public class StudentsRouteHandler : IRouteHandler, IHttpHandler {

    public IHttpHandler GetHttpHandler(RequestContext requestContext) {
    return (this);
    }

    public void ProcessRequest(HttpContext context) {

    context.Response.Write("<h1>Hello World!</h1>");
    }

    public bool IsReusable { get; set; }
    }



  6. Added the following to the httpmodules section of the Web.config :


    <add name="Routing" type="System.Web.Routing.UrlRoutingModule,
    system.Web.Routing, Version=3.5.0.0, Culture=neutral,PublicKeyToken=31BF3856AD364E35">




  7. Edited 'properties' of new web project on 'Web' tab configured it to use IIS server rather than visual studio development server. A new virtual directory is created as a side effect of this.

  8. In iis.msc edited properties of new site. On 'Directory Security' tab clicked on 'Configure' button and CHECKED the Integrated Windows Authentication check box all the way at the bottom

  9. Last but not least, in iis.msc edited properties of new site. On Virtual Directory tab clicked on 'Configuration' Button.

    Added:
    Executable: c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
    Extension: .*
    All Verbs
    UN-CHECK 'Check that file exists'




While trying to get it to work I mixed in a superstitious IISReset. I'm not sure if its required but I think not.

Wednesday, November 12, 2008

Visual Studio Still Refuses to Eat Its Own Syntactic Candy

Its been available since VS 2005 but even as of VS 2008 the designer still generates:

_fooGrid.CurrentCellDirtyStateChanged += new System.EventHandler(this._fooGrid_CurrentCellDirtyStateChanged);


When this will suffice:

_fooGrid.CurrentCellDirtyStateChanged += _fooGrid_CurrentCellDirtyStateChanged;

C# Sucks!

JK!! Seriously, though, somewhere around C#-3 we should have inculcated ourselves with the question: "Does 'CAN' == 'SHOULD...