Search code examples
c#asp.netcode-behind

How to set code-behind path after moving an .aspx file to a new folder?


I have an Employee.aspx page. First it was in a folder named Master. Now I moved it to Employee folder.

When I run the project it shows me the old path (Master/Employee.aspx) path and throws an error

The resource cannot be found( /Master/Employee.aspx).

How can I fix this issue?. If edit the path to use Employee it runs

http://localhost:49874/Master/Employee.aspx 

My old path it not showing Employee in place of Master

<%@ Page Title="" Language="C#" MasterPageFile="~/Home.Master" AutoEventWireup="true" CodeBehind="~/Employee/Employee.aspx.cs" Inherits="Manjilas.WebForm119" %>

Solution

  • Physically moving ASPX/ASCX files is not enough for them to work again. You need to also update the corresponding file's page/control directive.

    You have to change the CodeBehind value of the @Page directive to reflect the new path.

    Your ASPX page probably has something like this:

    <%@Page CodeBehind="~/Master/Employee.aspx.cs" ... %>
    

    It should become

    <%@Page CodeBehind="~/Employee/Employee.aspx.cs" ... %>
    

    Also, the URL you use to access the page will also change from:

    http://localhost:49874/Master/Employee.aspx 
    

    to

    http://localhost:49874/Employee/Employee.aspx 
    

    A side note: It is possible for odd compilation errors to persist after changing the .Net version if the Temporary ASP.NET files did not get refreshed. You can fix this by manually emptying the directory:

    %WINDIR%\Mircosoft.NET\Framework\${version}\Temporary ASP.NET Files\
    

    change the ${version} to your current .NET framework version that IIS uses. (If you use .NET 3.5 or 3.0, then the ${version} should be 2.0...)