0

I need to pass the ASP.NET Identity UserId as a parameter to a stored procedure, but I'm not sure how to get the ID from a logged in user?

Stored Procedure:

CREATE PROCEDURE [dbo].[GetUserProfile]
@UserId nvarchar(128)
AS
BEGIN
    SELECT Avatar, City, [State]
    FROM UserProfiles
    WHERE UserId = @UserId
END

Stored Procedure call from Repository:

public List<UserModels.UserProfile> GetUserProfile()
{
using (var connection = new SqlConnection(SQLSettings.GetConnectionString()))
{
    return connection.Query<UserModels.UserProfile>("GetUserProfile", commandType: CommandType.StoredProcedure).ToList();
}

}

PixelPaul
  • 2,609
  • 4
  • 39
  • 70
  • Instead of the `UserId`, are you okay to use the `UserName` instead? If you are using ASP.NET MVC, you can get the UserName from within your controller action by using `User.Identity.Name`. – OJ Raqueño Mar 28 '16 at 00:41
  • Thanks @OldProgrammer! I was able to get the ID using response by @peter_the_oak in the link you provided. – PixelPaul Mar 28 '16 at 01:17

0 Answers0