---
title: "Encode - Decode in ASP.NET"  
description: "Html Encode method encodes a particular string to be displayed in a browser. It is important to encode strings prior it’s rendering in the page, mainl"  
author: "Uttam Misra"  
published: 2010-12-22  
updated: 2026-05-12  
canonical: https://www.mindstick.com/blog/80/encode-decode-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# Encode - Decode in ASP.NET

Html Encode method encodes a particular string to be displayed in a browser. It is important to encode strings prior it’s rendering in the page, mainly to avoid cross-site script injection (XSS) and HTML [injection attacks](https://www.mindstick.com/forum/160895/protect-sql-server-database-against-sql-injection-attacks). However, [developers](https://www.mindstick.com/blog/302688/handling-errors-in-rust-a-comprehensive-guide-for-developers) so often forget to call the encode function.

Html Decode method decodes a particular string which is encoded.

Encoding and decoding is needed in somewhere like

· Pass the values from [one page](https://www.mindstick.com/forum/118/problem-in-display-content-of-one-page-to-another-page) to another.

· Access the URL or pass the URL.

· Fetch the data or [insert data in Database](https://www.mindstick.com/forum/33723/insert-data-in-database-using-windows-application-c-sharp).

· Read the [xml data](https://www.mindstick.com/forum/149/problem-in-showing-the-xml-data-in-table-form-on-browser) or insert data in xml.

· Change the [special character](https://www.mindstick.com/forum/119/special-character-remove-from-url-or-any-string) from string

· And security purpose etc.

In ASP.Net we used the following [encode and decode](https://www.mindstick.com/forum/159053/how-do-i-encode-and-decode-a-base64-string-in-c-sharp) method:

· Server.HtmlEncode()

· Server.HtmlDecode()

· Server.HtmlUrlEncode()

· Server.HtmlUrlDecode ()

· HttpUtility.UrlEncode()

· HttpUtility.UrlDecode ()

Check details here:

http://www.mindstick.com/Articles/b3d1fb4c-f386-49af-a464-fc96467eb957/?Encoding%20and%20Decoding%20in%20ASP%20Net

---

Original Source: https://www.mindstick.com/blog/80/encode-decode-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
