Lost back end files of a web page

Christopher Dietzel 0 Reputation points
2024-02-07T19:35:50.5666667+00:00

I recently create a project in C+. I published this code to our web server. The web page works fine. But i accidently deleted all the code for this website. I know i can go on our web server and get the front end code to copy and recreate my website, but i am not able to see the back end files like .aspx and .css etc. Is there a way to find all that code so i dont have to try and re create the project from scratch? Thank you

Developer technologies | Visual Studio | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,331 Reputation points
    2024-02-07T20:56:57.5166667+00:00

    Can it be done? Yes. Is it easy? No. This is why you should always ensure you are using source control.

    The CSS file is a content file so that is on your web server along with any other content files like images, JS files, etc.

    You mentioned ASPX so that means you're using web forms. The ASPX files are also deployed on the web server directly as well so you should be able to get them.

    What you won't have is the aspx.cs files that contain the codebehind written in C# and any custom .cs files you had. Assuming you are building a traditional web forms app then all that code got compiled into a DLL when you built your code. The only way to get that code back is to decompile the DLL.

    Get a decompiler for .NET. JustDecompile is old but works well. There is also ildasm from MS but I never really liked that tool. CodemerxDecompile is a newer tool and doesn't work quite right for me but it could also be used. Irrelevant have the decompiler decompile your web app's DLL to get to the code. Then comes the fun part.

    There will be no project file so create a new web project using the same name as what you used before. This gives you the basic structure that the project needs to be in. You will be either adding to this project or replacing the existing files as you go along to match what you had before.

    • For each aspx file create a corresponding .aspx.cs file. In the decompiled code find the class that was generated for the .aspx page and put it into the class. Depending on your decompiler you may need to adjust the code to actually compile.
    • For any code unrelated to pages you'll need to create additional .cs files to store them. For example if you have a User class then create a User.cs file and copy the class into there.
    • Most likely you had a Globals.asax.cs file that contained the global app startup logic. You'll need to create/update that file and put the app startup code there.
    • If you had custom handlers (.ashx) or controls (.ascx) then you'll need to do the same sort of thing there.
    • Copy all your content files into the new project as well. Most likely you were relying on NuGet packages so some of those files may already be there.
    • The web.config file would have been copied to the web server as well so you can grab that file and put it into your project. Note that it may not quite line up with what your project is expecting because of NuGet packages and whatnot so you might need to adjust your project settings and packages to match what was actually deployed.

    After that it is a matter of compiling and fixing things that don't line up.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.