Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> C# >> Encode and Decode in .Net
Encode and Decode in .Net

Concept related to encode,decode,UrlEncode and UrlDecode in ASP.Net
Views: 2123     Comments: 0
by Amit Singh on 11/12/2010
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. However, 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 to another.
·  Access the URL or pass the URL.
·  Fetch the data or insert data in Database.
·  Read the xml data or insert data in xml.
·  Change the special character from string
·  And security purpose etc.

In ASP.Net we used the following encode and decode method are
·  Server.HtmlEncode()
·  Server.HtmlDecode()
·  Server.HtmlUrlEncode()
·  Server.HtmlUrlDecode ()
·  HttpUtility.UrlEncode()
·  HttpUtility.UrlDecode ()

Example1:
string strData="?data??"
Response.Write(Server.HtmlEncode(strData)); //Encode the value here

Example2:
string strUrl=Request.Url.ToString();//Request.Url get the url
Response.Write("<font color='green'>URL is:</font> " + strUrl +"<br/>");
Response.Write("<font color='green'>Encoded URL is: </font>" + HttpUtility.UrlEncode(strUrl));//Encoded Url Here

Output:
URL is: http://localhost:49714/WebSite8/Default.aspx
Encoded URl is: http%3a%2f%2flocalhost%3a49714%2fWebSite8%2fDefault.aspx

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Amit SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 3416
  
Copyright © 2013MindStick. All Rights Reserved.