几个问题.防盗链 获取目录的大小.excel权限 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 防止盗链下载问题 经常在网络上四处载东西,有时碰到直接拷贝一个类似http://193.100.100.56/TestWebSolution/WebApplication1/test.rar地址准备下载test.rar文件时,却被告知没有登录或者直接跳转到其他页面的情况,然后等登录后直接下载该文件。要实现上面情况,在.NET世界里是比较容易的。1、 首先创建一个类库项目ClassLibrary1,实现如下(点这里查看):using System;using System.Web; // 引用System.Web组件 namespace ClassLibrary1{ public class MyHandler : IHttpHandler { public MyHandler() { } #region IHttpHandler 成员 public void ProcessRequest(HttpContext context) { // 跳转到WebForm1.aspx,由WebForm1.aspx输出rar文件 HttpResponse response = context.Response; response.Redirect("http://193.100.100.56/TestWebSolution/WebApplication1/WebForm1.aspx"); } public bool IsReusable { get { // TODO: 添加 MyHandler.IsReusable getter 实现 return true; } } #endregion }} 2、 创建测试用的Web项目WebApplication1。在配置文件Web.config文件节点里增加如下节点: <httpHandlers> <add verb="*" path="*.rar" type="ClassLibrary1.MyHandler, ClassLibrary1" />httpHandlers> 3、 在WebForm1.aspx里增加一个文本为“下载”的Button,其Click事件如下(点这里查看):FileInfo file = new System.IO.FileInfo(@"G:\WebCenter\TestWebSolution\WebApplication1\test.rar");// FileInfo 类在 System.IO 命名空间里 Response.Clear(); Response.AddHeader("Content-Disposition", "filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); string fileExtension = file.Extension; // 根据文件后缀指定文件的Mime类型 switch (fileExtension) { case ".mp3": Response.ContentType = "audio/mpeg3"; break; case "mpeg": Response.ContentType = "video/mpeg"; break; case "jpg": Response.ContentType = "image/jpeg"; break; case "........等等": Response.ContentType = "...."; break; default: Response.ContentType = "application/octet-stream"; break; } Response.WriteFile(file.FullName); Response.End(); 4、 最后一步就是在IIS里增加一个应用程序扩展。在“默认网站”->“属性”->“主目录”->“配置”。在弹出的“应用程序配置”窗口里按“添加”,在弹出的“添加/编辑应用程序扩展名映射”窗口里“可执行文件”选择C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,在扩展名里输入“.rar”,然后确定即可。 5、 在IE里输入http://193.100.100.56/TestWebSolution/WebApplication1/test.rar,会立即跳转到http://193.100.100.56/TestWebSolution/WebApplication1/WebForm1.aspx,然后按WebForm1.aspx的“下载”按钮就可以下载test.rar了。 6、 当然,这里只按例子给个思路,完全可以再根据自身情况扩展。下面有几个参考的资源文章:l http://www.9seek.com/news/show.aspx?id=745&cid=12l http://www.9seek.com/news/show.aspx?id=521&cid=12l http://www.9seek.com/news/show.aspx?id=520&cid=12l http://msdn.microsoft.com/asp.net/using/building/web/default.aspx?pull=/library/en-us/dnaspp/html/URLRewriting.asp //获取目录大小 using System.IO;public static long DirSize(DirectoryInfo d) { long Size = 0; // Add file sizes. FileInfo[] fis = d.GetFiles(); foreach (FileInfo fi in fis) { Size += fi.Length; } // Add subdirectory sizes. DirectoryInfo[] dis = d.GetDirectories(); foreach (DirectoryInfo di in dis) { Size += DirSize(di); } return(Size); } Excel权限不知道 你指什么?首先确保你有足够的权限,开始-运行:dcomcnfg在应用程序列表框中选择“Microsoft Excel 应用程序”->“安全性”->选择“使用自定义访问权限”,点击“编辑”按钮添加本地“ASPNET”用户,权限为 允许访问 asp.net 2.0 防盗链http://www.cnblogs.com/jackyrong/archive/2007/05/13/744961.html 老大的 MSN/QQ 是好多呢? 生成动态表格时超连接的onclick怎么添加? Fckeditor做新闻发布问题 对不齐了.求助呀! 后台怎么改变客户端css的className呢 【高分100分,不够再加】关于编辑器中未闭合标签的问题 gridview动态生成模板的问题 一个奇怪的问题,SESSION丢失问题。 100分求教高手解答关于在c#中调用vb.net中的StrConv函数 每次按 F5运行程序时出现:无法将文件“bin\dtmis.dll”复制到运行目录。 请问正则表达式中“数字.数字(1位)“,如何写。 进参问题!请高手来帮这看看!不够+分!顶这有分! 用.NET开发大型的门户网站哪位能提供一个整体的思路吗?
经常在网络上四处载东西,有时碰到直接拷贝一个类似http://193.100.100.56/TestWebSolution/WebApplication1/test.rar地址准备下载test.rar文件时,却被告知没有登录或者直接跳转到其他页面的情况,然后等登录后直接下载该文件。要实现上面情况,在.NET世界里是比较容易的。1、 首先创建一个类库项目ClassLibrary1,实现如下(点这里查看):using System;using System.Web; // 引用System.Web组件 namespace ClassLibrary1{ public class MyHandler : IHttpHandler { public MyHandler() { } #region IHttpHandler 成员 public void ProcessRequest(HttpContext context) { // 跳转到WebForm1.aspx,由WebForm1.aspx输出rar文件 HttpResponse response = context.Response; response.Redirect("http://193.100.100.56/TestWebSolution/WebApplication1/WebForm1.aspx"); } public bool IsReusable { get { // TODO: 添加 MyHandler.IsReusable getter 实现 return true; } } #endregion }}
2、 创建测试用的Web项目WebApplication1。在配置文件Web.config文件节点里增加如下节点: <httpHandlers> <add verb="*" path="*.rar" type="ClassLibrary1.MyHandler, ClassLibrary1" />httpHandlers> 3、 在WebForm1.aspx里增加一个文本为“下载”的Button,其Click事件如下(点这里查看):FileInfo file = new System.IO.FileInfo(@"G:\WebCenter\TestWebSolution\WebApplication1\test.rar");// FileInfo 类在 System.IO 命名空间里 Response.Clear(); Response.AddHeader("Content-Disposition", "filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); string fileExtension = file.Extension; // 根据文件后缀指定文件的Mime类型 switch (fileExtension) { case ".mp3": Response.ContentType = "audio/mpeg3"; break; case "mpeg": Response.ContentType = "video/mpeg"; break; case "jpg": Response.ContentType = "image/jpeg"; break; case "........等等": Response.ContentType = "...."; break; default: Response.ContentType = "application/octet-stream"; break; } Response.WriteFile(file.FullName); Response.End();
4、 最后一步就是在IIS里增加一个应用程序扩展。在“默认网站”->“属性”->“主目录”->“配置”。在弹出的“应用程序配置”窗口里按“添加”,在弹出的“添加/编辑应用程序扩展名映射”窗口里“可执行文件”选择C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,在扩展名里输入“.rar”,然后确定即可。 5、 在IE里输入http://193.100.100.56/TestWebSolution/WebApplication1/test.rar,会立即跳转到http://193.100.100.56/TestWebSolution/WebApplication1/WebForm1.aspx,然后按WebForm1.aspx的“下载”按钮就可以下载test.rar了。 6、 当然,这里只按例子给个思路,完全可以再根据自身情况扩展。下面有几个参考的资源文章:l http://www.9seek.com/news/show.aspx?id=745&cid=12l http://www.9seek.com/news/show.aspx?id=521&cid=12l http://www.9seek.com/news/show.aspx?id=520&cid=12l http://msdn.microsoft.com/asp.net/using/building/web/default.aspx?pull=/library/en-us/dnaspp/html/URLRewriting.asp
public static long DirSize(DirectoryInfo d)
{
long Size = 0;
// Add file sizes.
FileInfo[] fis = d.GetFiles();
foreach (FileInfo fi in fis)
{
Size += fi.Length;
}
// Add subdirectory sizes.
DirectoryInfo[] dis = d.GetDirectories();
foreach (DirectoryInfo di in dis)
{
Size += DirSize(di);
}
return(Size);
}
在应用程序列表框中选择“Microsoft Excel 应用程序”->
“安全性”->选择“使用自定义访问权限”,点击“编辑”按钮
添加本地“ASPNET”用户,权限为 允许访问