问题
An example of the Request URL: http:\\localhost\ChatWindow.aspx?username=sly_chandan
My webmethod is listed below:
[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();
}
I cannot seem to retrieve the querystring parameter.
回答1:
To get the querystring, you should simply be able to change your method to look like this:
[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();
}
来源:https://stackoverflow.com/questions/7427398/cannot-retrieve-a-querystring-parameter