Red de conocimiento informático - Conocimiento del nombre de dominio - ¡Tengo prisa y no puedo descargar el archivo descargado por asp.net a IIS!

¡Tengo prisa y no puedo descargar el archivo descargado por asp.net a IIS!

Modificar web.config //ruta relativa al directorio de descarga

lt; add key="UploadPath" value="/Security/Uploads" /gt;

/Ruta virtual del directorio de descarga

lt; agregar clave="DownloadURL" value="http://localhost/downloads" /gt;

//nombre de usuario de Windows

lt; "BasicAuthenticationUser" value=" administrador" /gt;

//contraseña de usuario de Windows

lt; agregar clave="BasicAuthenticationPWD" value="admin$123" /gt;

3.IO;

seguridad del espacio de nombres

{

//// lt;RESUMENgt;<

// /lt;/SUMMARYgt;

clase pública SecureFile

{

pública SecureFile()

{

}

public bool UploadFile( HtmlInputFile archivo de entrada)

{

intente

{

string fileName = " ";

cadena DirPath = "";

if (( inputfile.if (( inputfile.PostedFile ! = null ) amp; amp;

( inputfile .PostedFile.ContentLength > 0 ))

{

DirPath = HttpContext.Current.Server.MapPath(

System.Configuration.ConfigurationSettings.AppSettings [

"UploadPath"]);

fileName = System.IO.Path.GetFileName(

inputfile.PostedFile.FileName

inputfile); .PostedFile.SaveAs( DirPath "UploadPath");

DirPath = HttpContext.Current.Server.MapPath(

System.Configuration.ConfigurationSettings.Configuration.ConfigurationSettings.AppSettings[

"BasicAuthenticationPWD"];

string strURL=strDownloadURL "\\\\" strFile

WebClie;

nt req=new WebClient();

CredentialCache mycache=new CredentialCache();

mycache.Add(new Uri(strURL))Add(new Uri(strURL), "Básico ",

nueva NetworkCredential(strUser, strPWD));

req.Credentials=mycache;

respuesta HttpResponse = HttpContext.AddHeader("Disposición de contenido" ,

"adjunto; nombre de archivo=\"" strFile "\"");

byte[] data=req.DownloadData(strURL); .BinaryWrite(datos);

respuesta.End();

devuelve verdadero

}

captura (Excepción ex)

{

if(ex.Message== "El servidor remoto "

"devolvió un error: (404) No encontrado.")

throw new Exception("Archivo no encontrado");

else if(ex.Message=="El servidor remoto"

"devolvió un error: (401) No autorizado ."")

throw new Exception("Acceso no autorizado");

return false;

}

}

}

}