startIndex cannot be less than zero

Topics: Business Logic Layer
Jun 22, 2011 at 3:27 PM

I have just done a fresh install of BlogEngine.net 2.5 RC. I seem to be missing something in the configuration though because whenever I navigate to the root of the site (http://www.domain.com/) or any base directory (http://www.domain.com/account/) I receive the following error:

[ArgumentOutOfRangeException: StartIndex cannot be less than zero.
Parameter name: startIndex]
   System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +9389059
   BlogEngine.Core.Web.HttpModules.UrlRewrite.RewriteDefault(HttpContext context) in E:\Projects\BlogEngine-25-A\BlogEngine\DotNetSlave.BusinessLogic\Web\HttpModules\UrlRewrite.cs:239
   BlogEngine.Core.Web.HttpModules.UrlRewrite.ContextBeginRequest(Object sender, EventArgs e) in E:\Projects\BlogEngine-25-A\BlogEngine\DotNetSlave.BusinessLogic\Web\HttpModules\UrlRewrite.cs:348
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

If I add default.aspx (or any other existing page name) to the url it works fine (e.g. http://www.domain.com/default.aspx). Commenting out the URLRewrite http handler in the web.config file gets around this problem, but then prevents pages from working correctly (and I'm sure other things).

Has anyone else seen this behaviour and have some pointers of what I may be missing?

Thanks,

Dana

Jun 22, 2011 at 4:09 PM

I have the exact same problem. 

Coordinator
Jun 22, 2011 at 6:47 PM

What "default documents" do you have setup for your website?  With the out-of-the-box IIS default documents, navigating to http://www.domain.com/account/ for example should return a 403.14 - Forbidden "The Web server is configured to not list the contents of this directory." because there is not a default document in the /account/ folder.  Typically a link going into the /account/ directory would link directly to /account/login.aspx.

It appears on your site, the request to /account/ is being resolved to some .ASPX page.  On the error message you get, are there additional details you did not paste here?  For example, oftentimes the .NET error at the bottom might include the URL it was on when the error occurred.  You might find that the URL in the error message appears with some document name at the end ... e.g. http://www.domain.com/account/something.aspx.

Having said this, it would probably be good to have this particular piece of code fixed so it doesn't have this error.  Right now, it's making an incorrect assumption that your URL contains "default.aspx" (the "normal" default document) when it does not.

Thanks for bringing this up.  In the meantime, I would check your Default Documents.   The ones I have for example are:  Default.htm, Default.asp, index.htm, index.html, iisstart.htm, default.aspx.

Coordinator
Jun 22, 2011 at 7:05 PM

I did put in a fix (2.5.0.1) so it should not have that error.  If you'd like, you can download the updated BIN file folders here, and overwrite your existing BlogEngine.Core files with the ones in the ZIP.

Although this should avoid this particular error, as I mentioned above, at least in the /account/ example, that one would typically requires the URL to be /account/login.aspx unless you make login.aspx one of your default documents.

Jun 22, 2011 at 7:33 PM

Thanks Ben. I will give the fix a try and let you know if it resolves the problem. Sorry, I just chose the /account/ example out of the air, and realize now I should have been more clear. Basically the any URL without a filename was having an issue. My default documents are set as you have indicated, with the default being default.aspx.

Jun 22, 2011 at 8:07 PM

The updated bin solved my problem.  Thanks! 

Jun 22, 2011 at 8:59 PM

Yes, it did resolve the problem I was having as well. Thanks again Ben.

Jun 23, 2011 at 8:43 PM

This did not solve problem.  I still get 

Server Error in '/' Application.

StartIndex cannot be less than zero.
Parameter name: startIndex

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: StartIndex cannot be less than zero.
Parameter name: startIndex

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[ArgumentOutOfRangeException: StartIndex cannot be less than zero.
Parameter name: startIndex]
   System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +9389059
   BlogEngine.Core.Web.HttpModules.UrlRewrite.RewriteDefault(HttpContext context) in E:\Projects\BlogEngine-25-A\BlogEngine\DotNetSlave.BusinessLogic\Web\HttpModules\UrlRewrite.cs:239
   BlogEngine.Core.Web.HttpModules.UrlRewrite.ContextBeginRequest(Object sender, EventArgs e) in E:\Projects\BlogEngine-25-A\BlogEngine\DotNetSlave.BusinessLogic\Web\HttpModules\UrlRewrite.cs:348
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75



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

Jun 23, 2011 at 9:18 PM

It does appear to be the same problem. Are you sure that you updated the BlogEngine.Core files in the bin directory with the ones that Ben provided? If you browse to /default.aspx does your site theme show the BlogEngine.net version number? If so, what version number does it show. It should be 2.5.0.1.

Dana

Coordinator
Jun 23, 2011 at 10:20 PM

As Dana suggested, I would double check the version number.  If you're using the Standard theme, the version number should appear at the bottom of the page, or you can go into the control panel and the BE version number will appear at the bottom there as well.  If you see 2.5.0.1, then you are using the new version, if you see 2.5.0.0, then you are using the old version.

That error should not occur with the new 2.5.0.1 version.  If the error is occurring for 2.5.0.1, then we would want to fix it of course, but the 2.5.0.1 fix should have eliminated this error.

Jun 24, 2011 at 3:50 AM

ok, explain to me which folder it goes in...I put it in /BlogEngine.NET 2.5 RC (source)\BlogEngine\DotNetSlave.BusinessLogic\bin\Release and I put it in /BlogEngine.NET 2.5 RC (source)\BlogEngine\BlogEngine.NET\Bin and it still tells me 2.5.0.0

Coordinator
Jun 24, 2011 at 6:18 AM

First, you'll want to make sure you unzip the ZIP.  There are 3 files in there.  The files need to go in the 2nd path you mentioned -- /BlogEngine.NET 2.5 RC (source)\BlogEngine\BlogEngine.NET\Bin.

I see you are working off of the source version.  If you are running this within Visual Studio, it's possible the BlogEngine.Core.dll file from the "BE Core" (DotNetSlave.BusinessLogic) is recompiling and overwriting the BlogEngine.Core.dll file you put in your BIN folder.

If you have Visual Studio, you might want to get the latest Source Code version from the Source Code tab above and use that instead of using the 2.5 RC you downloaded and the replacement BIN folder files in my ZIP.

You could also test by temporarily removing the BlogEngine.Core.dll file from the BIN folder.  The site should not run correctly in that case.  If you can get that to happen, you'll know you found the right BIN directory.

Jun 24, 2011 at 10:24 AM
BenAmada wrote:

I did put in a fix (2.5.0.1) so it should not have that error.  If you'd like, you can download the updated BIN file folders here, and overwrite your existing BlogEngine.Core files with the ones in the ZIP.

Although this should avoid this particular error, as I mentioned above, at least in the /account/ example, that one would typically requires the URL to be /account/login.aspx unless you make login.aspx one of your default documents.


Thank you! I had the same problem in (2.5.0.0), the BIN folder files fixed it for me :)!

Jun 19, 2014 at 5:26 PM
This issue seems to be back for me in version 2.8
StartIndex cannot be less than zero. Parameter name: startIndex

Source File: c:\Users\jack\Documents\DevProjects\BikeReligion 2.8\MarketingPlatform\BlogEngine\BlogEngine.Core\Web\UrlRules.cs    Line: 346 

[ArgumentOutOfRangeException: StartIndex cannot be less than zero.
Parameter name: startIndex]
   System.String.Substring(Int32 startIndex, Int32 length) +10993299
   System.String.Substring(Int32 startIndex) +10
   BlogEngine.Core.Web.UrlRules.RewriteDefault(HttpContext context) in c:\Users\jack\Documents\DevProjects\BikeReligion 2.8\MarketingPlatform\BlogEngine\BlogEngine.Core\Web\UrlRules.cs:346
   BlogEngine.Core.Web.HttpModules.UrlRewrite.Rewrite(HttpContext context, Blog blogInstance, String url, String path) in c:\Users\jack\Documents\DevProjects\BikeReligion 2.8\MarketingPlatform\BlogEngine\BlogEngine.Core\Web\HttpModules\UrlRewrite.cs:173
   BlogEngine.Core.Web.HttpModules.UrlRewrite.ContextBeginRequest(Object sender, EventArgs e) in c:\Users\jack\Documents\DevProjects\BikeReligion 2.8\MarketingPlatform\BlogEngine\BlogEngine.Core\Web\HttpModules\UrlRewrite.cs:85
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69


Line 344:                string newUrl = url.Replace("Default.aspx", "default.aspx");  // fixes a casing oddity on Mono
Line 345:                int defaultStart = url.IndexOf("default.aspx", StringComparison.OrdinalIgnoreCase);
Line 346:                url = Utils.ApplicationRelativeWebRoot + url.Substring(defaultStart);
Line 347:            }
Line 348: