title: ASP.NET Web Page Not Available
body: <p>It's pretty difficult to show code for ASP.NET here, so I will try my best to describe my problem.</p>
  
  <p>I have a FileUploadControl and a Button that calls a function when it's clicked. It seems that the Button function works when there is nothing chosen for my FileUploadControl. However, when there is something chosen in the FileUploadControl (I have selected a file to upload), there is a problem when I click the button. It completely does not matter what the function does (it could just be writing to a label, even when it has nothing to do with the FileUploadControl). The error I get is:</p>
  
  <p>This webpage is not available.</p>
  
  <p>The webpage at <a href="http://localhost:2134/UploadMedia/Default.aspx" rel="nofollow noreferrer">http://localhost:2134/UploadMedia/Default.aspx</a> might be temporarily down or it may have moved permanently to a new web address.</p>
  
  <p>I have searched on Google, and people seem to have had problems with this, but different causes from me. They have said that their ASP.NET Development Server port is actually different from their port in the address bar. This is not the case for me.</p>
  
  <p>Also, another problem people have had is with <code>Use Dynamic Ports</code>. I have tried both <code>true</code> and <code>false</code>. I have also tried different ports, and I have always gotten the same error.</p>
  
  <p>This is really driving me crazy because it doesn't matter what the code in the buttonFunction is, it doesn't work as long as there is something in the FileUploadControl. If there is nothing, it seems to work fine.</p>
  
  <p>Here is the code for the ASP.NET Controls:</p>
  
  <pre><code>&lt;asp:FileUpload id="FileUploadControl" runat="server" /&gt;
  &lt;asp:Button runat="server" id="UploadButton" text="Upload" OnClick="uploadClicked" /&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;asp:Label runat="server" id="StatusLabel" text="Upload status: " /&gt;
  </code></pre>
  
  <p>And this is the code for the button function:</p>
  
  <pre><code>protected void uploadClicked(object sender, EventArgs e)
  {
      if (FileUploadControl.HasFile)
      {
          string filename = Path.GetFileName(FileUploadControl.FileName);
  
          //Check if the entered username already exists in the database.
          String sqlDupStmt = "Select songPath from Songs where songPath ='" + Server.MapPath("~/Uploads/") + filename + "'";
          SqlConnection sqlDupConn = new SqlConnection(@"Data Source = .\SQLEXPRESS; AttachDbFilename = |DataDirectory|\Database.mdf; Integrated Security = True; User Instance = True;");
          SqlCommand sqlDupCmd = new SqlCommand(sqlDupStmt, sqlDupConn);
          sqlDupCmd.Connection.Open();
          SqlDataReader sqlDupReader = sqlDupCmd.ExecuteReader(CommandBehavior.CloseConnection);
  
          if (sqlDupReader.Read())
          {
              StatusLabel.Text = "Upload status: The file already exists.";
              sqlDupReader.Close();
          }
  
          else
          {
              sqlDupReader.Close();
  
              //See "How To Use DPAPI (Machine Store) from ASP.NET" for information about securely storing connection strings.
              String sqlStmt = "Insert into Songs values (@songpath);";
              SqlConnection sqlConn = new SqlConnection(@"Data Source = .\SQLEXPRESS; AttachDbFilename = |DataDirectory|\Database.mdf; Integrated Security = True; User Instance = True; uid=sa; pwd=password;");
              SqlCommand cmd = new SqlCommand(sqlStmt, sqlConn);
              SqlParameter sqlParam = null;
  
              //Usage of Sql parameters also helps avoid SQL Injection attacks.
              sqlParam = cmd.Parameters.Add("@userName", SqlDbType.VarChar, 150);
              sqlParam.Value = Server.MapPath("~/Uploads/") + filename;
  
              //Attempt to add the song to the database.
              try
              {
                  sqlConn.Open();
                  cmd.ExecuteNonQuery();
                  FileUploadControl.SaveAs(Server.MapPath("~/Uploads/") + filename);
                  songList.Items.Add(filename);
                  StatusLabel.Text = "Upload status: File uploaded!";
              }
  
              catch (Exception ex)
              {
                  StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
              }
  
              finally
              {
                  sqlConn.Close();
              }
          }
      }
  }
  </code></pre>
  
  <p>But this buttonfunction provides the same results:</p>
  
  <pre><code>protected void uploadClicked(object sender, EventArgs e)
  {
      StatusLabel.Text = "FooBar";
  }
  </code></pre>
  
  <p>Has anyone had this problem before, or might know what the cause is?</p>
  
  <p>Thanks!</p>