Cannot use a leading ../ to exit above the top directory

前端 未结 10 801
小蘑菇
小蘑菇 2020-11-30 08:37

I have a asp.net web site with it we have admin area with login page for admin only and all site is allowed for all - i need to ask how to define the right security configur

相关标签:
10条回答
  • 2020-11-30 08:58

    I know these answers are enough, but I'll show the place that's throwing an error.

    If you have the structure like the below:

    • ./Src/Master.cs - (Master Form Page)
    • ./Invoice/SubFolder/InvoiceEdit.aspx - (Sub Form Page)

    If you enter the sub form page, you'll get an error when you use similar like that you've used in master page: Page.ResolveClientUrl("~/Style/img/logo_small.png").

    Now ResolveClientUrl is situated in the master page and trying to serve the root folder. But since you are in the subfolder, the function returns something like ../../Style/img/logo_small.png. This is the wrong way.

    Because when you're up two levels, you are not in the right place; you need to go up only one level, so something like ../.

    0 讨论(0)
  • 2020-11-30 09:02

    You have an image or a favicon link of the style ="../" somewhere, that if the "../" were valid, would go beyond the top of the site, like this:

    Image:

    http://example.com/Images/test.jpg
    

    Page

    http://example.com/Pages/test.aspx
    

    Valid on that page: ../Images/test.jpg
    Would throw an error: ../../Images/test.jpg

    0 讨论(0)
  • 2020-11-30 09:02

    It means that one of the paths has a ".." at the beginning of it that would result in exiting the web site's root folder hierarchy. You need to google "asp.net relative paths" or something like that to help you with your problem.

    BTW, a hint to where the problem is is included in the exception page that you saw. It will actually tell you what file it found the problem in.

    To head off future occurences of this exception, do a search in the entire solution for this string: "../". If you find any of those in files in the root path of your web site, address them.

    0 讨论(0)
  • 2020-11-30 09:04

    You can use ~/img/myImage.png instead of ../img/myImage.png to avoid this error in ASP.NET pages.

    0 讨论(0)
提交回复
热议问题