Bonjour tout le monde ;
j'ai un probleme avec httpHandler
voila tout d'abord mon code
classe http handler
et voila mon web.config
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 public class FileDownloaderHandler: IHttpHandler { #region IHttpHandler Membres bool IHttpHandler.IsReusable { get { return false; } } void IHttpHandler.ProcessRequest(HttpContext context) { string FileName= context.Request ["FileName"]; //string MyFile = context.Server.MapPath("Produts/" + FileName) ; // If nomPhoto = "" OrElse Not File.Exists(nomFichier) Then FileInfo MyFile = new FileInfo(@context.Server.MapPath("Products/" + FileName)); // "C:/inetpub/wwwroot/Uploaderfinal/Products/DERA/DERA V_1/0629015e-1f2b-439a-94f5-d65e0be59da8");// if (!MyFile.Exists ) { context.Response.Write(FileName + " File Not Found"); } else { FileInfo file = MyFile;// new FileInfo(MyFile); // context.Response.Write("Pas de fichier PDF avec le nom transmis") //Else FileStream Filestream = new FileStream(file.FullName , FileMode.Open); //context.Response.AddHeader("content-type", "application/rar" ); // context.Response.Write(file.Extension.Replace('.', ' ')); byte[] buffer = new byte[Filestream.Length]; Filestream.Read(buffer, 0, buffer.Length); context.Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); // Add a HTTP header to the output stream that contains the //content length(File Size). This lets the browser know how much data is being transfered context.Response.AddHeader("Content-Length", buffer.Length.ToString()); // Set the HTTP MIME type of the output stream //context.Response.ContentType = "application/"+file.Extension.Substring(1) ; Filestream.Close(); // Write the data out to the client. context.Response.BinaryWrite(buffer); // context.Response.Write("Fin"); } } #endregion }
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 <configuration> <appSettings/> <connectionStrings/> <system.web> <authentication mode="Windows"/> <identity impersonate="true"/> <httpHandlers> <add path="uploader" verb="*" type="FileUploaderHandler" /> <add path="downloader" verb="*" type="FileDownloaderHandler"/> <add path="Delete" verb="*" type="FileDelete"/> </httpHandlers> <httpRuntime executionTimeout="18000" maxRequestLength="100000"/> <customErrors mode="Off"/> <compilation debug="true" defaultLanguage="c#" /></system.web> <system.webServer> <handlers> <add name="uploader.up_*" path="uploader" verb="*" type="FileUploaderHandler" preCondition="integratedMode,runtimeVersionv2.0"/> <add name="downloader.down_*" path="downloader" verb="*" type="FileDownloaderHandler" preCondition="integratedMode,runtimeVersionv2.0"/> <add name="Delete.del_*" path="Delete" verb="*" type="FileDelete" preCondition="integratedMode,runtimeVersionv2.0"/> </handlers> <security> <authorization> <add accessType="Allow" users="?"/> </authorization> </security> </system.webServer> </configuration>
et voila la page d'appel (ce qu'une page de teste ni plus ni moin)
c 'est une application pour telecharger (upload et supprimer ) des fichiers
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <form id="form2" runat="server" method ="post" action="downloader" > <input type="text" name ="FileName" /> <input id ="button3" type= "submit" value ="fg" /> </form>
mon application marche tres tres bien en IIS 7 mais lorsque j'ai essaie de travailler avec IIS 5.1 j'ai un erreur de type
et merciHTTP 404 - Fichier introuvable
Services Internet (IIS)![]()
Partager