0

I have following settings in my web.config (unfortunately)

<globalization fileEncoding="Windows-1252" requestEncoding="Windows-1252" responseEncoding="Windows-1252" />

If I want to change one page's request encoding to UTF8, I could not just use <%@ Page RequestEncoding="utf-8" ResponseEncoding="utf-8" %> according to http://msdn.microsoft.com/en-us/library/39d1w2xf(v=vs.100).aspx because these properties simply do not exist.

If I add code to my page's code behind

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    Me.Request.ContentEncoding = Encoding.UTF8
End Sub

to force UTF8 as request encoding, it does not seem to work at all. But if I change web.config to use <globalization requestEncoding="UTF-8" responseEncoding="UTF-8" /> then it works fine for this page. But I don't want to change the setting globally.

Anybody has some suggestion?

1 Answer 1

3

You can use a location section in Web.config file to set specific properties for just single page or folder. In your case you should add configuration similar to this:

<configuration>
    <system.web>
        <globalization fileEncoding="Windows-1252" requestEncoding="Windows-1252" responseEncoding="Windows-1252" />
    </system.web>
    <location path="yourfile.aspx">
        <system.web>
            <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
        </system.web>
    </location>
<configuration>
Sign up to request clarification or add additional context in comments.

1 Comment

great solution, I almost forget the location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.