Category: components

MVC 5 encrypt parameters


This is an old idea that I was having. The problem was that , for many people, showing the parameters in MVC is not something that they want . For example. suppose that we have this action


public ActionResult TestEncrypt(int id, int a, string b)


The this action can be activated by putting in the Razor cshtml file this


<a href=’@Url.Action("TestEncrypt", new { id=7, a = 1, b = "asd" })’>Test</a>


that will generate this URL : .

The parameters are passed in clear text ( a is 1 and b is asd). What if I want to encrypt those into the URL ,


but receive in the Action the default values ( 1 and asd)?

Enter MVC5Encrypt

What you have to do is modify slightly the code in the .cshtml and add an attribute to the Action


<a href=’@Url.ActionEnc("mySecret", "TestEncrypt", new { id=7, a = 1, b = "asd" })’>Test</a>


and the action will be

[MVCDecryptFilter(secret = &quot;mySecret&quot;)]   
public ActionResult TestEncrypt(int id, int a, string b)


You can see into action at



1.  What is “mysecret”?

See code on that I shameless copied.


2. What about backward compatibility ( i.e., old links will function ) ?

Yes if you do not already encode in base64 ( default class encrypter knows if the parameter value is in base64 ) . See 


3. What about extending this with a custom encrypt class ?

You can – see this function


public static string ActionEnc(this UrlHelper helper, IEncryptDecrypt encDec, string actionName, object routeValues)


4. What about extending this to route parameters ( e.g. http://localhost/Person/Edit/5  – the 5 parameter is in the route and not encrypted ) ?

Glad you ask. Please fill an feature request on github

5. More details ? 

Sources on GitHub :

Demo at 

NuGet at

( Other solution is to use

.tt files to maintain assembly version in sync

Let’s suppose you have a medium-big application and you have several dll-assemblies-component that the main application references( DAL, BLL). You have several deployments of the application at clients and , when a client , you must find each version of each assembly deployed.

I have developed a simple .tt file to  ensure that every component that you compile have the same version – you can run on the server on the automatic build( or by hand.

More, with this .tt file you can

    1. Have the date /time ( with minute) of the compile of the dll embedded into version information
    2. Read a text file and add same copyright to all projects( left as an exercise to the user) .


You can see the demo at .

You can download the project at