mosini
شنبه 15 خرداد 1389, 09:38 صبح
سلام دوستان
من وبسایتی دارم که روی IIS محلی خودم با IP valid آپ کردم.کار هم میکنه.ولی مشکلش اینه که اون فایل های (doc و pdf) که برای دانلود گذاشتم کار نمیکنه و خطای روبرو رو میده:
http://www.4shared.com/photo/AYC9KkRK/error.html (http://www.4shared.com/photo/AYC9KkRK/error.html)
توی visual studio هیچ خطایی نمیده و دانلود manager من شروع به دانلود مینکنه ولی روی IIS که میزارم کار نمیکنه.اینو بگم که روی پوشه ای که در WWWROOT قرار دادم مجوز write و read رو گذاشتم باز هم کار نکرد.جالب اینجاست که وقتی نام فایل های دانلود با پسوندشون رو بعد از نام سایت مینویسم ،دانلود شروع میشه.
من برای دانلود از یه httphandler استفاده کردم کد کلاس دانلودم اینه:(البته توی web.config تنظیماتش رو هم انجام دادم)»:فکر میکنید مشکل چیه:(توی فورم http://forums.ASP.NET/p/1565369/3897391.aspx هم گذاشتم،جوابی که دادن خیلی متوجه نشدم)»
using System;
using System.Data;
using System.Configuration;
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;
/// <summary>
/// Summary description for myDownload
/// </summary>
public class myDownload:IHttpHandler
{
public myDownload()
{
//
// TODO: Add constructor logic here
//
}
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
try
{
string filename = context.Request.QueryString["file"];
string path = context.Server.MapPath(filename);
string name = Path.GetFileName(path);
string ext = Path.GetExtension(path);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".htm":
case ".html":
type = "text/HTML";
break;
case ".txt":
type = "text/plain";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
case ".pdf":
type = "Application/pdf";
break;
}
}
context.Response.ContentType = type;
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
string FilePath = context.Server.MapPath(string.Format(@"{0}", filename));
context.Response.WriteFile(FilePath);
context.Response.End();
context.Response.WriteFile(path);
context.Response.End();
}
catch
{
}
//string basePath = context.Server.MapPath("~");
//basePath = Path.Combine(basePath, filename);
//FileStream myStream = new FileStream(basePath, FileMode.Open, FileAccess.Read);
//byte[] buffer = new byte[(int)myStream.Length];
//myStream.Read(buffer, 0, (int)myStream.Length);
//myStream.Close();
//context.Response.Clear();
//context.Response.ContentType = "application/octet-stream";
//context.Response.AddHeader("Content-Length", buffer.Length.ToString());
//context.Response.AddHeader("Content-Disposition", "attachment; filename=" + basePath);
//context.Response.BinaryWrite(buffer);
//context.Response.End();
}
#endregion
}
من وبسایتی دارم که روی IIS محلی خودم با IP valid آپ کردم.کار هم میکنه.ولی مشکلش اینه که اون فایل های (doc و pdf) که برای دانلود گذاشتم کار نمیکنه و خطای روبرو رو میده:
http://www.4shared.com/photo/AYC9KkRK/error.html (http://www.4shared.com/photo/AYC9KkRK/error.html)
توی visual studio هیچ خطایی نمیده و دانلود manager من شروع به دانلود مینکنه ولی روی IIS که میزارم کار نمیکنه.اینو بگم که روی پوشه ای که در WWWROOT قرار دادم مجوز write و read رو گذاشتم باز هم کار نکرد.جالب اینجاست که وقتی نام فایل های دانلود با پسوندشون رو بعد از نام سایت مینویسم ،دانلود شروع میشه.
من برای دانلود از یه httphandler استفاده کردم کد کلاس دانلودم اینه:(البته توی web.config تنظیماتش رو هم انجام دادم)»:فکر میکنید مشکل چیه:(توی فورم http://forums.ASP.NET/p/1565369/3897391.aspx هم گذاشتم،جوابی که دادن خیلی متوجه نشدم)»
using System;
using System.Data;
using System.Configuration;
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;
/// <summary>
/// Summary description for myDownload
/// </summary>
public class myDownload:IHttpHandler
{
public myDownload()
{
//
// TODO: Add constructor logic here
//
}
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
try
{
string filename = context.Request.QueryString["file"];
string path = context.Server.MapPath(filename);
string name = Path.GetFileName(path);
string ext = Path.GetExtension(path);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".htm":
case ".html":
type = "text/HTML";
break;
case ".txt":
type = "text/plain";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
case ".pdf":
type = "Application/pdf";
break;
}
}
context.Response.ContentType = type;
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
string FilePath = context.Server.MapPath(string.Format(@"{0}", filename));
context.Response.WriteFile(FilePath);
context.Response.End();
context.Response.WriteFile(path);
context.Response.End();
}
catch
{
}
//string basePath = context.Server.MapPath("~");
//basePath = Path.Combine(basePath, filename);
//FileStream myStream = new FileStream(basePath, FileMode.Open, FileAccess.Read);
//byte[] buffer = new byte[(int)myStream.Length];
//myStream.Read(buffer, 0, (int)myStream.Length);
//myStream.Close();
//context.Response.Clear();
//context.Response.ContentType = "application/octet-stream";
//context.Response.AddHeader("Content-Length", buffer.Length.ToString());
//context.Response.AddHeader("Content-Disposition", "attachment; filename=" + basePath);
//context.Response.BinaryWrite(buffer);
//context.Response.End();
}
#endregion
}