-1

After going to use the mysql database in utf-8 and all my pages, check the coding and include

@ Language = VBScript CodePage = 65001

In the HTML page, including:

meta charset = "utf-8"

Everything was going wonderfully well until I have to change my upload system.   Now, I'm using the Pure Asp Upload, which for sending images, it's great, but I need your help, because the other text fields, are crazy.

I made a very simple code, with just a File field and a text field, just to exemplify, and give a Response.End () shortly after he takes the field just to try to see what happens, but after several days without success, come help.

Pure Asp Upload version is 2.06

<%@ Language=VBScript CodePage=65001%>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<!--#include file="../includes/pure-upload.asp"-->
<% Session.Timeout = 60 %>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<%
sAction = Request.querystring("a_edit")

If sAction = "" Or IsNull(sAction) Then
    sAction = "I" ' Display Record
else
    Dim fupload: Set fupload = New ASPForm

    Server.ScriptTimeout = 2000
    fupload.SizeLimit = 4*1000000 'limit of size per whole form
    Const fsCompletted  = 0

    If fupload.State = fsCompletted Then 'Completted

    fupload.CharSet = Response.CharSet
    x_jogadorID = fupload("x_jogadorID")
    x_jogadorNome = fupload.Item("x_jogadorNome")

    meukarma = fupload.CharSet
    response.write x_jogadorNome & "-" & meukarma
    response.End()

    ElseIf fupload.State > 10 then
      Const fsSizeLimit = &HD
      Select case fupload.State
        case fsSizeLimit
            Session(ewSessionMessage) = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
            Session(ewSessionMessageTipo) = "error"
        case else 
            Session(ewSessionMessage) = "<Font Color=red>Erro no Formulário." & Form.State & "</Font><br>"
            Session(ewSessionMessageTipo) = "error"
      end Select
    End If 'Form.State = 0 then
End If 

%>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>teste</title>
</head>

<body>
<form name="fjogadoredit" id="fjogadoredit" action="teste.asp?a_edit=U" class="form-horizontal" method="post" enctype="multipart/form-data"  onSubmit="return EW_checkMyForm(this);" >
<input type="text" name="x_jogadorNome" id="x_jogadorNome" class="input-xlarge" maxlength="50" value="<%= Server.HTMLEncode(x_jogadorNome&"") %>">
<input type="file" id="x_jogadorFotoRosto" name="x_jogadorFotoRosto"  class="default">
</form>
</body>
</html>

The name I'm a registered test is Amésio, changed by:

amnésio

If I put the block below as early as the second line, the result for Amésio is

amnésio
<%
Response.AddHeader "Content-Type", "text/html; charset=utf-8"
response.Charset="utf-8"
%>

Someone managed to use this component in this way, or managed to solve, as it did?

user692942
  • 16,398
  • 7
  • 76
  • 175
  • Possible duplicate of [Pure ASP upload with utf-8 filenames](http://stackoverflow.com/questions/22685301/pure-asp-upload-with-utf-8-filenames) – user692942 Dec 18 '15 at 11:55
  • Pointer... Don't `Server.HTMLEncode()` values otherwise it's working against the encoding you have already set. If encoding is done right there is no need to further encode the values. – user692942 Dec 18 '15 at 12:00
  • Have you tried just writing out `Response.Charset` to see if it is set to `UTF-8` because you don't appear to be setting it in the page before assigning it to `fupload.CharSet` can you edit the question and add the output of `response.write x_jogadorNome & "-" & meukarma`? – user692942 Dec 18 '15 at 12:08
  • Sorry I meant `Response.CodePage` if it's not `65001` then that's your problem. Set it before sending processing the HTML and you should be fine. – user692942 Dec 18 '15 at 12:53
  • I define codepage on first line of code, all included files was checked, they are saved on utf-8, only `Form.CharSet = Response.CharSet` not solved my problem... I was tried create a property get/set to work with 65001. I really know with my probelma is not simple, but, all my pages work correct... I tried using persits.aspuload, and, when set codepage from him, work very well, but I want use Pure Asp Upload. – user3067573 Dec 21 '15 at 16:46
  • Have you checked that the `` file is also saved as `UTF-8`? Includes are just an extension of the ASP page, if it's set to anything other then `UTF-8` it will fail. – user692942 Dec 21 '15 at 17:09

2 Answers2

0

Understanding How IIS Processes ASP Encoding

As with all encoding issues in Classic ASP it helps to understand what purpose the various commands fulfill (as too often people use them incorrectly, because it appears to solve the problem).

<%@ Language = "VBScript" CodePage = 65001 %>

This line is commonly misunderstood, the syntax <%@ is a "ASP @ Processing Directive" and serves to tell IIS how to process the ASP page and is probably one of the most important commands when it comes to working with encoding correctly.

  • @Language tells IIS what registered Active Scripting Language should be used to process the ASP Page.

  • @CodePage tells IIS what CodePage should be used to process the ASP Page. If the page has been saved using UTF-8 then IIS needs to know when processing the page it should use CodePage 65001 (otherwise known as UTF-8).

This means that @CodePage should always match the physical encoding that was used when the page was created. You may need to use an advanced text editor to work this out, some examples are Notepad++ (displays encoding on status bar in bottom right of the GUI window) and Visual Studio (Has a hidden menu command called Advanced Save Options which can be accessed by customising the menu bar).

<% Response.CodePage = 65001 %>

Again often misunderstood, the purpose of this command is to tell IIS how dynamic strings should be encoded (by dynamic strings we mean anything that is outputted using Response.Write()). Possibly the most important part of the entire process, if it is set incorrectly or assumed encoding mismatches can and do occur.

<% Response.CharSet = "UTF-8" %>

This command sets the ;charset=utf-8 in the Content-Type HTTP header when the response is sent from the Server to the Client Browser it tells the Browser that this response should be processed as UTF-8 rather then the default. Meaning code like

Response.AddHeader "Content-Type", "text/html; charset=utf-8"

is superfluous and shouldn't be used. Also worth noting there is a command for the Content-Type HTTP header as well

Response.ContentType = "text/html"

making it even more redundant than it already was.


Useful Links

user692942
  • 16,398
  • 7
  • 76
  • 175
0

Before reading this I suggest taking a quick look at this answer

Understanding How IIS Processes ASP Encoding


AS for your specific problem I think it's down to not specifying

Response.CodePage = 65001

explicitly and assuming it's 65001 without checking it before assigning the ASPForm.CharSet property to it.

Try this

<%@ Language=VBScript CodePage=65001%>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<!--#include file="../includes/pure-upload.asp"-->
<%
Session.Timeout = 60

sAction = Request.querystring("a_edit")

'Make sure both IIS and the Browser know how to process the page / response
Response.CodePage = 65001
Response.CharSet = "UTF-8"

If sAction = "" Or IsNull(sAction) Then
    sAction = "I" ' Display Record
else
    Dim fupload: Set fupload = New ASPForm

    Server.ScriptTimeout = 2000
    fupload.SizeLimit = 4*1000000 'limit of size per whole form
    Const fsCompletted  = 0

    If fupload.State = fsCompletted Then 'Completted

    fupload.CharSet = Response.CharSet
    x_jogadorID = fupload("x_jogadorID")
    x_jogadorNome = fupload.Item("x_jogadorNome")

    meukarma = fupload.CharSet
    response.write x_jogadorNome & "-" & meukarma

    ElseIf fupload.State > 10 then
      Const fsSizeLimit = &HD
      Select case fupload.State
        case fsSizeLimit
            Session(ewSessionMessage) = "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
            Session(ewSessionMessageTipo) = "error"
        case else 
            Session(ewSessionMessage) = "<Font Color=red>Erro no Formulário." & Form.State & "</Font><br>"
            Session(ewSessionMessageTipo) = "error"
      end Select
    End If 'Form.State = 0 then
End If 

%>
<!doctype html>
<html>
<head>
<title>teste</title>
</head>

<body>
<form name="fjogadoredit" id="fjogadoredit" action="teste.asp?a_edit=U" class="form-horizontal" method="post" enctype="multipart/form-data"  onSubmit="return EW_checkMyForm(this);" >
<input type="text" name="x_jogadorNome" id="x_jogadorNome" class="input-xlarge" maxlength="50" value="<%= x_jogadorNome & "" %>">
<input type="file" id="x_jogadorFotoRosto" name="x_jogadorFotoRosto"  class="default">
</form>
</body>
</html>
Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • @user3067573 Well that's informative what did you try did you remove the `Server.HTMLEncode()` from the HTML input value? Fact is this will work if it isn't working for you your doing something wrong, your pages aren't saved in `UTF-8` *(including `#include` files)* is a common one. Just saying *"thanks, but not work"* just shows your lack of commitment and makes me less inclined to help you. Good luck. – user692942 Dec 18 '15 at 20:40
  • @user3067573 Encoding is a complex problem and has to be systematically worked through until you understand how in works with ASP pages in IIS. That is why I provided a [detailed explanation](http://stackoverflow.com/a/34356187/692942). There are no quick fixes! – user692942 Dec 18 '15 at 20:44
  • Sory @Lankymart for incovenience. I'll close this question because I do not have the insight necessary to understand their indignation if I already tried the most basic commands, as he had explained in the context post. Thank you anyway. – user3067573 Dec 21 '15 at 16:51
  • @user3067573 Did you follow my comments above? You still haven't updated the code in your question so I cannot see you have tried all these steps, if you update the question it would help. – user692942 Dec 21 '15 at 17:11