Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy an ASP.NET project so that there is no code in the .aspx files?

I've recently become the maintainer of an ASP.NET web project. In the course of deploying some changes, we noticed that at some point the way the project deploys has changed. The project is a web application project. Currently, when I "Publish" it to my local machine, I can open the various .aspx files and see some code--a little ASP, mostly JavaScript, but the majority of the code seems to be compiled into a .dll.

What we would like is to build and deploy this application so that there is no code in the .aspx files--this is how it used to work, before the previous dev stopped maintaining it. There should be no code in the .aspx files at all, just a reference to the compiled .dll files.

Does anyone know what I'm talking about and how to set it up?

EDIT If it helps, it looks like the older version of the app just had text in the .aspx files that said "This is a marker file generated by the precompilation tool, and should not be deleted!" That is what I'm going for.

like image 548
SuperNES Avatar asked Mar 15 '11 20:03

SuperNES


People also ask

What are the different types of ASP NET deployment?

ASP.NET - Deployment. There are two categories of ASP.NET deployment: Local deployment : In this case, the entire application is contained within a virtual directory and all the contents and assemblies are contained within it and available to the application.

How to deploy ASP NET Core to IIs?

Steps to Deploy ASP.NET Core to IIS Step 1: Publish to a File Folder. Step 2: Copy Files to Preferred IIS Location. Now you need to copy your publish output to where you want the files to... Step 3: Create Application in IIS. First, create a new IIS Application Pool. You will want to create one ...

How to achieve no code in an ASP NET page?

In order to achieve no code in the .aspx files you need to write all the code in the code behind. You use the asp.net events in the life cycle to perform the generation of client code. For example, dynamically generated HTML and javascript could be generated in the Page_Load and written out as a Response.

How do I deploy to IIS using Visual Studio?

There are several ways you can deploy to IIS using Visual Studio and Web Deploy: Use Visual Studio one-click publish. Publish from the command line. Create a deployment package and install it using IIS Manager. Create a deployment package and install it using the command line.


2 Answers

If you want to do this for your Website just Pre-compile your project for deployment only. You can check out the exact steps in this MSDN article

This will move all the codebehind files into the .dll and create .aspx.compiled files as pointers to the compiled versions in the .dll. Sounds like thats what was being done before.

like image 177
Tj Kellie Avatar answered Sep 28 '22 04:09

Tj Kellie


The code shouldn't be visible from the client's browser.

Any code that in a code-behind will get compiled to a .dll which the pages in the application would reference. The actual code-behind files shouldn't get published with the .aspx files.

.NET code within the .aspx files shouldn't be visible on the client-side because it has no use on the client-side. It should be executed on the server-side to render HTML output to the client. If the .NET code is visible on the client-side in this case, it means the server isn't executing it and the site is essentially broken.

JavaScript code, of course, needs to be visible on the client-side. There are ways to obfuscate it, but the browser needs to see it in order to execute it. So in this case that code should be developed with the full understanding that it is publicly visible and nothing proprietary or compromising should be included in it.

like image 33
David Avatar answered Sep 28 '22 06:09

David