Не удалось получить параметр строки запроса. - PullRequest
2 голосов
/ 15 сентября 2011

Пример URL-адреса запроса: 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();
}

Мне не удается получить параметр строки запроса.

1 Ответ

1 голос
/ 15 сентября 2011

Чтобы получить строку запроса, вы должны просто изменить свой метод так, чтобы он выглядел следующим образом:

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