Part 1 (this) Basics (mostly server side)
Part 2 ExtJS Client Side Details

 

Introduction

In this series of articles, we will take the reference application build by the Sencha product team for using Sencha’s MVC pattern running with an ASP.NET 4.0 project (IIS in production).  The first article takes the reference Sencha MVC app and with almost no changes, makes it work with the ASP.NET Visual Studio 2010 project.  By default, the application works with JSON static files.  We change that to work with an ASP.NET MVC3 project.  The second article in the series embellishes the application to include a more real user experience by adding additional functionality and data.  The improved functionality includes both date and number columns as well as paging.  It also adds functionality for inserts and deletes which are left out of the base app from Sencha.

Visual Studio Project SenchaMVCASPNetSolution

 

The Final Project when running:

 

image

 

(more…)

Normally, when we stick a JSON file up on an IIS web server, all we have to do to get to is is to set the Mime type.  One easy way to do it is to add to your web.config the following:

 

<system.webServer>    <validation validateIntegratedModeConfiguration="false" />    <modules runAllManagedModulesForAllRequests="true" />    <staticContent>      <mimeMap fileExtension=".json" mimeType="application/json"  />    </staticContent>    ...

 

This works great as long as the GET verb is used (or just enter the on the url like http://mysite.com/myfile.json).

So, what if you "need” to use the POST keyword.  Say for example, you can not change the JavaScript file to use GET instead of POST to get the file.  I was hoping to find some simple web.config parameter to set but I had no luck.  I even posted to StackOverflow and so far, the answers have been less than helpful.  Who knows, maybe by the time you read this, there will be a better answer then my solution which is to write a simple asp.net handler and register it to type json.

 

So, here is the simpler handler that does the trick:

 

public class JSONHandler : IHttpHandler    {

        public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "application/json";            string output = System.IO.File.ReadAllText(context.Request.PhysicalPath);            context.Response.Write(output);

        }

        public bool IsReusable        {            get            {                return false;            }        }    }

 

and the associated web.config entries

 

<httpHandlers>     <add verb="*" path="*.json" validate="false" type="JSONHandler" />   </httpHandlers> </system.web>

 <system.webServer>   <validation validateIntegratedModeConfiguration="false" />   <modules runAllManagedModulesForAllRequests="true" />   <staticContent>     <mimeMap fileExtension=".json" mimeType="application/json"  />   </staticContent>   <handlers>     <add verb="*" path="*.json" name="JSONHandler" type="JSONHandler"/>   </handlers> </system.webServer>

I’m assuming there is a simple way, but for now, this works for me.  Please post a better solution and reference it or just tell me in the comments.


© 2012 PeterKellner.net. All Rights Reserved
Follow

Get every new post delivered to your Inbox

Join other followers: