Creating User in dotnetnuke and Assign Role using c# -
i'm trying create user programatically using c# in dnn. when ever execute code below, throws object reference error. tried breaking code , found out not getting inside if (result == usercreatestatus.success)
statement. whenever point mouse result instant, shows invalid password message. thing have used same code before somewhere else , working fine. copied used earlier on keeps showing same error. please there i'm missing?
//generating 8 char passwor random adomrng = new random(); string rndstring = string.empty; char c; (int = 0; < 8; i++) { while (!regex.ismatch((c = convert.tochar(adomrng.next(48, 128))).tostring(), "[a-za-z0-9]")) ; rndstring += c; } string space = " "; userinfo ouser = new userinfo(); ouser.portalid = this.portalid; ouser.issuperuser = false; ouser.firstname = session["fname"].tostring(); ouser.lastname = session["lname"].tostring(); ouser.email = session["email"].tostring(); ouser.username = session["username"].tostring(); ouser.displayname = session["fname"].tostring() + space.tostring() + session["lname"].tostring(); //fill minimum profile items (key piece) ouser.profile.preferredlocale = portalsettings.defaultlanguage; //ouser.profile.preferredtimezone =portalsettings.timezoneoffset; ouser.profile.firstname = ouser.firstname; ouser.profile.lastname = ouser.lastname; //set membership 17: usermembership onewmembership = new usermembership(); onewmembership.approved = true; onewmembership.createddate = system.datetime.now; onewmembership.email = ouser.email; onewmembership.isonline = false; onewmembership.username = ouser.username; onewmembership.password = rndstring; usercreatestatus result = usercontroller.createuser(ref ouser); if (result == usercreatestatus.success) { rolecontroller odnnrolecontroller = new rolecontroller(); //get role information roleinfo ocurrentrole = odnnrolecontroller.getrolebyname(this.portalid, request.querystring["tsorole"].tostring()); // roleinfo ocurrentrole1 = odnnrolecontroller.getrolebyname(this.portalid, " subscribers"); //assign user odnnrolecontroller.adduserrole(this.portalid, ouser.userid, ocurrentrole.roleid, null.nulldate, null.nulldate); // odnnrolecontroller.deleteuserrole(this.portalid, int.parse(ouser.userid.tostring()), ocurrentrole.roleid); }
the reason why same code works 1 , not other different password rules these websites. make sure generating password complies password requirements of target website.
Comments
Post a Comment