Error: Cannot use a leading .. to exit above the top directory.

Error: Cannot use a leading .. to exit above the top directory.

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.Web.HttpException: Cannot use a leading .. to exit above the top directory.

Solution:

Check The Master page or any Default Page currently using before error appears.

Make sure that references in the <head> </head> section do not go above directory listings.

simple basic example:

If your page is in the main project:

ERROR:         <link href=”../CSS/help.css” rel=”stylesheet” type=”text/css” />

SOLTION:    <link href=”CSS/help.css” rel=”stylesheet” type=”text/css” /> //Removing the ../ 

                        <link href=”<%= ResolveUrl(“~/”) %>CSS/help.css” rel=”stylesheet” type=”text/css” /> //When using ASP.NET we can resolve the URL when not sure about the path

Error: The Controls collection cannot be modified because the control contains code blocks (i.e. )

Error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).

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.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).

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.

SOLUTION:

Search within the <head> </head> part of your page and look for any content with the following characters “<%” or use ctrl+F to look for them.

Make sure you gather all <% parts and place them in a simple PlaceHolder, no matter if they are placed in style tags, script tags or simple html tags.

Example:

<asp:PlaceHolder runat=”server”>

<script type=”text/javascript” src=”<%# ResolveUrl(“~/scripts/jquery.js”)%>“></script>

<script type=”text/javascript”>

function SearchUser() {

document.getElementById(“<%= txt_search.userID%>“).value = “”;

}

</script>

</asp:PlaceHolder>