asp.net 繁体环境下简体转换繁体

ccw7534569518 2010-05-12 04:51:31
我的程序在简体环境下可以转换成功,但是在繁体环境下转换后都是乱码,这是什么原因?怎么解决?
方法如下:
1、配置文件:<httpModules>
<add name="StrConvHttpModule" type="HttpModules.StrConvHttpModule, ClassLibrary1" />
</httpModules>
2、ClassLibrary1.dll是两个文件编译出来的:
第一个:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Collections;
using zhuanhuan.IO;

namespace HttpModules
{
public class StrConvHttpModule : IHttpModule
{
public string ModuleName
{
get
{
return "StrConvHttpModule";
}
}

public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
}

private void Application_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication) sender;
HttpContext context = application.Context;
context.Response.Filter = new StrConvFilter(context.Response.Filter);
}

public void Dispose()
{
}
}
}

第二个:
using System;
using System.Collections.Generic;
using System.Text;

namespace zhuanhuan.IO
{
using System;
using System.IO;
using System.Web;
using System.Text;
using System.Globalization;

using Microsoft.VisualBasic;

public class StrConvFilter : Stream
{
private Stream _sink;
private long _position;

public StrConvFilter(Stream sink)
{
this._sink = sink;
}

public override bool CanRead
{
get
{
return true;
}
}

public override bool CanSeek
{
get
{
return true;
}
}

public override bool CanWrite
{
get
{
return true;
}
}

public override long Length
{
get
{
return 0;
}
}

public override long Position
{
get
{
return this._position;
}
set
{
this._position = value;
}
}

public override long Seek(long offset, SeekOrigin direction)
{
return this._sink.Seek(offset, direction);
}

public override void SetLength(long length)
{
this._sink.SetLength(length);
}

public override void Close()
{
this._sink.Close();
}

public override void Flush()
{
this._sink.Flush();
}

public override int Read(byte[] buffer, int offset, int count)
{
return this._sink.Read(buffer, offset, count);
}

public override void Write(byte[] buffer, int offset, int count)
{
if (HttpContext.Current.Response.ContentType == "text/html")
{
Encoding e = Encoding.GetEncoding(HttpContext.Current.Response.Charset);
string s = e.GetString(buffer, offset, count);
s = Strings.StrConv(s, VbStrConv.TraditionalChinese, CultureInfo.CurrentCulture.LCID);
this._sink.Write(e.GetBytes(s), 0, e.GetByteCount(s));
}
else
{
this._sink.Write(buffer, offset, count);
}
}
}
}
...全文
223 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
a124819202 2010-05-24
  • 打赏
  • 举报
回复
lester19872007 2010-05-13
  • 打赏
  • 举报
回复
有简体和繁体的转换包 你可以去找找,顺便顶一下楼上的。。牛人啊!
jshi123 2010-05-12
  • 打赏
  • 举报
回复
最后的Write方法改下
public override void Write(byte[] buffer, int offset, int count)
{
if (HttpContext.Current.Response.ContentType == "text/html")
{
Encoding e = Encoding.GetEncoding(HttpContext.Current.Response.Charset);
Encoding e = HttpContext.Current.Response.ContentEncoding;

string s = e.GetString(buffer, offset, count);
s = Strings.StrConv(s, VbStrConv.TraditionalChinese, CultureInfo.CurrentCulture.LCID);
s = Strings.StrConv(s, VbStrConv.TraditionalChinese, 2052);
this._sink.Write(e.GetBytes(s), 0, e.GetByteCount(s));
}
else
{
this._sink.Write(buffer, offset, count);
}
}
}
Teng_s2000 2010-05-12
  • 打赏
  • 举报
回复
感觉你的逻辑和代码有点不一致

CHS平台应该是转化成CHT

CHT平台应该是转化成CHS

ccw7534569518 2010-05-12
  • 打赏
  • 举报
回复
没有人知道吗?
myhope88 2010-05-12
  • 打赏
  • 举报
回复
没遇到过,帮顶下
ccw7534569518 2010-05-12
  • 打赏
  • 举报
回复
怎么没有人进来啊?

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧