title: Invalid token 'try' in class, struct, or interface member declaration
body: <p>Just started using ASPX files this morning and have hit a roadblock.</p>
  
  <p>I'm getting the following error:</p>
  
  <pre><code>Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
  
  Compiler Error Message: CS1519: Invalid token 'try' in class, struct, or interface member declaration
  
  Source Error:
  
  Line 5:  int portno = 52791;
  Line 6:  IPAddress ipa = Dns.GetHostEntry(hostname).AddressList[0];
  Line 7:  try
  Line 8:  {
  Line 9:      System.Net.Sockets.Socket sock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
  
  Source File: c:\inetpub\wwwroot\test.aspx    Line: 7 
  </code></pre>
  
  <p>from the following ASPX file code:</p>
  
  <pre><code>&lt;%@ Page Language="C#" %&gt;
  &lt;%@ Import namespace="System" %&gt;
  &lt;script runat="server"&gt;
  string hostname = "localhost";
  int portno = 52791;
  IPAddress ipa = Dns.GetHostEntry(hostname).AddressList[0];
  try
  {
      System.Net.Sockets.Socket sock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
      sock.Connect(ipa, portno);
      if (sock.Connected == true)  // Port is in use and connection is successful
              string output = "Port is Closed";
      sock.Close();
  
  }
  catch (System.Net.Sockets.SocketException ex)
  {
      if (ex.ErrorCode == 10061)  // Port is unused and could not establish connection 
          string output = "Port is Open!";
      else
          string output = ex.Message;
  }
  &lt;/script&gt;
  &lt;html&gt;...
  </code></pre>
  
  <p>Hours of Googling have not helped my problem.</p>