problema critico c#

alfinete

Power Member
ficheiro aspx
_______________________________________

Código:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="upload.aspx.cs" Inherits="insersao.upload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
  
    <div>
    <input id="filUpload" type="file" runat="server"/>&nbsp;
    <asp:Button ID="btSubmeter" runat="server" Text="Submeter" OnClick="btSubmeter_Click" /><br />
    <br />

    <asp:Label id="lblMensagem" runat="server" Font-Bold="True" Font-Size="Large"/> 

    </div>
   
</body>
</html>

ficheiro aspx.cs

Código:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

namespace insersao
{
    public partial class upload : System.Web.UI.Page
    {
      private string tamanho = ConfigurationManager.AppSettings.Get("tamanhofile");
        private string upload = ConfigurationManager.AppSettings.Get("upload");
            protected void btSubmeter_Click(object sender, EventArgs e)
        {
           
                try
                {
                    //Verificamos se tem alguma coisa postada 
                    if (filUpload.PostedFile.FileName != "")
                    {
                        if (this.filUpload.PostedFile.ContentLength <= Convert.ToInt32(tamanho))
                        {
                            string base_path_dir = @"" + upload;
                            //Cria o objeto FileInfo baseado no arquivo postado

                            FileInfo fl = new FileInfo(this.filUpload.PostedFile.FileName);

                            //Salva o arquivo no diretório selecionado com o nome do arquivo postado

                            filUpload.PostedFile.SaveAs(base_path_dir + "/" + fl.Name);

                            //Emite a resposta ao usuário

                            lblMensagem.Text = "Arquivo enviado com sucesso!";
                        }
                        else
                        {
                            lblMensagem.Text = "Tamanho de arquivo inválido, tem de ser < 20 mgs";
                        }
                    }
                    else
                    {
                        lblMensagem.Text = "Selecione um arquivo!";
                    }
                }
                catch (Exception ex)
                {
                    lblMensagem.Text = "Há erros!. " + ex.Message;
                    //throw ex;
                }

            }

        
    }
}

ficheiro webconfig

_________________________________

Código:
<?xml version="1.0"?>

<configuration>

 
  <appSettings>
    <add key="Upload" value="\Documents and Settings\jaribeiro\Os meus documentos\Visual Studio 2005\Projects\acordaos\Pesquisa\pdfjur\" />
    <add key="tamanhofile" value="20480000" />
    <!--<add key="upload3" value="\Inetpub\wwwroot\pdfjur" />-->

  </appSettings>
  <!-- <connectionStrings/>-->


  <system.web>
   
    
    <httpRuntime
 

    executionTimeout="240"

    maxRequestLength="20480"

    useFullyQualifiedRedirectUrl="true" 

    minFreeThreads="8"

    minLocalRequestFreeThreads="4"

    appRequestQueueLimit="100"

    />
  

  
    <pages validateRequest="false"  />
    <!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
    <compilation debug="true" />
    <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
    <authentication mode="Windows" />
    <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
  </system.web>

</configuration>

tenho um problema quando fasso uopload acima dio tamanaho que limitei dá o erro da iamagem do link a baixo

Código:
http://img245.imageshack.us/my.php?image=errorg9.jpg

caso uploade um file menor que esse tamanho , faz na perfeição

gostava que me ajudassem na resolução do problema

tem os ficheiros com code necessario para a resolução do problema

o projecto que criei foi insersão por isso o nome do namespace dos files cs

para escolherem o caminho de onde querem guardar o upload basta mudarem na seguinte linha do web config

Código:
<add key="Upload" value="\Documents and Settings\jaribeiro\Os meus documentos\Visual Studio 2005\Projects\acordaos\Pesquisa\pdfjur\" />
asp.net e c# são as linguagens utilizadas

agradeço uma ajuda
 
o valor do "maxRequestLength" não é só o máximo do ficheiro... é o máximo do "Request"...
ora, um request tem sempre mais informação, logo, se tentas fazer um upload de um ficheiro com o tamanho igual ao definido no "maxRequestLength" é natural que o pedido não seja aceite.
 
sim assim funciona

aumentei o request para 30 mgs e o key ficou igual , mas se passar os 30 mgs do request, continua na mesma , não ha forma de contornar esse problema

obrigado na mesma
 
Back
Topo