易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET 判断网页编码读取内容,防止乱码

最近要写一个在网页中查找关键字及链接的程序,在输出到TextBox的时候发现经常出现乱码,整理了一下根据不同的编码选取网页源文件,目前可以解决几种常编码方式的网页,感兴趣的可以试下。
本来想用“==”判断编码,感觉比较麻烦,所以改用比较模糊的方法,Contains用在这里挺方便的。
Contains说明:就是返回一布尔值,指示是否当前字符串实例包含给定的子串。
//存放网页的源文件
string all_code = "";
HttpWebRequest all_codeRequest = (HttpWebRequest)WebRequest.Create(web_url);
WebResponse all_codeResponse = all_codeRequest.GetResponse();
string contenttype = all_codeResponse.Headers["Content-Type"];//得到结果为"text/html; charset=utf-8"
//网页编码判断
if (contenttype.Contains("GB2312"))
{
StreamReader the_Reader = new StreamReader(all_codeResponse.GetResponseStream(), Encoding.GetEncoding("gb2312"));
//获取源文件
all_code = the_Reader.ReadToEnd();
the_Reader.Close();
}
else if (contenttype.Contains("GBK"))
{
StreamReader the_Reader = new StreamReader(all_codeResponse.GetResponseStream(), Encoding.GetEncoding("GBK"));
//获取源文件
all_code = the_Reader.ReadToEnd();
the_Reader.Close();
}
else if (contenttype.Contains("UTF-8"))
{
StreamReader the_Reader = new StreamReader(all_codeResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"));
//获取源文件
all_code = the_Reader.ReadToEnd();
the_Reader.Close();
}


相关文档:

ASP.NET导出Excel乱码的解决方案

在asp.net中导出excel 中比较通行的做法是: Response.ContentType = "application/vnd.ms-excel";
然后直接向里面扔 html 的table
但是有中文的时候 老出现乱码,有很多解决方案,但都不能通盘解决, 就是在 输出html两头输出
 
Response.Write("<html><head><meta http-equiv=Content-Type conte ......

使用ASP.NET 2.0 Profile存储用户信息[翻译]

作者: Stephen Walther
原文地址:http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnvs05/html/UserProfiles.asp

者:Tony Qu
概要:许多ASP.NET应用程序需要跨访问的用户属性
跟踪功能,在ASP.NET1.1中,我们只能人工实现这一功能。但如今,使用 ASP.NET 2.0的Profile对象,这个过程变得异 ......

asp.net为图片添加文字水印

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="s ......

ASP.NET 首页性能的十大做法

ASP.NET 首页性能的十大做法
前言
本文是我对ASP.NET页面载入速度提高的一些做法,这些做法分为以下部分:
1.采用 HTTP Module 控制页面的生命周期。
2.自定义Response.Filter得到输出流stream生成动态页面的静态内容(磁盘缓存)。
3.页面GZIP压缩。
4.OutputCache 编程方式输出页面缓存。
5.删除页面空白字符串 ......

在asp.net webservice中如何使用session

在使用asp.net编写webservice时,默认情况下是不支持session的,但我们可以把WebMethod的EnableSession选项设为true来显式的打开它,请看以下例子:
1 新建网站WebSite 
2 新建web服务WebService.asmx,它具有以下两个方法:
[WebMethod(EnableSession = true)]
public string Login(string name)
{
   ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号