IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

Longueur maximale de la demande dépassée


Sujet :

ASP.NET

  1. #1
    Membre régulier
    Inscrit en
    Mars 2007
    Messages
    145
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 145
    Points : 86
    Points
    86
    Par défaut Longueur maximale de la demande dépassée
    Bonjour à tous,
    sur une page ASPx j'upload des fichiers et les copier dans un autre repertoire,
    mon probleme est que mon unpload n'autorise pas les fichiers superieurs à 3 Mo, et j'obtient l'erreur suivant:
    {longueur maximale dépassé
    [http exception (0X80004005)
    system.web httprequest.get
    Entire Raw content ()+3315778....
    PhysicalApplicationPath...
    __________________________________________
    mon code est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
     
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.IO;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Drawing.Design;
    using System.IO;
     
     
    public partial class UploadImages : System.Web.UI.Page
    {
        Random random = new Random();  //variable aléatoire pour nommer du FolderName
     
     
        protected void Page_Load(object sender, EventArgs e)
        {
            //string ApplicationPath = Request.PhysicalApplicationPath;
            //ApplicationPath = ApplicationPath.Substring(0, ApplicationPath.Length - 3);
            //lblMessage.Text = ApplicationPath ;
     
            //lblMessage.Text = "";
        }
     
        public int InsertedImageID = 0;
     
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                HttpFileCollection uploads = HttpContext.Current.Request.Files;
     
                string ApplicationPath = Request.PhysicalApplicationPath;
                ApplicationPath = ApplicationPath.Substring(0, ApplicationPath.Length - 4);
     
                //FolderName du livre selectionné
                DALivre dalivre = new DALivre();
                string FolderName = dalivre.getFolderNameByIDLivre(Convert.ToInt32(ddlLivre.SelectedItem.Value));
     
                int NombreImages = dalivre.getNombreImagesByIDLivre(Convert.ToInt32(ddlLivre.SelectedItem.Value));
     
                string path = ApplicationPath + "\\images\\";
     
                path = path + FolderName;
     
                //Upload photos
                int UploadedImages = 0;
     
                for (int i = 0; i < uploads.Count; i++)
                {
                    HttpPostedFile upload = uploads[i];
     
                    if (upload.ContentLength == 0) // si aucune image dans le input en cours alors passer au suivant
                        continue;
     
                    string FileName = System.IO.Path.GetFileName(upload.FileName); // We don't need the path, just the name.
     
                    string FileExtention = System.IO.Path.GetExtension(upload.FileName);
     
                    if (FileExtention.ToLower() != ".jpg")
                    {
                        lblMessage.Text = "Fichiers jpg uniquement.";
                        btnSubmit.Enabled = true;
     
                        return;
                    }
     
                    upload.SaveAs(@ApplicationPath + "\\images\\" + FolderName + "\\page" + (NombreImages + i).ToString() + ".jpg");
                    UploadedImages++;
                    lblMessage.Text = "Upload terminé.";
                }
     
                NombreImages = NombreImages + UploadedImages;
     
                if (uploads.Count > 0)  //update livre, enregistrer NombreImages
                {
                    dalivre.UpdateNombreImages(Convert.ToInt32(ddlLivre.SelectedItem.Value), NombreImages);
                }
            }
            catch (Exception Exp)
            {
                lblMessage.Text = "Echec lors de l'upload : <br />" + Exp.ToString();
                //lblMessage.ForeColor = System.Drawing.Color.Red;
            }
     
        }
     
        private void New()
        {
            //txtFolderName.Enabled = true;
            //txtFolderName.Text = "";
            btnSubmit.Enabled = false;
        }
     
        protected void ddlCategorie_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlLivre.Items.Clear();
            ddlLivre.Items.Add(new ListItem("Sélectionnez un livre", "0"));
            ddlLivre.DataBind();
        }
     
        protected void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                // (1) Read Uploaded file (here Image) in Byte Array
                if (File1.PostedFile != null)
                {
                    if (File1.PostedFile.ContentLength > 0)
                    {
                        // Get Posted File.
                        HttpPostedFile objHttpPostedFile = File1.PostedFile;
     
                        // Check valid Image type. Create this function according to your need
                        string FileExtention = System.IO.Path.GetExtension(File1.PostedFile.FileName);
     
                        if (FileExtention == ".jpg")
                        {
                            // Find its length and convert it to byte array
                            int intContentlength = objHttpPostedFile.ContentLength;
     
                            // Create Byte Array 
                            Byte[] bytImage = new Byte[intContentlength];
     
                            // Read Uploaded file in Byte Array
                            objHttpPostedFile.InputStream.Read(bytImage, 0, intContentlength);
     
                            //(2) Insert image in database
                            DAImage daimage = new DAImage();
                            InsertedImageID = daimage.InsertImage(bytImage, Convert.ToInt32(ddlLivre.SelectedItem.Value));
                        }
                        else
                        {
                            lblMessage.Text = "Fichiers jpg uniquement.";
                            //lblMessage.ForeColor = System.Drawing.Color.Red;
                        }
                    }
                }
            }
            catch (Exception Exp)
            {
                lblMessage.Text = "Echec lors de l'enregistrement : <br />" + Exp.ToString();
                //lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
     
        protected void cmdRetour_Click(object sender, EventArgs e)
        {
            Response.Redirect("Ajout.aspx");
        }
     
     
     
    }
    __________________________________________________
    dans le web.config j'ai:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    		<httpHandlers>
    			<remove verb="*" path="*.asmx"/>
    			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx"/>
    			<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx" validate="false"/>
    		</httpHandlers>

    et merci d'avance!

  2. #2
    Expert confirmé
    Avatar de Nicolas Esprit
    Homme Profil pro
    Consultant en technologies
    Inscrit en
    Février 2010
    Messages
    1 467
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Consultant en technologies
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2010
    Messages : 1 467
    Points : 4 066
    Points
    4 066
    Par défaut


    Il faut augementer ton maxRequestLength dans le fichier Web.Config. Valeur = X * 1024, avec X représentant le nombre de Mo maximum à uploader.

  3. #3
    Membre régulier
    Inscrit en
    Mars 2007
    Messages
    145
    Détails du profil
    Informations forums :
    Inscription : Mars 2007
    Messages : 145
    Points : 86
    Points
    86
    Par défaut
    Merci, c'est ca ce que j'ai cherché mais sur le web.config je ne trouve pas maxRequestLength.

  4. #4
    Expert éminent sénior

    Avatar de Philippe Vialatte
    Homme Profil pro
    Architecte technique
    Inscrit en
    Juillet 2004
    Messages
    3 029
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Architecte technique
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Juillet 2004
    Messages : 3 029
    Points : 12 465
    Points
    12 465
    Par défaut
    je ne trouve pas maxRequestLength
    probablement parce qu'il faut l'ajouter

    http://www.lmgtfy.com/?q=maxRequestL....microsoft.com


    Mon Blog

    The Cake is still a lie !!!



    Vous voulez contribuer à la rubrique .NET ? Contactez-moi par MP.
    Vous voulez rédiger des articles pour la rubrique .NET ? Voici la procédure à suivre.

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Ingénieur généraliste IT
    Inscrit en
    Janvier 2016
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur généraliste IT

    Informations forums :
    Inscription : Janvier 2016
    Messages : 1
    Points : 6
    Points
    6
    Par défaut
    Le fichier upload est plus grand que la valeur acceptée par défaut.
    Il faut ajouter/modifier dans le fichier web.config le paramètre "maxRequestLength" et le set à la valeur max que tu souhaites pouvoir upload

    <configuration>
    <system.web>
    <httpRuntime maxRequestLength="size in kbytes" />

    Lien vers la doc MSDN

    PS : Je me permets de re-poster ici, même si ce topic est vieux, car c'est le premier à remonter dans mes recherches Google et ne m'a pas apporté la réponse rapidement ^^

    Bonne journée,
    Magic-Denver

  6. #6
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2014
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2014
    Messages : 199
    Points : 70
    Points
    70
    Par défaut
    Bonjour,

    Je me permets à mon tour de reposter la dessus parce que aprés de nombreux tests, il m'a fallut pour ma part jouer sur deux parametre.
    le MaxRequestLength (qui est en Ko /1024=Mo) et le maxAllowedContentLength (qui lui est en octet /1024/1024 = Mo)

    pour ma part, pour pouvoir uploader jusqu'à 100 Mo, j'ai du mettre
    MaxRequestLength = 102400
    maxAllowedContentLength = 104857600

    Sinon, ça ne marchais pas...

    Peut-être est ce lié à la méthode utilisé pour uploader...

    Voili, voilou
    Sylo

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 09/03/2012, 14h53
  2. [SOAP] Longueur maximale de la demande dépassée
    Par Gregory.M dans le forum Services Web
    Réponses: 0
    Dernier message: 28/07/2009, 16h19
  3. Réponses: 0
    Dernier message: 27/11/2007, 03h31
  4. Longueur maximale d'un varchar2
    Par coucou_tt_le_monde dans le forum Oracle
    Réponses: 1
    Dernier message: 05/10/2005, 10h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo