现在想做一个文件资料管理的系统:在服务器上,不同的登录用户有不同的存放文件目录,只有这个登录用户有权限(或者他授权给另一个用户下载)对自己目录下的文件进行下,在服务器上存放的文件格式不定,要求:如果没有登录系统,即使知道文件的服务器路径也不允许下载,如何控制?

解决方案 »

  1.   

    用Cookie验证登录就可以了. 登录后写个cookie,里面放上验证信息,
    然后再HttpModule里,检查请求的路径,然后检查cookie里的验证信息是否正确,
      

  2.   

    问题是如果知道文件路径还是可以下载的,比如: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"]));
          }
        }
      }
    }