Files
emall-api/FutureMailAPI/Extensions/HttpContextExtensions.cs
2025-10-16 15:21:52 +08:00

23 lines
732 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.AspNetCore.Mvc;
namespace FutureMailAPI.Extensions
{
public static class HttpContextExtensions
{
/// <summary>
/// 获取当前用户ID简化版本不再依赖token
/// </summary>
public static int? GetCurrentUserId(this HttpContext context)
{
// 简化实现从查询参数或表单数据中获取用户ID
// 在实际应用中,这里应该使用会话或其他认证机制
if (context.Request.Query.TryGetValue("userId", out var userIdStr) &&
int.TryParse(userIdStr, out var userId))
{
return userId;
}
return null;
}
}
}