ASP.NET页面乱码
运行ASP.NET个人网站初学者工具包(C#版)时出现问题:鈥?涓汉缃戠珯鍒濆鑰呭伐鍏峰寘(C#)鈥濆簲鐢ㄧ▼搴忎腑鐨勬湇鍔″櫒閿欒銆?hr width=100% size=1 color=silver>
HTTP 閿欒 404 - Not Found銆?/i>
--------------------------------------------------------------------------------
鐗堟湰淇℃伅: ASP.NET Development Server 8.0.0.0
但是我运行ASP.NET个人网站初学者工具包(VB版)时却没有问题,我对比了一下两个项目,发现基本一样,但C#版的一直出现上面问题,这是怎么回事? --------------------编程问答--------------------
//C#中文乱码解决:UTF8 转 UNICODE
//XML文件可以采用多种编码,但是经过不同的编码后对于中文会出现乱码问题,比如“骞垮憡涓戦椈”,对于此问题的解决如下:
static void Main()
{
string utf8String = "骞垮憡涓戦椈";
// Create two different encodings.
Encoding utf8= Encoding.UTF8;
Encoding defaultCode= Encoding.Default;
// Convert the string into a byte[].
byte[] utf8Bytes = default.GetBytes(utf8String );
// Perform the conversion from one encoding to the other.
byte[] defaultBytes = Encoding.Convert(utf8, defaultCode, utf8Bytes );
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] defaultChars = new char[defaultCode.GetCharCount(defaultBytes , 0, defaultBytes .Length)];
defaultCode.GetChars(defaultBytes , 0, defaultBytes .Length, defaultChars , 0);
string defaultString = new string(defaultChars );
// Display the strings created before and after the conversion.
Console.WriteLine("Original string: {0}", utf8String);
Console.WriteLine("Ascii converted string: {0}", defaultString);
//或者如下:
byte[] buffer1 = Encoding.Default.GetBytes(utf8String );
byte[] buffer2 = Encoding.Convert(Encoding.UTF8, Encoding.Default, buffer1, 0, buffer1.Length);
string strBuffer = Encoding.Default.GetString(buffer2, 0, buffer2.Length);
}
--------------------编程问答-------------------- 你把页码整体的编码方式设成UTF-8了吗? --------------------编程问答-------------------- 下面是web.config内容:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="Personal" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Personal.mdf" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf" />
</connectionStrings>
<system.web>
<pages styleSheetTheme="White"/>
<customErrors mode="RemoteOnly"/>
<compilation debug="false"/>
<authentication mode="Forms">
<forms loginUrl="Default.aspx" protection="Validation" timeout="300" />
</authentication>
<authorization>
<allow users="*"/>
</authorization>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<roleManager enabled="true"/>
<siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
<providers>
<add name="XmlSiteMapProvider"
description="SiteMap provider which reads in .sitemap XML files."
type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
siteMapFile="web.sitemap"
securityTrimmingEnabled="true"/>
</providers>
</siteMap>
</system.web>
<location path="Admin">
<system.web>
<authorization>
<allow roles="Administrators"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
</configuration>
--------------------编程问答-------------------- 我是ASP.NET页面啊,Main函数怎哪里呢? --------------------编程问答-------------------- --------------------编程问答-------------------- web.config里添加:
<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
或者页面里添加:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
试试看!望能解决! --------------------编程问答-------------------- 会不会是你的项目名字有问题? --------------------编程问答--------------------
完全同意!
补充:.NET技术 , ASP.NET