Click here to Skip to main content
15,878,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I hope I explain this well. I have been developing websites with ASP.NET Core 6 C# in Visual Studio for some time. I just realized with a site I am working on now that information entered and stored from a form into objects that I then read and display on another page from one computer will show up if I pull that display page up on a different computer. For example, if I have an input for firstname, public string firstname, and a button which submits the name from the input into firstname, then displays the name on a new page, @Model.firstname, then goes to a different computer and pulls that page up, the name shows up. I guess I always assumed the server, IIS, created new instances of the site objects when someone else on a different computer or browser pulled the site up. Now I am unsure of exactly how things are working on the server, IIS. Hope someone can help me out and explain what is going on. Let me know if I need to send more information.

What I have tried:

Using session variable objects.
Updated 25-Oct-23 4:07am
Richard MacCutchan 17-Oct-23 6:50am    
There is something seriously wrong in your backend code, if it can capture data from one user and display it to another.
brian5795 17-Oct-23 7:04am    
Yes thanks, that is i guess what i am trying to figure out. Like i stated before, i thought that instances of the web app would be created for each computer or browser accessing the app on iis, so that if you pull up the form, and i pull up the form, there are separate instances of the objects created, but it seems i am wrong about that assumption.
Dave Kreskowiak 17-Oct-23 9:56am    
Well, since nobody can see your code, because you haven't posted any of the code that handles user data, it's impossible for anyone to tell you what you did wrong.
brian5795 17-Oct-23 20:41pm    
Just to clarify, i am not using user data at this point. Just in the most simplistic form, i have one page


function Update() {

document.getElementById('input-div').style.backgroundColor = 'green';

var firstnamein = document.getElementById('firstname').value;

var fileform = new FormData;

fileform.append("firstnamein", firstnamein);

url: "./orderform?handler=Update",
type: 'POST',
data: fileform,
async: true,
cache: false,
contentType: false,
processData: false,
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN", $('input:hidden[name="__RequestVerificationToken"]').val());

success: function (Return) {



document.getElementById('input-div').hidden = true;

document.getElementById('confirm-div').hidden = false;



public class orderformModel : PageModel
public static string firstname { get; set; }
public void OnGet()

public async Task<iactionresult> OnPostUpdateAsync(string firstnamein)
firstname = firstnamein;

return Content("OK");


and then


Layout = "_PlainLayout";

Hello @orderformModel.firstname

So with this, if you go to orderform, enter name, and click next, it will bring up the orderview with Hello 'firstname'. when run on the server iis and you go to the page on one computer and put name in and click next it will show the name entered. But you also can go to a different computer then and pull up orderview and it will show the name entered on the other computer. So i believe i am missing some fundamental property of web apps and iis. Like i said i always believed that iis created a new instance of the objects or app so that new connections would not share data. I hope that makes sense.
Dave Kreskowiak 18-Oct-23 0:58am    
public static string firstname { get; set; }

The "static" keyword means the variable is shared between all instances of the class it's contained in. Remove the static keyword and the sharing goes away.

1 solution

If you're experiencing issues with session variables not behaving as expected, it's important to check if you are correctly using and managing the session in your ASP.NET Core application. Here are some common steps to troubleshoot issues with session variables:
Make sure that the session has been properly configured in your application's Startup.cs file. You need to add the session middleware and configure it as follows:
public void ConfigureServices(IServiceCollection services)
    // Add session services
    services.AddSession(options =>
        options.IdleTimeout = TimeSpan.FromMinutes(30);
        options.Cookie.HttpOnly = true;
        options.Cookie.IsEssential = true;

    // Other configurations...

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    // Use session

    // Other configurations...

If you're still encountering problems, kindly provide more specific details about the issues you're facing, including any error messages, This additional information can help in diagnosing and resolving the issues related to using session variables in your ASP.NET Core application.
Share this answer
brian5795 17-Oct-23 6:39am    
Yeah sorry not sure i explained it well. I have the session set up as you have stated. The problem is the same whether i use session variable or not so do not really want to focus on the session part of it. Say i have a page orderform.cshtml with an input for firstname, i have a button to submit the name to public static string firstname { get; set; } declared in orderform.cshtml.cs. then using js i load another page orderview.cshtml in div in orderform.cshtml which then displays the name @orderformModel.firstname. If i pull the orderform up on one computer, enter a name and submit, it loads orderview and displays the name i entered. If i then go to a different computer and load the orderview page it also displays then name i entered on the other computer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900