c# - ASP.NET 5 MVC6 User.GetUserId() returns incorrect id -
i have simple project in asp.net 5 1 registered user. have tried id of current logged user extension method getuserid()
using system.security.claims
namespace. unfortunately method returns me not existing id , don't know why.
here simple code:
var currentuserid = user.getuserid();
method result:
database:
more you're getting old auth ticket still valid or getting authentication ticket site running locally. clear browser cache , cookies , run again.
also, try changing name of cookie, default set .aspnet.cookies
can cause issues if you're running multiple apps locally. caught me while back.
the cookie name can changed this
app.usecookieauthentication(new cookieauthenticationoptions { authenticationtype = defaultauthenticationtypes.applicationcookie, loginpath = new pathstring("/account/login"), provider = new cookieauthenticationprovider { onvalidateidentity = securitystampvalidator.onvalidateidentity<usermanager, applicationuser>( validateinterval: timespan.fromminutes(0), regenerateidentity: (manager, user) => manager.generateuseridentityasync(user)) }, cookiename = "myauthcookie", });
the msdn documentation on can found here.
Comments
Post a Comment