Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The name Response does not exist in the current context

I'm creating a Blazor web application with .Net Core and trying to save the token in the cookie. However I get the error:

The name Response does not exist in the currect context

In all the examples that I have seen people do not face this problem. What do I have to do?

@functions {
    async Task Submit()
    {
        using (var client = new HttpClient())
        {
            User user = new User(state.user.Username, state.user.Password);
            var response = await client.PostAsJsonAsync("api/adimin/token", user);
            var token = await response.Content.ReadAsAsync<string>();

            var option = new CookieOptions();
            option.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Append(setting, token, option);
        }
    }
}
like image 349
javafx Avatar asked Oct 25 '25 15:10

javafx


1 Answers

This worked well to me:-

Replace Response with HttpContext.Current.Response

like image 119
emanuel sabali Avatar answered Oct 27 '25 05:10

emanuel sabali