title: How to limit the number of characters read by StreamReader.ReadLine() in .NET?
body: <p>I am writing a web server application in C# and using StreamReader class to read from an underlying NetworkStream:</p>
  
  <pre><code> NetworkStream ns = new NetworkStream(clientSocket);
   StreamReader sr = new StreamReader(ns);
   String request = sr.ReadLine();
  </code></pre>
  
  <p>This code is prone to DoS attacks because if the attacker never disconnects we will never finish reading the line. Is there any way to limit the number of characters read by StreamReader.ReadLine() in .NET?</p>