In this post I am explain how to encrypt query string in ASP.NET
We know that ASP.NET Web application is State less because HTTP is State less.
So, If you want your application redirects from one ASP.NET Web page to another, you will not get any information from your previous page.
To overcome this there are some technique in asp.net to pass information form one page to another and most popular of them is Query String.
But if we pass information in query string and our information is related to out database id then
for security reasons, we should not pass direct and clear information in your URL query strings.
So we need to hide this information by encrypting the URL query strings.
We can do this by following this below steps. Here I create a project, that show list of products with link to show product details. Here pass product id (encrypted) as query string.
Steps :
Just follow the steps and get result easily.
Step-1 : Create New Project
Go to File > New > Project > Select asp.net web forms application > Entry Application Name > Click OK.
Step-2: Add a Database.
Go to Solution Explorer > Right Click on App_Data folder > Add > New item > Select SQL Server Database Under Data > Enter Database name > Add.
Step-3: Create a table and insert data.
Open Database > Right Click on Table > Add New Table > Add Columns > Save > Enter table name > Ok.
Step-4: Add Entity Data Model.
Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add.
A popup window will come (Entity Data Model Wizard) > Select Generate from database > Next >
Chose your data connection > select your database > next > Select tables > enter Model Namespace > Finish.
Step-5: Add a Class for encryption / decrypt Query string.
Go to Solution Explorer > Right Click on Project under solution explorer > Add > New item > Select Class under Code > Enter Name > Add.
Hello ! My name is Sourav Mondal. I am a software developer working in Microsoft .NET technologies since 2010.
I like to share my working experience, research and knowledge through my site.
I love developing applications in Microsoft Technologies including Asp.Net webforms, mvc, winforms, c#.net, sql server, entity framework, Ajax, Jquery, web api, web service and more.
Get latest article about asp.net, mvc, jquery, web api, angularjs and much more straight into your INBOX for free. Just Enter your email address, Verify and join our Newsletter!