asp.net - How Authenticate by WebMethod -


i passed username , pass webmethod in .aspx page ajax in json format, want authenticate users , redirect user same page , update loginview logedin state;

how can it? here's webmethod

[webmethod]     // [ [system.web.script.services.scriptmethod(responseformat = responseformat.json, usehttpget=false)]     public static void login(object mydata)     {          javascriptserializer js = new javascriptserializer();         list<nameval> myfrm = js.deserialize<list<nameval>>(mydata.tostring());       //  membershipuser u = membership.getuser(myfrm.singleordefault(rs=>rs.name=="username").value);          if (  membership.validateuser(myfrm[0].value,myfrm[1].value))         {             formsauthentication.authenticate(myfrm[0].value, myfrm[1].value);             //formsauthentication.redirectfromloginpage(myfrm[0].value, false);              formsauthenticationticket tkt;             string cookiestr;             httpcookie ck;             tkt = new formsauthenticationticket(1, myfrm[0].value, datetime.now,             datetime.now.addminutes(30), true, "my custom data");             cookiestr = formsauthentication.encrypt(tkt);             ck = new httpcookie(formsauthentication.formscookiename, cookiestr);              ck.path = formsauthentication.formscookiepath;              //  ******* must somthing this: -->  response.cookies.add(ck);             // im in static method don't have respons request objects             // want respons in json form , proccess json              // return "success";         }         else         {             //return "faild";         }      } 

so tanks

you can following:

formsauthentication.setauthcookie(myfrm[0].value, createpersistentcookie: false); return formsauthentication.getredirecturl(user.name, false); 

and in javascript:

var onsuccess = function (result) {    if (result === null) {       // login failed       return;    }    window.location.href = result; };  pagemethods.login(mydata, onsuccess); 

this unfortunately still has "silent" threadabortexception can't seem rid of, doesn't seem cause problems. think it's unavoidable , benign.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -