文件下载控制 现在想做一个文件资料管理的系统:在服务器上,不同的登录用户有不同的存放文件目录,只有这个登录用户有权限(或者他授权给另一个用户下载)对自己目录下的文件进行下,在服务器上存放的文件格式不定,要求:如果没有登录系统,即使知道文件的服务器路径也不允许下载,如何控制? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用Cookie验证登录就可以了. 登录后写个cookie,里面放上验证信息,然后再HttpModule里,检查请求的路径,然后检查cookie里的验证信息是否正确, 问题是如果知道文件路径还是可以下载的,比如:http://192.168.1.122/wangwu/22.rar我已经在HttpModule里做了验证还是不行namespace Myyz{ public class yz1 : IHttpModule { public void Dispose() { } public void Init(HttpApplication context) { context.AcquireRequestState += new EventHandler(context_AcquireRequestState); } void context_AcquireRequestState(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender;// 获取应用程序 string Curl = application.Request.Url.ToString(); //当前访问的连接 string Cname = Curl.Substring(Curl.LastIndexOf('/') + 1);//访问的文件名 string Clx = Cname.Substring(Cname.LastIndexOf('.') + 1).ToUpper();//获取文件的后缀 if (Clx == "RAR" || Clx == "DOC" || Clx == "XLS") //禁止下载的文件格式,可是不成功 { application.Server.Transfer("Error.aspx"); application.Response.End(); return; } // 检查用户是否已经登录 if (application.Context.Session["UserName"] == null || application.Context.Session["UserName"].ToString().Trim() == "") { string requestUrl = application.Request.Url.ToString();// 获取Url string requestPage = requestUrl.Substring(requestUrl.LastIndexOf('/') + 1); // 如果请求的页面不是登录页面,重定向到登录页面。 if (requestPage != "Default.aspx") application.Server.Transfer("Default.aspx"); } else { // 已经登录,向每个请求的页面打印欢迎词。 application.Response.Write(string.Format("欢迎您!{0}!", application.Context.Session["UserName"])); } } }} gridview 比较错综复杂的问题 falsh 缓存问题······· 用c#怎么探测到 一台主机上跑了几个虚机呢,并取得虚机的相关信息 导出问题 如何设置StreamWriter的编码为UTF-8? 怎么屏蔽一个网址啊? 急:Label 控件的文字能够换行且居中显示? 【求助】关于Asp.net页面间传递参数的问题 湖 南 信 息 港 诚 聘 英 才 网站经常出现超时的问题,高手请进,送分了 ##### provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接 下载文件,在本地调试没有任何问题,但一发布后,只弹出一个窗口闪一下,请教各位.
然后再HttpModule里,检查请求的路径,然后检查cookie里的验证信息是否正确,
{
public class yz1 : IHttpModule
{
public void Dispose()
{ } public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
} void context_AcquireRequestState(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;// 获取应用程序
string Curl = application.Request.Url.ToString(); //当前访问的连接
string Cname = Curl.Substring(Curl.LastIndexOf('/') + 1);//访问的文件名
string Clx = Cname.Substring(Cname.LastIndexOf('.') + 1).ToUpper();//获取文件的后缀 if (Clx == "RAR" || Clx == "DOC" || Clx == "XLS") //禁止下载的文件格式,可是不成功
{
application.Server.Transfer("Error.aspx");
application.Response.End();
return;
}
// 检查用户是否已经登录
if (application.Context.Session["UserName"] == null || application.Context.Session["UserName"].ToString().Trim() == "")
{
string requestUrl = application.Request.Url.ToString();// 获取Url
string requestPage = requestUrl.Substring(requestUrl.LastIndexOf('/') + 1);
// 如果请求的页面不是登录页面,重定向到登录页面。
if (requestPage != "Default.aspx")
application.Server.Transfer("Default.aspx");
}
else
{
// 已经登录,向每个请求的页面打印欢迎词。
application.Response.Write(string.Format("欢迎您!{0}!", application.Context.Session["UserName"]));
}
}
}
}