About Session Data

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 anos atrás
Hello.

I have created new controller with name CustomBuilderController.cs

Now in it's Index Action I want to set session variable.

So can any one tell me how can I do that and also I want to access that in other cshtml file as well as in other controller action.

So can any one help me step by step to do this.

I am stuck with this, so please help me.

Thanks
6 anos atrás
pms wrote:
Hello.

I have created new controller with name CustomBuilderController.cs

Now in it's Index Action I want to set session variable.

So can any one tell me how can I do that and also I want to access that in other cshtml file as well as in other controller action.

So can any one help me step by step to do this.

I am stuck with this, so please help me.

Thanks


in your controller you can do this...


System.Web.HttpContext.Current.Session["sessionString"] = sessionValue;


You may want to avoid accessing session data within your view, you can do that in the controller as well and assign the value to the ViewBag or ViewData


ViewBag.SessionString = (string)System.Web.HttpContext.Current.Session("sessionString")


Now in your view you can use


@ViewBag.SessionString
6 anos atrás
Dear Sean,

Thanks for reply.. I try that but getting error like below.

please see attached image.

Thanks

6 anos atrás
Hello.

You can see image from this link.

See Error Image here
6 anos atrás
pms wrote:
Hello.

You can see image from this link.

See Error Image here



HttpContext.Session
6 anos atrás
Dear ...Still error is coming :(

6 anos atrás
See Image Here
6 anos atrás
Hi

You can review this

Thanks,
Jatin
3 anos atrás
pms wrote:

having this problem with nopcommerce 4.3. Any help?
3 anos atrás
What problem?  (The image is showing error "unreachable code")

In a controller you can use HttpContext.Session, but in other contexts (like a service), you may have to use the HttpContextAccessor, like this example in \Libraries\Nop.Services\Payments\PaymentService.cs
 var previousPaymentRequest = _httpContextAccessor.HttpContext.Session.Get<ProcessPaymentRequest>("OrderPaymentInfo");
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.