如何将ASP.NET标识UserId传递给存储过程

时间:2016-03-28 00:32:30

标签: c# asp.net sql-server stored-procedures asp.net-identity

我需要将ASP.NET Identity UserId作为参数传递给存储过程,但我不确定如何从登录用户获取ID?

存储过程:

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

来自存储库的存储过程调用:

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

}

0 个答案:

没有答案