Getting error loading Kentico page: System.ArgumentOutOfRangeException: Length cannot be less than

AI Support asked on May 17, 2019 07:51

Hi, I'm getting an error loading http://oes.com.qa. Can you take a look at my global.asax.cs file? I have pored over the code but I cannot figure what needs to get changed to get rid of the error.

You can view the post at the bottom of https://social.msdn.microsoft.com/Forums/en-US/21c219ec-a9da-45c2-8a05-af484590c565/update-error-length-cannot-be-less-than-zero-parameter-name-length?forum=vbgeneral

All help is greatly appreciated. Thank you

The error message is:

Server Error in '/' Application. Length cannot be less than zero. Parameter name: length Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length

Source Error:

Line 506: bool checkParameters = false; Line 507: Line 508: URLRewritingResultEnum status = URLRewriter.RewriteUrl(relativePath, excludedEnum, siteName, viewMode); Line 509: switch (status) Line 510: {

Source File: f:\hostingspaces\oryxcom1\oes.com.qa\wwwroot\App_Code\Global.asax.cs Line: 508

Stack Trace:

[ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length] System.String.Substring(Int32 startIndex, Int32 length) +13025523 CMS.PortalEngine.PageInfoProvider.GetDataForPageInfoForUrl(String url, String cultureCode, String defaultAliasPath, Boolean combineWithDefaultCulture, Boolean isDocumentPage, GeneralConnection conn, PageInfoSource& source, String& wildcardQueryString) +456 CMS.PortalEngine.PageInfoProvider.GetPageInfoForUrl(String url, String cultureCode, String defaultAliasPath, Boolean combineWithDefaultCulture, Boolean isDocumentPage, GeneralConnection conn, PageInfoSource& source, String& wildcardQueryString, String siteName) +502 CMS.PortalEngine.PageInfoProvider.GetPageInfoForUrl(String url, String cultureCode, String defaultAliasPath, Boolean combineWithDefaultCulture, Boolean isDocumentPage, GeneralConnection conn, PageInfoSource& source, String& wildcardQueryString) +46 CMS.URLRewritingEngine.URLRewriter.RewriteUrl(String relativePath, ExcludedSystemEnum excludedEnum, SiteNameOnDemand siteName, ViewModeOnDemand viewMode) +4592 Global.RewriteUrl(String relativePath, ExcludedSystemEnum excludedEnum, ViewModeOnDemand viewMode, SiteNameOnDemand siteName) in f:\hostingspaces\oryxcom1\oes.com.qa\wwwroot\App_Code\Global.asax.cs:508 Global.Application_AuthorizeRequest(Object sender, EventArgs e) in f:\hostingspaces\oryxcom1\oes.com.qa\wwwroot\App_Code\Global.asax.cs:301 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +71

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0

Recent Answers


Dmitry Bastron answered on May 17, 2019 10:47

Hi,

In the code example given you've got RewriteURL method commented whereas in the stack trace of the error it is active.

Could you double check the active code of Global.asax.cs and paste it to some resource like Pastebin rather than copying here?

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on May 17, 2019 10:52

first off... you shouldn't expose this much information on you production site!

add a custom errors block in your web.config

    <customErrors defaultRedirect="yourErrorPage.html" mode="RemoteOnly">

About the error itself:

  • Does your site work locally?
  • are you sure you have copied all files?
  • did you make any customizations to the global.asax.cs?
1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.