日期:2014-05-18  浏览次数:20476 次

不使用web.config,设置requestEncoding的编码方式为gb2312
简单的说,我要的是web.config里 <globalization   requestEncoding= "gb2312 "   /> 设置在aspx页面中的等效代码,我目的是在我的站点里不想要web.config配置文件。


要看具体的请看一下这条帖子,谁解决了两条帖子一起给分!
http://community.csdn.net/Expert/TopicView3.asp?id=5660079

------解决方案--------------------
// 要是这个都不行,就爱莫能助了,
// 我试过了是可以滴,GB2312
// just try, plz
//
// .aspx
protected override void InitializeCulture()
{
//string selectedLanguage = System.Configuration.ConfigurationSettings.AppSettings[ "zh-tw "]; // "en-us ";
string selectedLanguage = "zh-cn ";
Page.UICulture = selectedLanguage;
Page.Culture = selectedLanguage;
Page.Request.ContentEncoding = Encoding.GetEncoding( "GB2312 ");
Page.Response.ContentEncoding = Encoding.GetEncoding( "GB2312 ");

System.Threading.Thread.CurrentThread.CurrentCulture =
System.Globalization.CultureInfo.CreateSpecificCulture(selectedLanguage);
System.Threading.Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo(selectedLanguage);


base.InitializeCulture();
}

Hope helpful.
------解决方案--------------------
protected string GetQueryString(string sKey,System.Text.Encoding e) { string QueryString = Server.UrlDecode(System.Web.HttpUtility.UrlDecode(Request.ServerVariables[ "QUERY_STRING "], e)); System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(sKey + "=([^&$]*?)(&|$) "); System.Text.RegularExpressions.Match m = reg.Match(QueryString); if (m.Success) { return m.Result( "$1 "); } else return String.Empty; } //以上这个不受编码影响,只需知道原来传入的编码就可.