【问题标题】:Restrict direct file access of our attachment folder限制对附件文件夹的直接文件访问
【发布时间】:2012-12-17 13:10:54
【问题描述】:

我们有这个网站,我们还有一个签证申请模块。签证申请模块需要用户创建一个账户。每当用户上传附件时,它都会保存在附件内的特定文件夹中。此特定文件夹对应于分配给每个用户的唯一生成的数字。

现在我需要的是,如果用户没有登录,他们应该无法访问附件文件夹中的文件。

如何使用 http 处理程序实现这一点?

我有这个代码

if (HttpContext.Current.Session["UserRegistrationID"] != null)
            {
                if (HttpContext.Current.Session["UserRegistrationID"].ToString() != "")
                {
                    DownloadFile(context);
                }
                else
                {
                    context.Response.Write("You don't have the rights to access this file.");
                    context.Response.Flush();
                }
            }
            else
            {
                context.Response.Write("You don't have the rights to access this file.");
                context.Response.Flush();
            }

protected void DownloadFile(HttpContext context)
        {

        context.Response.ContentType = "image/jpg";
        context.Response.WriteFile(context.Request.PhysicalPath);
        context.Response.Flush();
    }

但问题是我在 web config 中配置它时遇到问题。

有人知道怎么做吗?

【问题讨论】:

    标签: c# asp.net iis-7 web-config generic-handler


    【解决方案1】:

    看看我的一个答案

    How to restrict unlogged unauthorized users from viewing web pages in asp net

    此规则实际上适用于文件夹,正是您要查找的内容。

    【讨论】:

      猜你喜欢
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      • 2016-05-05
      相关资源
      最近更新 更多