标签:
今天在做后台管理系统的无刷新左侧菜单,遇到两个难题:
1、怎么将数据表中的菜单项按树形结构进行层次性的查询?群里有人给我指点说用CTE递归查询,我还没搞明白。
2、要做左侧导航栏的根据用户权限的无刷新加载时,要用到AJAX,那么就要在ashx一般处理程序中取得Session["UserID"]的值,但是ashx中是不能用Session的,之后找到一篇文章,指出:若要在ashx中使用Session和Request需要引入一个接口。
有三点需要注意:
1.命名空间中要加入using System.Web.SessionState;
2.接口名要加入IRequiresSessionState或IReadOnlySessionState;
3.不管是Session还是QueryString都要通过HttpContext来获取。
具体代码如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<%@ WebHandler Language="C#" Class="UploadHandler" %>using System;using System.IO;using System.Net;using System.Web;using System.Web.SessionState;public class UploadHandler : IHttpHandler, IRequiresSessionState{ public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; string str1 = context.Session["aaa"].ToString(); string str2 = context.Request.QueryString["bbb"].ToString(); } public bool IsReusable { get { return false; } }} |
今天在做后台管理系统的无刷新左侧菜单,遇到两个难题:(CTE递归查询、ashx+Session[])
标签:
原文地址:http://www.cnblogs.com/haust/p/4314692.html