ASP.NET Core 2.1 Persist HttpContext.User details once set
I am trying to persist some data that I intend on using in the application in my HttpContext.User. However, when I go to another page/controller and I recheck HttpContext.User, its empty again. Is there a way to set this as persistent? I am not using any form of identity as my application relies on jwt
public IActionResult Index()
var claims = new
new Claim("name", "Test"),
;
var identity = new ClaimsIdentity(claims, "basic");
HttpContext.User = new ClaimsPrincipal(identity);
return View();
asp.net asp.net-core asp.net-core-mvc
add a comment |
I am trying to persist some data that I intend on using in the application in my HttpContext.User. However, when I go to another page/controller and I recheck HttpContext.User, its empty again. Is there a way to set this as persistent? I am not using any form of identity as my application relies on jwt
public IActionResult Index()
var claims = new
new Claim("name", "Test"),
;
var identity = new ClaimsIdentity(claims, "basic");
HttpContext.User = new ClaimsPrincipal(identity);
return View();
asp.net asp.net-core asp.net-core-mvc
HttpContext.User is not session. Please refer docs.microsoft.com/en-us/aspnet/core/security/… on how to setup authentication and authorization
– Ramesh
Nov 14 '18 at 5:00
So this is impossible? How does a non jwt .net core application persist user data? I don't see any sessions or cookies being used in the devtools of chrome.
– JianYA
Nov 14 '18 at 5:03
What kind of authentication are you using / you need ? Cookie Based ?
– Ramesh
Nov 14 '18 at 5:06
When I login, I send my username and password to a rest api which returns a jwt token. I haven't set anything in my startup.cs. I'm quite lost now as I need to persist some items across the application but I cannot use stuff like Iauthorization as I use a rest api to validate a users role as well.
– JianYA
Nov 14 '18 at 5:12
1
Check the solution in ASP.NET Core 2.1 Jwt setting custom claims
– Tao Zhou
Nov 14 '18 at 5:21
add a comment |
I am trying to persist some data that I intend on using in the application in my HttpContext.User. However, when I go to another page/controller and I recheck HttpContext.User, its empty again. Is there a way to set this as persistent? I am not using any form of identity as my application relies on jwt
public IActionResult Index()
var claims = new
new Claim("name", "Test"),
;
var identity = new ClaimsIdentity(claims, "basic");
HttpContext.User = new ClaimsPrincipal(identity);
return View();
asp.net asp.net-core asp.net-core-mvc
I am trying to persist some data that I intend on using in the application in my HttpContext.User. However, when I go to another page/controller and I recheck HttpContext.User, its empty again. Is there a way to set this as persistent? I am not using any form of identity as my application relies on jwt
public IActionResult Index()
var claims = new
new Claim("name", "Test"),
;
var identity = new ClaimsIdentity(claims, "basic");
HttpContext.User = new ClaimsPrincipal(identity);
return View();
asp.net asp.net-core asp.net-core-mvc
asp.net asp.net-core asp.net-core-mvc
edited Nov 14 '18 at 4:56
Tetsuya Yamamoto
16.5k42240
16.5k42240
asked Nov 14 '18 at 4:39
JianYAJianYA
6771128
6771128
HttpContext.User is not session. Please refer docs.microsoft.com/en-us/aspnet/core/security/… on how to setup authentication and authorization
– Ramesh
Nov 14 '18 at 5:00
So this is impossible? How does a non jwt .net core application persist user data? I don't see any sessions or cookies being used in the devtools of chrome.
– JianYA
Nov 14 '18 at 5:03
What kind of authentication are you using / you need ? Cookie Based ?
– Ramesh
Nov 14 '18 at 5:06
When I login, I send my username and password to a rest api which returns a jwt token. I haven't set anything in my startup.cs. I'm quite lost now as I need to persist some items across the application but I cannot use stuff like Iauthorization as I use a rest api to validate a users role as well.
– JianYA
Nov 14 '18 at 5:12
1
Check the solution in ASP.NET Core 2.1 Jwt setting custom claims
– Tao Zhou
Nov 14 '18 at 5:21
add a comment |
HttpContext.User is not session. Please refer docs.microsoft.com/en-us/aspnet/core/security/… on how to setup authentication and authorization
– Ramesh
Nov 14 '18 at 5:00
So this is impossible? How does a non jwt .net core application persist user data? I don't see any sessions or cookies being used in the devtools of chrome.
– JianYA
Nov 14 '18 at 5:03
What kind of authentication are you using / you need ? Cookie Based ?
– Ramesh
Nov 14 '18 at 5:06
When I login, I send my username and password to a rest api which returns a jwt token. I haven't set anything in my startup.cs. I'm quite lost now as I need to persist some items across the application but I cannot use stuff like Iauthorization as I use a rest api to validate a users role as well.
– JianYA
Nov 14 '18 at 5:12
1
Check the solution in ASP.NET Core 2.1 Jwt setting custom claims
– Tao Zhou
Nov 14 '18 at 5:21
HttpContext.User is not session. Please refer docs.microsoft.com/en-us/aspnet/core/security/… on how to setup authentication and authorization
– Ramesh
Nov 14 '18 at 5:00
HttpContext.User is not session. Please refer docs.microsoft.com/en-us/aspnet/core/security/… on how to setup authentication and authorization
– Ramesh
Nov 14 '18 at 5:00
So this is impossible? How does a non jwt .net core application persist user data? I don't see any sessions or cookies being used in the devtools of chrome.
– JianYA
Nov 14 '18 at 5:03
So this is impossible? How does a non jwt .net core application persist user data? I don't see any sessions or cookies being used in the devtools of chrome.
– JianYA
Nov 14 '18 at 5:03
What kind of authentication are you using / you need ? Cookie Based ?
– Ramesh
Nov 14 '18 at 5:06
What kind of authentication are you using / you need ? Cookie Based ?
– Ramesh
Nov 14 '18 at 5:06
When I login, I send my username and password to a rest api which returns a jwt token. I haven't set anything in my startup.cs. I'm quite lost now as I need to persist some items across the application but I cannot use stuff like Iauthorization as I use a rest api to validate a users role as well.
– JianYA
Nov 14 '18 at 5:12
When I login, I send my username and password to a rest api which returns a jwt token. I haven't set anything in my startup.cs. I'm quite lost now as I need to persist some items across the application but I cannot use stuff like Iauthorization as I use a rest api to validate a users role as well.
– JianYA
Nov 14 '18 at 5:12
1
1
Check the solution in ASP.NET Core 2.1 Jwt setting custom claims
– Tao Zhou
Nov 14 '18 at 5:21
Check the solution in ASP.NET Core 2.1 Jwt setting custom claims
– Tao Zhou
Nov 14 '18 at 5:21
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293282%2fasp-net-core-2-1-persist-httpcontext-user-details-once-set%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293282%2fasp-net-core-2-1-persist-httpcontext-user-details-once-set%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
HttpContext.User is not session. Please refer docs.microsoft.com/en-us/aspnet/core/security/… on how to setup authentication and authorization
– Ramesh
Nov 14 '18 at 5:00
So this is impossible? How does a non jwt .net core application persist user data? I don't see any sessions or cookies being used in the devtools of chrome.
– JianYA
Nov 14 '18 at 5:03
What kind of authentication are you using / you need ? Cookie Based ?
– Ramesh
Nov 14 '18 at 5:06
When I login, I send my username and password to a rest api which returns a jwt token. I haven't set anything in my startup.cs. I'm quite lost now as I need to persist some items across the application but I cannot use stuff like Iauthorization as I use a rest api to validate a users role as well.
– JianYA
Nov 14 '18 at 5:12
1
Check the solution in ASP.NET Core 2.1 Jwt setting custom claims
– Tao Zhou
Nov 14 '18 at 5:21