Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User profile image asp.net mvc identity

I'm creating a web application using MVC 5 and Identity. I have so far created a registration system, but I would like to allow users to upload a profile when they register.

I was wondering if it is possible to implement profile pictures with asp.net identity?

like image 373
Dolaps Avatar asked Jan 12 '23 06:01

Dolaps


1 Answers

Yes. Assuming you're using the default Entity Framework implementation, you can extend the ApplicationUser in a file called Models/IdentityModels.cs.

You can store the image in the database or elsewhere on the file system.

One way to store it in the database is using a byte array in the model (which I believe maps to varbinary(max))...

public class ApplicationUser : IdentityUser
{
    public byte[] Image { get; set; }
}

Details on how to save upload an image and save in the database via EF can be found here... Entity Framework 5 Code first adding an image

Or you can simply save the uploaded file to the file system or to blob storage, then store the path or URL to the image...

public class ApplicationUser : IdentityUser
{
    public string ImagePath { get; set; }
}
like image 82
Anthony Chu Avatar answered Jan 31 '23 05:01

Anthony Chu