I am using the formauthentication and as the user.identity.name I am using they're email, How can I change it to were I can use they're unique Registration ID instead?
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,model.Email, DateTime.Now, cookieExpiration, true,model.Email);
The model.Email is the Email that the users have and its a String parameter I instead would like to put model.RegistrationID .
You can't change its data type but you can do what you want by keeping the RegistrationId in the database as string.
FormsAuthenticationTicket ticket= new FormsAuthenticationTicket(RegistrationId.ToString() ,model.Email, DateTime.Now,cookieExpiration, true,model.Email);
Related
Entity contact = new Entity("contact");
contact.Attributes.Add("fullname", "h api test");
contact.Attributes.Add("emailaddress1", "hh#devenv1.local");
contact.Attributes.Add("telephone1", "1");
contact.Attributes["parentcusotmerid"] = new EntityReference("Organization", );
Guid contactId = m_OrgServ.Create(contact);
Console.WriteLine(contactId);
The lookup field I want to set
The logicalname of the lookup field is parentcusotmerid, and
m_OrgSerc.create
is basically
Service.create
I am setting attribute values for the fields, it works fine for normal text boxes where I am entering values, however for lookup values it doesn't work. I know lookup fields are of type EntityReference, so I need to know the LogicalName of the entity the lookup is pointing and the Id of the record.
I have tried it but its asking for the GUID of the Organization field now, so I'm not sure if I am going about it the right way?
You cannot set "parentcustomerid" to organization. It's special reference field that takes either Account or Contact entity reference as parameter.
If you want to set it you go like this
contact.Attributes["parentcusotmerid"] = new EntityReference("account", Guid.NewGuid());
or
contact.Attributes["parentcusotmerid"] = new EntityReference("contact", Guid.NewGuid());
where Guid.NewGuid() is Guid of your Account or Contact that you want to reference
I am trying to add a annotation via code and the annotation adds fine but it won't add the correct CreatedBy user. It just adds the annotation and sets the createdby user to the admin. This is what I am using:
Entity annotation = new Entity("annotation");
annotation["createdby"] = new EntityReference("systemuser", new Guid("2a213502-db00-e111-b263-001ec928e97f"));
annotation["objectid"] = new EntityReference("opportunity", opportunityId);
annotation["subject"] = "Lead Note";
annotation["notetext"] = p.Column_18;
Guid annotationId = lService.Create(annotation);
Do you have to do anything special to add the CreatedBy?
Thanks!
You cannot set createdby in Create or Update. See the description for the attribute createdby. It is not valid for Create or Update. The system will set this attribute to the user which is executing the current request.
You have to use impersonation to create a record in the name of another user. Therefore you have to set the CallerId property to the id of the user which identity you would like to impersonate. See Impersonate Using the ActOnBehalfOf Privilege
I hope i'm not bithering with my many questions...
i'm creating users in the ASPNETDB.MDF database with the asp.net configuration.
i have a client MVC, and i want when a client is created, edited, or deleted, it must dispaly the user_name and last_user_name of the user that performed the action. These two properties r in the client model. i want my controller to only deal with the ID(PK) of the users, and not their names. I only know how to make the controller work with the user names. How do i ensure that any functionality is done with the id but the display is the user_name? Here is my create method in my clientcontroller
[Authorize]
public ActionResult Create()
{
var model = new title
{
create_dt = DateTime.Now,
last_maint_dt = DateTime.Now,
row_version = 1,
status = "ACTIVE",
user_id = System.Web.HttpContext.Current.User.Identity.Name,
last_user_id = System.Web.HttpContext.Current.User.Identity.Name
};
return View(model);
}
If you are using the default ASP.NET Membership Provider you can find the user GUID for an account by accessing System.Web.Security.Membership. Then you can use the GetUser() method and pass it the username as an argument.
//Get Current User ID
var user = System.Web.Security.Membership.GetUser(User.Identity.Name);
if (user != null)
{
string id = user.ProviderUserKey.ToString();
}
And if you have the GUID and want the Username
var user = System.Web.Security.Membership.GetUser(id);
if (user != null)
{
string username = user.UserName;
}
i have a project that use MVC3. in my project, i have a page that user can edit their account (UserComment, UserEmail, IsLocked, IsApproved). i already make the View for Edit Account. i have some trouble to make the Edit Controller.
here's my code:
[HttpPost]
public ActionResult Edit(string id, FormCollection collection)
{
id = id.Replace("+", " ");
var user = Membership.GetUser();
Guid UserGUID = new Guid(user.ProviderUserKey.ToString());
var SysUser = db.System_User.Single(u => u.User_UserId == UserGUID);
//this is for updating User Office in my System_user table
SysUser.User_Office = collection["SysUsers[0].UserOffice"];
//this is for updating User Account in aspnet_membership table
user.UserName = collection["SysUsers[0].UserName"];
Membership.UpdateUser(user);
user.Comment = collection["SysUsers[0].UserComment"];
Membership.UpdateUser(user);
user.Email = collection["SysUsers[0].UserEmail"];
Membership.UpdateUser(user);
return View();
}
when i run my controller, i get some error like :
user.UserName is read only, i cant update this one.
i get user.Comment value, but its not update.
i get error in my Edit View, it says "Object reference not set to an instance of an object."
#using (Html.BeginForm("edit/" + #Model.SysUsers[0].UserID, "cpanel/sysuser", FormMethod.Post))
can anyone help me ?
thanks,
You cannot update the UserName of a user using ASP.NET Membership provider. You need to write some custom data access logic if you wish to update a username.
I would suggest using the Membership Provider primarily for authentication and build all the other maintenance etc. methods into your User's business objects.
i know how to get userid for a current user
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
But for my application i need to get userid of user who are not loginned in also.
Because i need to assign the userid to different table which i m using.
Thank you in Advance
Use the Membership.GetUser(username, userIsOnline) method, passing false as the userIsOnline parameter.