我有以下内容:
public HttpResponseMessage Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
WebSecurity.Login(model.UserName, model.Password);
InitiateDatabaseForNewUser(model.UserName);
FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
return Request.CreateResponse(HttpStatusCode.Created, WebSecurity.CurrentUserId);
在此代码中,CurrentUserId(在最后)始终解析为 -1,因为 WebSecurity 直到方法关闭后才能看到新用户。我想从 Register() 方法返回个人资料或至少返回新注册用户的 id - 这如何实现?