using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace HttpUtilityDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            String myString;
            Console.WriteLine("Enter a string having '&' or '\"'  in it: ");
            myString = Console.ReadLine();
            String myEncodedString;
            // Encode the string.
            myEncodedString = HttpUtility.HtmlEncode(myString);
            Console.WriteLine("HTML Encoded string is " + myEncodedString);
            StringWriter myWriter = new StringWriter();
            // Decode the encoded string.
            HttpUtility.HtmlDecode(myEncodedString, myWriter);
            Console.Write("Decoded string of the above encoded string is " +
                           myWriter.ToString());
            Console.Read();
        }
    }

}

MVC HttpUtility.HtmlEncode是如何编码的的更多相关文章

  1. HttpUtility.HtmlDecode ,HttpUtility.HtmlEncode 与 Server.HtmlDecode ,Server.HtmlEncode 与 HttpServerUtility.HtmlDecode , HttpServerUtility.HtmlEncode

    HtmlEncode: 将 Html 源文件中不允许出现的字符进行编码,通常是编码以下字符"<".">"."&" 等. ...

  2. HttpUtility.HtmlEncode

    HttpUtility.HtmlEncode用来防止站点受到恶意脚本注入的攻击 public string Welcome(string name, int numTimes = 1) {     r ...

  3. 利用方法HttpUtility.HtmlEncode来预处理用户输入

    利用方法HttpUtility.HtmlEncode来预处理用户输入.这样能阻止用户用链接注入JavaScript代码或HTML标记,比如//Store/Broswe?Genre=<script ...

  4. 【C#】C#中的HtmlEncode与HtmlDecode:HttpUtility.HtmlEncode,HttpUtility.HtmlDecode,Server.HtmlEncode,Server.HtmlDecode,WebUtility.HtmlEncode,WebUtility.HtmlDecode

    HtmlEncode(String) 将字符串转换为 HTML 编码字符串. HtmlDecode(String) 将已经为 HTTP 传输进行过 HTML 编码的字符串转换为已解码的字符串. 在we ...

  5. Spring mvc 注解@ResponseBody 返回内容编码问题

    @ResponseBody 在@Controller 类方法中能够让字符串直接返回内容. 其返回处理的类是org.springframework.http.converter.StringHttpMe ...

  6. HttpUtility.HtmlEncode 方法

    將字串轉換為 HTML 編碼的字串. 例如: publicstringWelcome(string name,int numTimes =1){     returnHttpUtility.HtmlE ...

  7. javascript; JS版HtmlEncode方法,结果与C#中HttpUtility.HtmlEncode方法一样。

    <script type="text/javascript"> function HTMLEncode(html) { var temp = document.crea ...

  8. MVC前后端数据被编码

    @{ ViewBag.Title = "Home Page";}<script> function htmldecode(s) { console.log(s); va ...

  9. Spring MVC 关于controller的字符编码问题

    在使用springMVC框架构建web应用,客户端常会请求字符串.整型.json等格式的数据,通常使用@ResponseBody注解使 controller回应相应的数据而不是去渲染某个页面.如果请求 ...

随机推荐

  1. 配置java 环境变量(jdk)

    java环境变量需要配置3个: JAVA_HOME:D:\Program Files (x86)\Java\jdk1.8 CLASSPATH:.;%JAVA_HOME%\lib\dt.jar;%JAV ...

  2. windows 空闲超时 非管理员如何破解

    windows 空闲超时 非管理员如何破解

  3. 【Bash百宝箱】Linux shell学习

    shell特点-- Linux有多种shell能够使用,默认的为bash,bash有以下几个主要特点. 1.命令记忆能力 在命令行中按上下键能够找到一个前/后输入的命令.这些命令记录在-/.bash_ ...

  4. OpenGL学习一

    作者:朱金灿 来源:http://blog.csdn.net/clever101 回家计划学习OpenGL开发.没有开发机子,用的是别人的笔记本,不想装庞大的VS,于是选择小巧一点的codeblock ...

  5. 短文评估【安徽省选2003】- hash / trie

    题目分析 其实是hash/trie裸题,讲一下hash的做法:如果其小写状态是第一次出现则加入集合,同时将小写状态加入小写单词的hash表,最后查时查出出现次数即可. code #include< ...

  6. 【13.77%】【codeforces 734C】Anton and Making Potions

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【38.24%】【codeforces 621E】 Wet Shark and Blocks

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. Ubuntu server使用命令行上板VPNclient

    Ubuntu server使用命令行上板VPNclient VPN,虚拟专用网络,这个技术还是非常有用的.近期笔者參与的项目中就使用上了VPN,大概情况是这种.有两个开发团队,在异地,代码服务器在深圳 ...

  9. PAT 1011-1020 题解

    早期部分代码用 Java 实现.由于 PAT 虽然支持各种语言,但只有 C/C++标程来限定时间,许多题目用 Java 读入数据就已经超时,后来转投 C/C++.浏览全部代码:请戳 本文谨代表个人思路 ...

  10. shell问题集合

    1.syntax error near unexpected token `then' if后要有空格,[] 中括号的开头和结尾要有空格! [ $1-eq"root" ]中括号中的 ...