问题描述:

I've ASP.NET MVC5 project with standard auth process.

After calling /Account/Login I've got response with new cookie .AspNet.ApplicationCookie with auth token. The question is how to get this token in Login action, right after it's generated?

My only idea is to try obtain it from response's cookie but it doesn't work:

// ... somwhere in login action

AuthenticationManager.SignIn(identity);

// <-- How to obtain auth token here? Code below don't work

var token = HttpContext.Current.GetOwinContext().Response.Cookies[".AspNet.ApplicationCookie"];

.. but this is not even compiling.

网友答案:
Request.Cookies[".AspNet.ApplicationCookie"]

Not sure if there is a leading period "." though, also try:

Request.Cookies["AspNet.ApplicationCookie"]
网友答案:

On callback action from OAuth you could use Request.Cookies[".AspNet.ExternalCookie"]

网友答案:

I believe you may be confusing Request and Response. Response is what you send TO the client - so you never want to read a cookie from there. Instead, read the cookie from the Request object.

If you "read" from the Response object and the cookie doesn't' already exist in it, it will simply create a NEW cookie of that name - with no value!

相关阅读:
Top