How to Hide web application code from users in ASP.NET

April 04, 2015 0 Comments

If we talk about web application projects then we simply says that each presentation page attach with code behind page(where you can design your business logic code). If you are a developer and you want to sell your project without code then you will hide its business logic code behind the ".DLL" (dynamic link library) file.
There are available some steps to do this task.
These are
  1. Create a web application project (file--new project--Visual C# --Web -- ASP.NET web Form application)
  2. Write project name, which you want, In this article we take "hide code" as a project name.
new web project in

3. Delete all directories from the solution explorer. Because i want to design only business logic code, after coding we will create DLL file for this. For this you should attach a class file in this project. Take a look after deleted all files from solution explorer.

deleted all files from solution explorer.

4.  Now, we learn how to attach a class file in the project. Select "add new item" from context menu by right clicking on project name.
Select "add new item"

Now, here appear a new window. In this window select code in left panel and also select class in the right panel.
 select code in left panel and also select class in the right panel.

5.  Write the business logic code for display message on the screen, so we raise a button handler code in displayResult class.
You can design your code for multiple classes through this approach we will create a business logic model. Suppose i want to create a small application for employee, in which i want to display data of employee also display employee salary. Application hold two function first for employee data and second for employee salary. Similarly through this code i want to display "Hello World!" message on the browser. Now your code look like
business logic model

In the above mentioned snap displayResult class inherits from page class, page class contains some object like response,request etc. if you want to use page objects then created class must be inherits from Page class. Also mentioned two namespace, first is System.Web.UI and other is System.Web.UI.WebControls.
6.  Build the solution by selecting "Build HideCode" from Build Tab.
Build the solution by selecting "Build HideCode"

Now your .DLL file has made in Bin folder of the project. File contains single namespace(HideCode) , class(displayResult) and single method(displayresult( )).
7. Now add new project in the solution by right clicking on solution name. Select ASP.NET Web form application project in appeared window also write name of the project, i keep presentation part as a project name. Now your solution explorer contains two project, see below
solution explorer contains two project

8.  Now add new web form in the project also change the name of it, i keep  "presentationpage.aspx" as a project name. This page is basically used for designing purpose. Through this page we can call method of other projects, but will do some changes in the page . Before doing this, first of all add above mentioned project reference in the current project. Learn how to add reference in the project.
Note : Remove all attached file from this page.
 Remove all attached file from this page

(a) Add Reference by right click on References link. select Solution from the appeared window also select .dll checkbox which is appeared in right panel of it.
select .dll checkbox which is appeared in right panel

9. Remove "CodeBehind" attribute from presentation page also add inherits attribute in the page directive. Assign namespace , which is created in earlier project  with class name. Look like
 Remove "CodeBehind" attribute

10. Add button in the page also raise onclick event on it. Call displayresult( ) method, which is created in business logic code. now your code look like
<%@ Page Language="C#" AutoEventWireup="true" Inherits="HideCode.displayResult" %>

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="hide coding" OnClick ="displayresult" />

Now your code generate the following output

How to Hide web application code from users in ASP.NET

First code of line define the page directive. In this line,you must to add namespace with class name in inherits attribute. After that you can access methods and properties of that class. In this code i also access method of displayResult class using Button click event.

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google