简体   繁体   中英

C# app and asp.NET session

I try build client-base desktop app using webservices. I have problem when I try send List through session. Even though the session was created, when reference back to session no longer exists.

[WebMethod(EnableSession = true)]
public void dodajdolisty(string login) {
    bool jest = false;

    if (Session["uzytkownicy"] != null) {
        listaOsob = (List<string>)Session["uzytkownicy"];

        foreach (string s in listaOsob) {
            if (s == login) { jest = true; break; }
        }

        if (! jest) {
            listaOsob.Add(login);
            Session["uzytkownicy"] = listaOsob;
        }
    }
    else {
        listaOsob.Add(login);
        // the debugger shows that the session has been created
        Session["uzytkownicy"] = listaOsob;
    }
}

public List<string> pobierzzlisty() {
    List<string> list = new List<string>();
    list = (List<string>)Session["uzytkownicy"]; // session is null

    return list;
} // null

How can I fix this?

I think you missed to add cookiecontainer on client app, try this

MyWebService ws= new MyWebService();
ws.CookieContainer = new System.Net.CookieContainer(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM