Asp.net 不能显示北欧的æøå;生成ics文件时(æ;ø;å;)

Asp.net 不能显示北欧的æøå;生成ics文件时(æ;ø;å;),asp.net,vb.net,ado.net,outlook,icalendar,Asp.net,Vb.net,Ado.net,Outlook,Icalendar,我是新来的,但有一个生成脚本的ics文件,工作100%的iCal和Outlook,但我看不出我如何修复编码 当我的数据库中有一个北欧字母(nordicæåå)的文本时,我得到的字母是?。 有人能帮我设置使用iso-8859-1吗 或者我需要用html标记(æøå)替换字母的6个替换代码吗 我的代码是 Imports System.Data.OleDb Imports System.Data Imports RF.Event2 Partial Class _new Inherits System

我是新来的,但有一个生成脚本的ics文件,工作100%的iCal和Outlook,但我看不出我如何修复编码

当我的数据库中有一个北欧字母(nordicæåå)的文本时,我得到的字母是?。 有人能帮我设置使用iso-8859-1吗

或者我需要用html标记(æøå)替换字母的6个替换代码吗

我的代码是

Imports System.Data.OleDb
Imports System.Data
Imports RF.Event2

Partial Class _new
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then

    End If
End Sub

Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim ical As New iCalendar()

    Dim strConnection As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString)
    Dim strQuery As String = String.Empty

    strQuery = "SELECT * FROM [Events] WHERE ([EventType]='K' OR [EventType]='E' OR [EventType]='T') ORDER BY [EventDate] ASC"
    Dim daEvents As New OleDbDataAdapter(strQuery, strConnection)
    Dim dtEvents As New DataTable
    strConnection.Open()
    daEvents.Fill(dtEvents)
    strConnection.Close()

    If (dtEvents.Rows.Count > 0) Then

        For i As Integer = 0 To dtEvents.Rows.Count - 1
            Dim ev As New [Event]()
            ev.Title = dtEvents.Rows(i)("EventHome")
            ev.Description = dtEvents.Rows(i)("EventNote")
            ev.Location = dtEvents.Rows(i)("EventPlace")
            ev.StartTime = DateTime.Parse(dtEvents.Rows(i)("EventDate"))
            ev.EndTime = DateTime.Parse(dtEvents.Rows(i)("EventDate").AddMinutes(90))
            ical.Events.Add(ev)
        Next
    End If
    ' Set the content-type of the response and file name
    ' so Windows knows how to handle the response.
    Context.Response.Buffer = True
    Context.Response.ContentType = "text/calendar"
    Context.Response.ContentEncoding = Encoding.GetEncoding("iso-8859-1")
    Context.Response.Charset = "iso-8859-1"
    Context.Response.AddHeader("content-disposition", "inline;filename=Sport.ics")

    ' Write the bytes of the iCalendar item output to the resonse stream
    Context.Response.BinaryWrite(New System.Text.ASCIIEncoding().GetBytes(ical.Output))
    Context.Response.[End]()

    'Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("iso-8859-1")
End Sub


End Class

您正在使用
ascienceoding
将有问题的字符映射到“?”来写入流

您可以通过一些修改来修复代码并使其抵抗此错误:

Context.Response.ContentEncoding = Encoding.GetEncoding("iso-8859-1") 
Context.Response.Charset = Context.Response.ContentEncoding.WebName
Context.Response.AddHeader("content-disposition", "inline;filename=Sport.ics") 

' Write the bytes of the iCalendar item output to the resonse stream 
Context.Response.BinaryWrite(Context.Response.ContentEncoding.GetBytes(ical.Output)) 

也许你需要使用UTF-8编码。要解决此问题,可以使用Fiddler之类的工具查看从服务器接收的实际字节。例如,对于ISO-8859-1,字符串
æå
应编码为
0xE6 0xF8 0xE5
,而
Ê255;
应编码为
0xAF 0xCA 0xFF
,这是完全不同的。