Domanda

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?

È stato utile?

Soluzione 2

Best thing todo is to create a second table (or add a column to the current table), add a file upload feature to the registration form. When registration is successful add the picture to the db with EntityFramework. Create a page to return the picture by the userid so you can include it in a page somewhere.

Something like this http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx but with a profile picture

Altri suggerimenti

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; }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top