xoail
xoail

Reputation: 3064

Sitecore Web Service Url Length

So for some reason sitecore seems to be rejecting the longer version of this url http://site1.com/sitecore%20modules/shell/service.svc/terms/a new term to find for all/ with error:

[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
   System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +14652406
   Sitecore.Web.RequestUrl.get_ItemPath() +157
   Sitecore.Pipelines.HttpRequest.SiteResolver.GetItemPath(HttpRequestArgs args, SiteContext context) +55
   Sitecore.Pipelines.HttpRequest.SiteResolver.UpdatePaths(HttpRequestArgs args, SiteContext site) +88
   Sitecore.Pipelines.HttpRequest.SiteResolver.Process(HttpRequestArgs args) +75
   (Object , Object[] ) +83
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +191
   Sitecore.Nexus.Web.HttpModule.(Object , EventArgs ) +457
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165

But the url http://site1.com/sitecore%20modules/shell/service.svc/terms/a new term to find/ seems to work fine. Also when I add the url in IgnoreUrlPrefix, it seems to be loosing the sitecore context altogether.

Any ideas?

Upvotes: 1

Views: 752

Answers (1)

user459491
user459491

Reputation:

I had the same problem,and if I choose a short name for my webmethod works fine. With long method name I get same error like you .

I didn't find a reason why is this behavior. Update :

I asked Sitecore Support about this issue , and they send me this link .

This is the code they provide :

 public class SiteResolver : SiteResolver
  {
    protected override void UpdatePaths(HttpRequestArgs args, SiteContext site)
    {
      if (!string.IsNullOrEmpty(HttpContext.Current.Request.PathInfo))
      {
        string filePath = args.Url.FilePath;
        int length = filePath.LastIndexOf('.');
        int num = filePath.LastIndexOf('/');
        args.Url.ItemPath = length >= 0 ? (length >= num ? filePath.Substring(0, length) : filePath) : filePath;
      }
      args.StartPath = site.StartPath;
      args.Url.ItemPath = this.GetItemPath(args, site);
      site.Request.ItemPath = args.Url.ItemPath;
      args.Url.FilePath = this.GetFilePath(args, site);
      site.Request.FilePath = args.Url.FilePath;
    }
  }

To works fine, IgnoreUrlPrefixes should not contains Asxm webservice path, and siteresolver configuration must be:

   <processor type="Sitecore.Pipelines.HttpRequest.SiteResolver, Sitecore.Kernel">
      <patch:attribute name="type">yourNamespace.CustomSiteResolver,yourAssembly</patch:attribute>
    </processor>

Upvotes: 2

Related Questions