Cannot retrieve a querystring parameter.

人盡茶涼 提交于 2019-12-24 00:50:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!