ASP.NET笔记之 图库权限设置的方法

2019-05-20 08:45:27王冬梅

    }
}
/*出现错误:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。
 * 未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。
 * (provider: SQL Network Interfaces, error: 26 - 定位指定的服务器/实例时出错)
 *
 * 解决:
*/

下载列表页面:Pic_list.htm

<a href="Pic_download.ashx?fileName=11.jpg">图片1</a>
<a href="Pic_download.ashx?fileName=11.jpg">图片2</a>
<a href="Pic_download.ashx?fileName=11.jpg">图片3</a>

下载列表页面:Pic_download.ashx
using System.Linq;
using System.Web;
using 图片下载.DAL.DataSetPicTableAdapters;
using System.Web.SessionState;
using System.Drawing;

namespace 图片下载
{
    /// <summary>
    /// Pic_download 的摘要说明
    /// </summary>
    public class Pic_download : IHttpHandler,IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Session["是否登陆"] == null)
            {
                context.Response.Redirect("Target.htm");
            }
            else {
                string fileName = context.Request["fileName"];

                //报头
                context.Response.ContentType="image/JPEG";
                string newFileName = HttpUtility.UrlEncode(fileName);
                context.Response.AddHeader("Content-Disposition", "attachment:filename=" + newFileName);

                //根据ID获取数据
                int user_id = (int)context.Session["登陆的ID"];
                T_userInfoTableAdapter adapter = new T_userInfoTableAdapter();
                var data = adapter.GetDataById(user_id);
                var user = data.Single();