Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC UrlHelper.GenerateUrl exception: "Cannot use a leading .. to exit above the top directory"
    text
    copied!<p>I am using the IIS 7 Rewrite module to rewrite an incoming url like:</p> <p><a href="http://server/year/all" rel="noreferrer">http://server/year/all</a></p> <p>to</p> <p><a href="http://server/application/controller/year/all" rel="noreferrer">http://server/application/controller/year/all</a></p> <p>Everything works fine, except when, while processing the rewritten request, I use MVC's UrlHelper.GenerateUrl() method:</p> <pre><code>UrlHelper.GenerateUrl( "Assets", "Css", "Asset", new RouteValueDictionary(new { site = site.Name, assetPath = assetPath }), RouteTable.Routes, controllerContext.RequestContext, false); </code></pre> <p>Calling this method results in an HttpException: </p> <pre><code>System.Web.HttpException: Cannot use a leading .. to exit above the top directory. at System.Web.Util.UrlPath.ReduceVirtualPath(String path) at System.Web.Util.UrlPath.Reduce(String path) at System.Web.VirtualPath.Combine(VirtualPath relativePath) at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath) at System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) at System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath) at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues) </code></pre> <p>Looking at the RequestContext, it seems that all of the request paths are correct (ie, have the rewritten values). I can't seem to figure out why it's trying to exit out of the top level directory... There's nowhere we are using .... in a path.</p> <p>I've also made sure the RewriteModule is in above the UrlRouting module in IIS.</p> <p>While I can step into the framework methods, I can't examine any of the local variables (either in VS or WinDbg) because it's been compiler optimized.</p> <p>Any thoughts? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload