2010-04-05 9 views
2

여기에 ASP.NET 코드를 표시하는 것이 꽤 어렵 기 때문에 내 문제를 설명하기 위해 최선을 다할 것입니다.ASP.NET 웹 페이지를 사용할 수 없습니다.

은 내가 FileUploadControl과 클릭 할 때 함수를 호출하는 버튼이있다. 내 FileUploadControl에 아무 것도 선택하지 않으면 Button 기능이 작동하는 것 같습니다. 그러나 FileUploadControl에서 선택한 항목 (업로드 할 파일을 선택 함)이있을 때 버튼을 클릭하면 문제가 발생합니다. 함수가 무엇을하는지는 중요하지 않습니다 (FileUploadControl과 아무 관련이없는 경우에도 레이블에 쓸 수 있습니다). 내가 얻는 오류는 다음과 같습니다.

이 웹 페이지를 사용할 수 없습니다.

http://localhost:2134/UploadMedia/Default.aspx의 웹 페이지가 일시적으로 다운되었거나 새 웹 주소로 완전히 이동했을 수 있습니다.

나는 구글에서 검색 한 사람들은 저에서이 문제,하지만 서로 다른 원인을 갖고있는 것 같다. 그들은 ASP.NET 개발 서버 포트가 주소 표시 줄의 포트와 실제로 다릅니다라고 말했습니다. 이것은 나를위한 것이 아닙니다.

또한, 또 다른 문제는 사람들이 있었다 Use Dynamic Ports 함께. 나는 truefalse을 시도했다. 나는 또한 다른 포트를 시도하고, 나는 항상 같은 오류가 발생했습니다.

정말 나를 미치게는 FileUploadControl에 뭔가가로 buttonFunction의 코드가, 그것은 오래 작동하지 않습니다 어떤 문제가되지 않기 때문에 운전. 아무것도 없다면 제대로 작동하는 것 같습니다. 여기

은 ASP.NET 컨트롤에 대한 코드입니다 :

<asp:FileUpload id="FileUploadControl" runat="server" /> 
<asp:Button runat="server" id="UploadButton" text="Upload" OnClick="uploadClicked" /> 
<br /><br /> 
<asp:Label runat="server" id="StatusLabel" text="Upload status: " /> 

그리고 이것은 버튼 기능에 대한 코드입니다 :

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(); 
      } 
     } 
    } 
} 

그러나이 buttonfunction 같은 결과를 제공합니다

protected void uploadClicked(object sender, EventArgs e) 
{ 
    StatusLabel.Text = "FooBar"; 
} 

누구든지 전에이 문제가 있었거나 원인을 알 수 있습니까?

감사합니다.

답변

4

제 친구가 도와주었습니다. ASP.NET은 4MB 크기의 업로드 만 허용했기 때문입니다. web.config 또는 machine.config 파일에 들어가서 MaxRequestLength 값을 4096보다 크게 변경해야했습니다.이 문제는 해결되었습니다. 그냥 뭔가 잘못했다 말해 대신 나에게 웹 페이지를 사용할 수없는 오류를 제공하는 이유

+0

정말 모르겠어요. – hahuang65

관련 문제