Computer/ASP

ASP 에서 UTF-8 처리

알찬돌삐 2011. 11. 29. 10:19

 
1. 모든 ASP 코드 페이지 첫줄에 다음과 같은 코드를 추가합니다
<% @LANGUAGE='VBSCRIPT' CODEPAGE='65001' %>
 
2. Meta 테그를 다음과 같이 추가 합니다.
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
 
3. 에디트플러스나 울트라 에디터에서 수정후 저장할 때 반드시 Encoding 방식을 UTF-8 로 저장합니다
 
4.DB Insert/Update 시 숫자 타입을 제외한 모든 대상에 N을 추가 합니다
Insert [into] table_name [(column_list)] Value N[data_value]
 
5.DB like 검색시 N 추가
 
6. 파일 첨부 DEXT Upload사용(영문으로 설치)
  1. SET uploadform = Server.CreateObject("DEXT.FileUpload")
  2.  uploadform.DefaultPath = Server.MapPath(ESP_BBS_DATA)
  3.  uploadform.CodePage = 65001
  4.  wFileSize = 0
  5.  rAttachment = uploadform("txtAttachFile")
  6.  
  7.  If Len(rAttachment) > 0 Then
  8.   wFileName =  uploadform("txtAttachFile").FileName
  9.   wFileSize =  uploadform("txtAttachFile").FileLen
  10.  
  11.   response.write uploadform.DefaultPath
  12.   rAttachment = uploadform.SaveAs(uploadform.DefaultPath & "" & wFileName , False)
  13.   rAttachment = UploadForm.LastSavedFileName
  14.  End If
7. 파일 다운로드 

  1. <% @LANGUAGE='VBSCRIPT' CODEPAGE='65001' %>
  2. <%
  3.  'Response.Charset = "UTF-8"
  4.  filepath = Request.QueryString("txtFilepath") '// form으로 파라메터 전달해야 함.
  5.  filename = Request.QueryString("txtFilename")'// form으로 파라메터 전달해야 함.
  6.  
  7.  If filepath = "" Then
  8.   filepath=server.MapPath( Request.QueryString("txtFilename"))
  9.   filename = Mid(filepath, InStrRev(filepath, "")+1)
  10.  Else
  11.   filepath=server.MapPath(filepath)
  12.   filename =  Request.QueryString("txtFilename")
  13.   If filename = "" Then
  14.    filename = Request.QueryString("txtattachment")
  15.   End If
  16.  End If
  17.  
  18.  filepath = filepath &"" & filename
  19. Call FileDown
  20. %>
  21.  
  22. <%
  23. Sub FileDown
  24. ' 참고http://www.taeyo.pe.kr/Lecture/20_TIps/Danny03.asp
  25.  
  26.  Response.Buffer = False
  27.  Response.ContentType = "application/x-msdownload"
  28.  'ContentType 를 선언합니다.
  29.  'server.HTMLEncode
  30.  'server.URLPathEncode
  31.  Response.AddHeader "Content-Disposition","attachment; filename=" & server.URLPathEncode(filename) '//server.URLPathEncode 사용해야만 파일명 재대로 출력
  32.  '헤더값이 첨부파일을 선언합니다.
  33.  Set objStream = Server.CreateObject("ADODB.Stream")
  34.  'Stream 을 이용합니다.
  35.  objStream.Open
  36.  '무엇이든 Set 으로 정의했으면 열어야 겠지요^^
  37.  objStream.Type = 1
  38.  objStream.LoadFromFile filepath
  39.  '절대경로 입니다.
  40.  download = objStream.Read
  41.  Response.BinaryWrite download
  42.  '이게 보통 Response.Redirect 로 파일로 연결시켜주는 부분을 대신하여 사용된 것입니다.
  43.  Set objstream = nothing
  44.  '초기화시키구요.
  45. End Sub
  46. %>
  47.  
  48. <%
  49. Sub DEXTDown   ' DEXT.FileDownload 는 일본어 OS에 영문으로 설치시 한글파일 찾지 못함.(DextUpload 2.0까지는 그랬음)
  50.  'On Error Resume Next
  51.  Response.Buffer = False
  52.  Response.AddHeader "Content-Disposition","inline;filename=" &  server.URLPathEncode(filename)
  53.  set objFS = Server.CreateObject("Scripting.FileSystemObject")
  54.  
  55.  set objF = objFS.GetFile(filepath)
  56.  
  57.  Response.AddHeader "Content-Length", objF.Size
  58.  set objF = nothing
  59.  set objFS = nothing
  60.  Response.ContentType = "application/x-msdownload"
  61.  Response.CacheControl = "public"
  62.  Set objDownload = Server.CreateObject("DEXT.FileDownload")
  63.  objDownload.Download filepath
  64.  Set uploadform = Nothing
  65. End Sub
  66. %>

8. Cdo Mail 발송
  1. Dim iMsg
  2. Dim iConf
  3. Dim Flds
  4. Dim strHTML
  5. Const cdoSendUsingPort = 2 '1:로컬, 2:외부 smtp
  6. set iMsg = CreateObject("CDO.Message")
  7. set iConf = CreateObject("CDO.Configuration")
  8. Set Flds = iConf.Fields
  9. Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
  10. Flds.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  '포트번호
  11. Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
  12. Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
  13. Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") =  "" 'ID
  14. Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") =  "" '암호
  15.  
  16. Flds.Update
  17. Set iMsg.Configuration = iConf
  18. iMsg.To = "xxxx@xxx.ccx" 'ToDo: Enter a valid email address.
  19. iMsg.From = "xxxx@xxx.ccx"  'ToDo: Enter a valid email address.
  20. iMsg.Subject = "This is a test CDOSYS message (Sent via Port 25)"
  21.  
  22. 'iMsg..TextBody = strHTMLMsg '// 텍스트
  23. iMsg.HTMLBody = strHTML  '// HTML 제목 깨짐 발생..
  24.  
  25. iMsg.BodyPart.Charset="UTF-8" '/// 한글을 위해선 꼭 넣어 주어야 합니다.
  26. iMsg.HTMLBodyPart.Charset="UTF-8" '/// 한글을 위해선 꼭 넣어 주어야 합니다.
  27. iMsg.Send
  28. End With
  29. Set iMsg = Nothing
  30. Set iConf = Nothing
  31. Set Flds = Nothing 
 
9. ASP에서 배달 확인/ 읽음 확인 구현 방법 http://tong.nate.com/windeo/5767827
  1. <%
  2. Set oMsg = CreateObject("CDO.Message")
  3. oMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  4. ‘ 생성되는 메시지가 SMTP pickup 디렉터리가 아닌 SMTP 서비스로 전송되게 합니다.
  5. oMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "이름"
  6. oMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxx"
  7. oMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "seo-msg-01"
  8. ‘ 생성되는 메시지의 서버, 사서함 및 암호
  9. oMsg.Configuration.Fields.Update
  10.  
  11. oMsg.From = "smpark@microsoft.com"
  12. oMsg.To = "smpark@microsoft.com"
  13.  
  14. oMsg.Subject = "읽음 확인 및 배달 확인"
  15. oMsg.DSNOptions = 14
  16. ‘ 이 메시지의 배달 상태 확인(delivery status notification:DSN)값으로 14는 배달 성공, 실패 및 지연시
  17. ‘ 확인메시지 생성
  18. oMsg.Fields("urn:schemas:mailheader:return-receipt-to") = smpark@microsoft.com <mailto:smpark@microsoft.com>
  19. ‘ 받는 사람이 이 메시지를 열었을 때 읽음 확인 메시지가 여기에서 지정된 사람에게 보내집니다.
  20. oMsg.Fields("urn:schemas:mailheader:disposition-notification-to") = smpark@microsoft.com <mailto:smpark@microsoft.com>
  21. ‘ MDN(Message Disposition Notification)은 이 메시지의 확인 메시지가 리턴 될 수신자를 지정합니다.
  22. ‘ MDN에 대하여는 Request for Comments (RFC) 2298에 자세히 설명됩니다.
  23. oMsg.TextBody = " SMTP 서버를 통한 읽음 확인 및 배달 확인 메시지"
  24. oMsg.Fields.Update
  25. oMsg.Send
  26.  
  27. Set oMsg = Nothing
  28. %>




출처 http://blog.naver.com/lowsky/21899479.

'Computer > ASP' 카테고리의 다른 글

asp 용 UTF8 컨버터  (0) 2012.08.10
효율적인 페이징 기법  (0) 2011.11.29
성능 및 스타일 향상을 위한 25 ASP 팁  (0) 2011.11.29
URLEncode  (0) 2011.11.29
ASP 서버 변수 출력  (0) 2011.11.29