Click here to Skip to main content
15,889,315 members
Articles / Web Development / ASP.NET

Code encryption in MVC2

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
11 Nov 2013CPOL1 min read 17K   3   4
Code encryption in MVC 2.

Introduction

It's been on my mind that, to encrypt all the major code of my MVC project. Last night I did it. Now it’s time to share it with you. Let’s start.

Step 01. Create a new ASP.NET mvc2 project and named it TestProject.

Step 02. Now you need to create a class library project. For that,  select File > Add > New Project. Add New Project window will appear. Select Class Library as project type and named the project as Test.EncryptCode. Solution Explorer window will be like as below picture.

01

Delete the Class1.cs file from Test.EncryptCode project.

Step 03. Now add all the references to Test.EncryptCode project, those references are exist in TestProject project.

Step 04. Select the AccountModels.cs file from TestProject > Models. Drag that file to Test.EncryptCode project. Delete the AccountModels.cs file from TestProject project.  Now Solution Explorer window will be like as below picture.

02

Step 04. Now change the AccountsModels namespace as Test.EncryptCode. It will look like below picture.

03

Now build the Test.EncryptCode project. Add the Test.EncryptCode project as reference into TestProject project. We can add it by using project > add reference menu. A Reference window will appear and select the Test.EncryptCode from project tab

04

Open AccountController.cs file and change the TestProject.Models namespace to Test.EncryptCode.

Now open the ChangePassword.aspx, LogOn.aspx and Register.aspx file. just change the TestProject.Models to Test.EncryptCode in inherits property. The code will be like as below.

ChangePassword.aspx

ASP.NET
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
   Inherits="System.Web.Mvc.ViewPage<Test.EncryptCode.ChangePasswordModel>" %>

Register.aspx

ASP.NET
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
   Inherits="System.Web.Mvc.ViewPage<Test.EncryptCode.RegisterModel>" %>

LogOn.aspx

ASP.NET
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
    Inherits="System.Web.Mvc.ViewPage<Test.EncryptCode.LogOnModel>" %>

Now run the project and see it works!

This article was originally posted at http://www.crea8ivecode.net/weblog?p=74

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Codexplorer Technologies
Bangladesh Bangladesh
I am:
Founder & Technical Head at Codexplorer Technologies.
IT Consultant at Meridian Group.

I was:
Manager (IT) at Meridian Group.
Assistant Manager (Software Division) at KDS Garment Industries Limited.
Assistant Manager (Software Division) at E-Vision Software Limited.

My blog:
crea8ivecode

My preferred work area:
ASP.NET & SQL SERVER.

My email:
sadeque.sharif@yahoo.com

Follow me:
twitter | facebook | linkedin

Comments and Discussions

 
Question@RenderBody() & @RenderSection Methods is ASP.NET MVC4 Pin
Member 1179982929-Jun-15 0:16
Member 1179982929-Jun-15 0:16 
AnswerRe: @RenderBody() & @RenderSection Methods is ASP.NET MVC4 Pin
Sadeque Sharif29-Jun-15 22:04
professionalSadeque Sharif29-Jun-15 22:04 
GeneralMy vote of 1 Pin
R. Harris18-Nov-13 15:16
R. Harris18-Nov-13 15:16 
QuestionEncryption? Pin
gore0111-Nov-13 4:13
gore0111-Nov-13 4:13 
What is the real meaning of the "code encryption" in the context of this article? I think that it's not the encryption any way. You just extracted the models from the main into the separate assembly.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.