views:

39

answers:

1

I'm displaying an address to a user on a ASP.Net page using a label. The new lines are converted from

Environment.NewLine

to

<br />

If a user edits the address, the address is displayed in a text area and the

<br />

is replaced with

Environment.NewLine

Sometimes the address saved to the database only has the line feed. Given how often this happens, it looks like it could be happening for Linux or OSX users.

Does Environment.NewLine return the new line value of the client's browser or of the server, or could it something else?

+2  A: 

No, Environment.NewLine returns whatever's on your server (because that's where it's running). It's entirely possible that a browser running on Unix will submit data with just "\n" instead of "\r\n" as the line-break. It sounds like you should be normalizing the data before saving it in the database. Then you know you can perform the replacement to <br /> safely for display purposes.

(I'm assuming your server is running on Windows, and that that's where all your code is - i.e. there's no Silverlight etc involved.)

Jon Skeet
@Jon - wouldn't mono/moonlight on linux/mac return `\n` for `Environment.NewLine`?
Oded
@Oded: They would if the code was running there, but it sounds more likely that they're Linux browsers talking to a Windows server.
Jon Skeet
@Oded to be clear, I'm using Windows 2003 and IIS
TheLukeMcCarthy
@Jon thanks for that, I didn't think Environment.Newline would work that way.
TheLukeMcCarthy