0

Hi Dears, Masters
Help me please. my web application share Global variables for all web-site visitors and any user does not have his private session area in IIS. I mean when USER1 login to my web-application, asp.net fill a global array with him information but if USER2 login simultaneity, Asp.Net fill array with new information and USER1 details lost. here is first lines of my cs file:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Net;
public partial class Family : System.Web.UI.Page
{
// define some  GLOBAL variables
public static string PersonnelGender, ConnectionString = "",PrsConnectiongStr="",EditDivTagSelector="",PrsCodeVar;
public static string PrsMobileVar, PrsInjuriedVar, PrsEmpTypeVar,PrsInsStatusVar,PrsBasicInsVar,PrsInsNumVar,PrsMarriedVar,PrsSecInsTypeVar,PrsGenderVar;
//EditDivTagSelector={NewMember,EditPrs,EditMember}
public static int LatestMember = 0;
public static string[,] FamilyMemberArray = new string[10, 15];
public static string[] PersonnelInfoArray = new string[16];
public static string FamilyNationalCode_Update = "";
public static int FamilyMemForEditVar;
public static string UIReport = "";

string[,] FamilyMemberArray = new string[10, 15] is very important array. what's wrong with my code?

Morteza
  • 366
  • 3
  • 7
  • I'm pretty sure ASP.NET or IIS is not "confused", but when you are calling member variables as globals you clearly are. The problem is not very clear, especially without any actual code, so please refrain from extraneous comments and explain the whole situation more clearly, with relevant code. – Sami Kuhmonen Oct 19 '16 at 04:07
  • Thank you Sami. I went a step forward and found what's exactly wrong with my code. please have a look to question again and help me please. – Morteza Oct 21 '16 at 16:12
  • Don't use static variables. That's what's making everything wrong. – Sami Kuhmonen Oct 21 '16 at 16:18
  • Oh, I removed static but it didn't work(scope is not global if I remove static). Would you like tell me how should I declare global variable??? I checked this page but no luck: http://stackoverflow.com/questions/4171089/how-to-define-a-global-variable-in-asp-net-web-app – Morteza Oct 21 '16 at 17:14
  • Your whole issue is that you're trying to use globals. *Don't do it!* – Sami Kuhmonen Oct 21 '16 at 17:14
  • I have to. Because they are more than 10 function in my .cs file that need family members information. So in page load function I fetch them from Database and save in global variables for further use. I can use Controls or cookie but variable is too easy for use. Is not it? What's your suggestion? – Morteza Oct 21 '16 at 17:25
  • It has nothing to do with being easy or not, it's just *wrong* as you can see. You have problems immediately. There's no need for global state within one class. But if you mean you want to store them and use in postbacks etc then think of another way. Use the Session if you have to. Global state is *global* for *every user*. – Sami Kuhmonen Oct 21 '16 at 17:28
  • I deeply appreciate you – Morteza Oct 21 '16 at 18:26
  • I have same problem now , How to define variables in where? – Peter P. Mar 29 '21 at 18:39

0 Answers0