REST services on IIS 6

   —   
This article deals with how to establish REST services with Kentico CMS on IIS 6.
The pre-requisite of REST is that you need the Integrated pipeline mode. As IIS 6 does not offer this, the recommended solution is to upgrade to IIS 7 and follow the standard instructions.

There is a workaround for making REST services work on IIS 6, however this is only a workaround and we will not be supporting IIS 6 at all in the future, so the recommended solution remains upgrading to IIS 7. But should you wish to get REST Services to work on IIS 6, follow these simple instructions: 
  1. You need to configure IIS for extension-less URLs. Take a look at this article: Custom URL extensions - IIS 6 and configure handler404
     
  2. You need to re-write this file:

    <web site folder>\App_Code\Application\CMSAppBase.cs
     
    Find the CMSMapRequestHandler method and add the code in yellow:


                    // Set flag to output filter for cms dialogs
                    if (excludedEnum == ExcludedSystemEnum.CMSDialog)
                    {
                        OutputFilter.UseFormActionWithCurrentURL = true;
                    }
                   
                   // IIS6 REST issue fix
                    if (relativePath.ToLower().Equals("/cmspages/handler404.aspx") && URLHelper.CurrentURL.ToLower().Contains("/rest"))
                    {
                        // Application runs in virtual directory
                        if (!URLHelper.ApplicationPath.Equals("/"))
                        {
                            relativePath = URLHelper.CurrentURL.Replace(URLHelper.ApplicationPath, "");
                        }
                        else
                        {
                            relativePath = URLHelper.CurrentURL;
                        }
     
                        string queryString = relativePath..Replace(URLHelper.RemoveQuery(relativePath), "").Replace("?", "");
                        relativePath = URLHelper.RemoveQuery(relativePath);
     
                        // Rewrite REST Service
                        if (relativePath.ToLower().StartsWith("/rest/") || relativePath.EndsWith("/rest"))
                        {
                          string[] urlparts = CMS.RESTService.RESTService.RewriteRESTUrl(relativePath, queryString, URLHelper.GetFullDomain().ToLower());
                          if (urlparts.Length == 2)
                          {
                           HttpContext.Current.RewritePath(urlparts[0], HttpContext.Current.Request.PathInfo, urlparts[1]);
                          }
                          URLRewriter.CurrentStatus = URLRewritingResultEnum.RESTService;
                        }
                     }
                     else
                     {
                      // Perform the URL rewriting
                      RewriteUrl(status, relativePath, excludedEnum, viewMode, siteName);
                     }
    }
    // Finalize the event
    h.FinishEvent();

     
-hg-


See also: REST services overview


Applies to: Kentico CMS 6.x
Share this article on   LinkedIn