2011-09-15 31 views
2

请求URL的一个例子:http:\\localhost\ChatWindow.aspx?username=sly_chandan无法检索查询字符串参数。

我的WebMethod如下表所示:

[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

也许你的意思||代替 && – onof

回答

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(); 
}