Accept different encoding as input to form
I have a webpage with a form that accepts userinput that when submitted is used as content for a text file – the simplified application flow is:
1) User enters text and presses submit
2) Webpage gets template from filesystem and replaces some of the content of the file with the userinput
3) File is stored.
Now the problem is that the form can be used by people with different nationalities and written language, and if the user enters for example Chinese text, into the form, I want the Chinese characters to be written to the file. As I understand it I need to know the encoding for the content – is there any way to get this from th开发者_运维百科e form, or do you have another idea to get around this?
Best regards (or as some users would input 最好的問候)
Michael
In ASP.Net This should already work pretty much exactly as you describe it:
- The browser allows the user to enter some text and submits it to the web server using a suitable encoding. The ASP.Net framework handles the encoding for you and just gives you a standard .Net string.
- As long as the templating itself is done using standard .Net strings you shouldn't need to worry about the encoding when doing string manipulation - the .Net framework handles the encoding internally and exposes the characters represented independently of encoding.
- When saving the file you just need to make sure you choose a suitable encoding. UTF-8 will do just fine and is most likely the encoding that the .Net framework will choose unless you explicitly specify another encoding.
Have you tried this yet? If so what goes wrong?
精彩评论