Today in the background management system does not refresh the left menu, encountered two challenges:
1. How to query the menu items in the data table hierarchically by tree structure? I was told by someone in the group to use the CTE recursive query, I still do not understand.
2, to do the left navigation bar according to the user permissions of the non-flush load, to use Ajax, then the general processing program in ASHX to obtain the value of session["UserID", but ASHX is not used session, and then found an article, Point out: To use session and request in ashx, you need to introduce an interface.
Use session and QueryString in the Ashx file
There are three points to note:
1. The using System.Web.SessionState should be added to the namespace;
2. Interface name to join IRequiresSessionState or ireadonlysessionstate;
3. Both the session and the QueryString are acquired through HttpContext.
The specific code is as follows:
1234567891011121314151617181920212223242526 |
<%@ 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
;
}
}
}
|
Today in the background management system does not refresh the left menu, encountered two challenges: (CTE recursive query, ashx+session[])