.ASPX是一个脚本页面,所以你实际上不能下载原始的ASPX。另一端的IIS服务器有.aspx的处理程序,导致.NET处理它。通常,您不希望服务器返回原始ASPX源代码。
它需要在服务器端进行特殊处理才能获得原始的ASPX页面。例如,你可以创建一个ASHX脚本处理程序,它可以为你提供这个脚本处理程序,你可以请求类似getfile.ashx?filename=myfile.aspx
的东西,并且getfile.ashx处理程序会从磁盘读取ASPX页面并将其作为响应写入。 (安全注意事项:如果这是您选择的路线,请确保清理指定的页面,以免它们做像getfile.ashx?filename=C:\my\secret\file.txt
这样的傻事)。将处理程序的信任级别设置为中或更低会更好。
但这一切都需要服务器端的开发。从客户端来看,在服务器想要玩游戏之前,没有什么可以做的。
下面是一个文件处理程序的一个示例:
public class MyHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
var file = context.Request.QueryString["file"];
//Make sure to do your security checks on the file path here.
using (var source = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
{
source.CopyTo(context.Response.OutputStream);
}
}
}
,可以设定处理程序或者内部的ASHX的或通过在web.config的httpHandlers
部。
或者,如果你正在使用MVC2 +,你并不需要一个HTTP处理程序,你可以只使用一个动作来实现同样的事情:
public ActionResult GetFile(string path)
{
//Make sure to do your security checks
using (var source = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return File(source, "text/html");
}
}
为什么这标志着下来?看起来像一个公平和明确的问题。 – Urbycoz 2011-06-06 07:37:43