请求网址的示例:http:\\localhost\ChatWindow.aspx?username=sly_chandan
我的网络方法如下:
[WebMethod(EnableSession = true)]
public static List<PrivateMessage> GetMessages()
{
List<PrivateMessage> getMsgsList = (List<PrivateMessage>)HttpContext.Current.Application["PrivateMessages"];
var msgs = getMsgsList.Where(x => x.fromUsername == HttpContext.Current.Session["Username"].ToString() && x.toUsername == HttpContext.Current.Request.QueryString["username"]);
return msgs.ToList();
}
我似乎无法检索查询字符串参数。
答案 0 :(得分:1)
要获取查询字符串,您应该只需将方法更改为:
[WebMethod(EnableSession = true)]
public static List<PrivateMessage> GetMessages(string username)
{
List<PrivateMessage> getMsgsList = (List<PrivateMessage>)HttpContext.Current.Application["PrivateMessages"];
var msgs = getMsgsList.Where(x => x.fromUsername == HttpContext.Current.Session["Username"].ToString() && x.toUsername == username;
return msgs.ToList();
}