If you get this error: "Cannot use a leading .. to exit above the top directory." here is how to solve it in one specific case:
1) If you had a User Control and you moved it to Custom Control into the Library project and are now trying to use it on the website
2) your control is looking for a specific querystring, if not found it needs to send the user to some other page of the website
3) all this is done in the Custom control
4) you are getting this error: "Cannot use a leading .. to exit above the top directory."
5) you perform the redirect with Server.Transfer
You might want to change Server.Transfer to Response.Redirect...it should work.
I am sure this is resolved by now but still here are some more.... issues
The folder is C:\inetpub\wwroot and hosted in IIS as
Default Web Site
Had pqrst.aspx inside folder
ABC and a button calls server.transfer() with link as "~/abcd.aspx" this is when I get the error.
But it works if both abcd.aspx and pqrst.aspx are on the root.
Again... without any changes it also works if it is hosted on a new virtual directory inside
Default Web Site in a new physical folder inside
\wwroot or outside or anywhere.
Any technical explanation still.... I still have .NET 2.0 on Win Server 2003 Std Edition with SP2, will an update solve this issue?
I have changes my code and used Server.Transfer in place of Response.Redirect ... But As i have use Grid View in that page and have few event on it :( So still giving me the same problem :(
So I again start searching help and i come accross ur solution about ... But in that point
The only problem with using Response.Redirect is that for url rewritten pages like a product page you want to issue a 404 if the product does not exist. The problem with Response.Redirect is that it works by issuing a 302 therefore the product page does
not get removed from search engines. This is the workaround I've come up with:
Basically if you use the rewrite path method above you no longer get the error, unfortunately the paths to your css files and images (all ~ references) will be wrong so we add the html base element to fix it.
I received the same error while attempting to access my admin pages in a project that uses the
SubSonic CMS. Turns out, I had a js file linked from my MasterPage without a leading .. or ~ at all. Imagine my suprise, it wasn't the inclusion of an unnecessary ".." that caused the error,
but a lack of one. For those of you using SubSonic CMS who are experiencing this problem, check the bottom of your site.master for this line:
AspForumTany...
Member
207 Points
113 Posts
"Cannot use a leading .. to exit above the top directory."
Nov 14, 2007 04:35 PM|LINK
Hi All,
If you get this error: "Cannot use a leading .. to exit above the top directory." here is how to solve it in one specific case:
1) If you had a User Control and you moved it to Custom Control into the Library project and are now trying to use it on the website
2) your control is looking for a specific querystring, if not found it needs to send the user to some other page of the website
3) all this is done in the Custom control
4) you are getting this error: "Cannot use a leading .. to exit above the top directory."
5) you perform the redirect with Server.Transfer
You might want to change Server.Transfer to Response.Redirect...it should work.
Also you might want to do some reading here:
1) About Server Transfer: http://msdn2.microsoft.com/en-us/library/caxa892w.aspx
2) About resolving the issue with CSS and other http://jaredprins.com/blog/?page_id=71
3) Could also happen during URL rewrite: http://forums.asp.net/t/1019849.aspx + I added my case there too just in case somebody will be looking there...
4) And finally some tech support on this (also related to CSS): http://www.telerik.com/community/forums/thread/b311D-orJO1.aspx
If anybody has an answer as to why Server.Transfer doesn't work I would be very interested to hear it...
WarrenLong
Member
62 Points
14 Posts
Re: "Cannot use a leading .. to exit above the top directory."
Feb 04, 2009 05:59 PM|LINK
I am sure this is resolved by now but still here are some more.... issues
The folder is C:\inetpub\wwroot and hosted in IIS as Default Web Site
Had pqrst.aspx inside folder ABC and a button calls server.transfer() with link as "~/abcd.aspx" this is when I get the error.
But it works if both abcd.aspx and pqrst.aspx are on the root.
Again... without any changes it also works if it is hosted on a new virtual directory inside Default Web Site in a new physical folder inside \wwroot or outside or anywhere.
Any technical explanation still.... I still have .NET 2.0 on Win Server 2003 Std Edition with SP2, will an update solve this issue?
Ashish Amodi...
Member
17 Points
13 Posts
Re: "Cannot use a leading .. to exit above the top directory."
May 28, 2009 11:15 AM|LINK
Hello madam,
I have changes my code and used Server.Transfer in place of Response.Redirect ... But As i have use Grid View in that page and have few event on it :( So still giving me the same problem :(
So I again start searching help and i come accross ur solution about ... But in that point
4) And finally some tech support on this (also related to CSS): http://www.telerik.com/community/forums/thread/b311D-orJO1.aspx
I have change my css path to
<link href='<%= Page.ResolveUrl("~/Main.css")%>' rel="stylesheet" type="text/css" />
But I loss all my css style :(
And ur Link in point 4 is also not working do u have any advice for me hmmm ??
Waiting with puppy eyes.
Ashish Amodia
amodia.a.s@gmail.com
Thank you
mcm
Member
77 Points
37 Posts
Re: "Cannot use a leading .. to exit above the top directory."
Jul 03, 2009 05:22 AM|LINK
The only problem with using Response.Redirect is that for url rewritten pages like a product page you want to issue a 404 if the product does not exist. The problem with Response.Redirect is that it works by issuing a 302 therefore the product page does not get removed from search engines. This is the workaround I've come up with:
Util.DisplayMessage("The requested product no longer exists.");
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true;
HttpContext.Current.RewritePath("~/categories.aspx");
Server.Transfer("~/categories.aspx");
And then on your Master page:
if (!Request.Url.ToString().ToLower().Contains(Request.RawUrl.ToLower().TrimEnd('?')))
{
string baseurl = System.IO.Path.GetDirectoryName(Request.Url.ToString().Replace('/', '\\')).Replace('\\', '/') + "/";
Page.Header.Controls.AddAt(0, new LiteralControl("<base href='" + baseurl + "' />"));
}
Basically if you use the rewrite path method above you no longer get the error, unfortunately the paths to your css files and images (all ~ references) will be wrong so we add the html base element to fix it.
rabrabber
Member
17 Points
9 Posts
Re: "Cannot use a leading .. to exit above the top directory."
Jul 05, 2009 06:10 PM|LINK
I had the same problem, after little investigation it turned out to be cause by the ImageUrl of a hyperlink !!
I don't know the exact reason, but putting an image inside the hyperlink tags solved my problem.
Hope this helps
rerainc
Member
6 Points
3 Posts
Re: "Cannot use a leading .. to exit above the top directory."
Oct 14, 2009 04:18 PM|LINK
I received the same error while attempting to access my admin pages in a project that uses the SubSonic CMS. Turns out, I had a js file linked from my MasterPage without a leading .. or ~ at all. Imagine my suprise, it wasn't the inclusion of an unnecessary ".." that caused the error, but a lack of one. For those of you using SubSonic CMS who are experiencing this problem, check the bottom of your site.master for this line:
Should do the trick.
matabares
Member
4 Points
2 Posts
Re: "Cannot use a leading .. to exit above the top directory."
May 25, 2011 07:45 PM|LINK
Hi,
this problem the solve
1) this master page have
<link href="../../App_Themes/Tema/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
delete ../..
2)new
<link href="/App_Themes/Tema/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
me found
from colombia - medellin