none
Cookies aus Webservice an Client RRS feed

  • Allgemeine Diskussion

  • Hallo allerseits!

    Ich bin neu hier im Forum und hoffe auf Eure Hilfe.

    Ich bin dabei einen Webservice zu entwickeln, der auch eine Benutzerauthentifizierung integrieren soll. Eigentlich sollte das nicht so schwer sein, nur leider bekomme ich in meiner Client-Anwendung (eine ASP.NET-Seite) die Cookies vom Server nicht zurück.

    Hier mal der Code vom Webservice:

    [code]

    [WebMethod]

    public bool Login(string _username, string _password)

    {

    //ToDo: Find user in table and verify password and login

    string strRole = AuthenticateUser(_username, _password);

    if (strRole != null)

    {

    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(

    1, // version

    _username, // user name

    DateTime.Now, // create time

    DateTime.Now.AddMinutes(30), // expire time

    false// persistent

    strRole); // user data

    string strEncryptedTicket = FormsAuthentication.Encrypt(ticket);

    HttpCookie cookie = new HttpCookie("a", strEncryptedTicket); //FormsAuthentication.FormsCookieName, strEncryptedTicket);

    Context.Response.Cookies.Add(cookie);

    return true;

    }

    else

    {

    return false;

    }

    }

    [/code]

    Und hier noch der Code vom Client (in der global.asax):

    [code]

    protected void Application_AuthenticateRequest(object sender, EventArgs e)

    {

    try

    {

    HttpCookie authenCookie = Context.Request.Cookies.Get("a"); //FormsAuthentication.FormsCookieName);

    if (authenCookie == nullreturn;

    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authenCookie.Value);

    FormsIdentity id = new FormsIdentity(ticket);

    string[] astrRoles = ticket.UserData.Split(new char[] { ',' });

    GenericPrincipal principal = new GenericPrincipal(id, astrRoles);

    Context.User = principal;

    }

    catch (Exception ex)

    {

    System.IO.StreamWriter wr = new System.IO.StreamWriter(Context.Request.MapPath("log.txt"));

    wr.WriteLine(ex.Message);

    wr.Close();

    }

    }

    [/code]

     

    Im Request-Objet ist die Cookies-Collection immer leer. Hat jemand eine Ahnung was das sein kann?

    Vielen Dank im Voraus

    Markus

    • Typ geändert Stefan FalzModerator Dienstag, 11. März 2014 20:42 Thread ohne bestätigte Lösung abgeschlossen
    Freitag, 27. September 2013 05:46

Alle Antworten