-1

I built an c# desktop application for attendance

application is working fine when i run it on single machine and all is good..

but now issue is ... my boss want this application should work on LAN and every client can access application from server

but i used static variables which store some values at run time and then i utilized these values in next forms.

here is example..

on login form username is stored in static variable as

 public static string username;
username = txtUser.Text.Trim().ToString();

and in next form which is Home Page this user name is used as

lblName.Text = Login.username;

here lblName is name of label and Login name of Login form

when i configure this application on LAN then may be at same time more than one user will be logged in and want to access application then each user should see his/her own username....

e-g abc is user 1 and xyz is user 2

if both are logged in at same time then i want abc to see

 lblName.Text = "abc"

and xyz to see

lblName.Text = "xyz" 

so what should i do to handle this job?

i need not to mix up any information between users...

i used c# windows app.

thanks in advance.

Waqas
  • 847
  • 4
  • 14
  • 36
  • The answer to this question is to not use static variables. You need some kind of storage mechanism, this could be any number of things (DB, local storage, noSQL, etc. etc.). TBH if you want it to *"run on a network"* then a web site would be the obvious choice. Voting to close as too broad I'm afraid. You need to spend sometime researching an answer for yourself then return when you have an answerable question. – Liam Sep 07 '15 at 13:43
  • Have you actually tested your app doesn't work when run from the LAN? Each user running the desktop exe from the server gets their own instance of the exe - you shouldn't get 'conflicts'. – Ulric Sep 07 '15 at 14:31
  • i didn't check this on LAN but on google i searched it a lot some says i doesn't work... so i am now checking this .and will be here very soon to edit my question... thanks for your time – Waqas Sep 08 '15 at 04:47

1 Answers1

0

I assume you use static variables on server-side, right?

So, your issue happens because you use static variables.

Static variables are consistent in your class during all period of application is running. And that fields are shared between ALL processes which can use that class. Static variables was designed for this.

As a possible quick solution you can generate something like unique session Id. During client logs in to your system - you need just generate that id on client's side, send it with login information to server. In case of successful authentication server will store id in cache a key. And value of the cache can be object with user's name and other needs.

Every request to your server should be followed with that id. So your server will always know which user it is.

If you need more detailed answer please provide more information about app network structure and it's modules.

Anton Norko
  • 2,166
  • 1
  • 15
  • 20
  • as for i know sessions is only in web based application it is totally desktop. actually i built this app for myself but when my boss go through it then he liked this and now he wants it to be on LAN.... – Waqas Sep 07 '15 at 13:56
  • @Waqas yes, but you can use same concept, why not? I assume you have Dewsktop application and server-side app. Right? – Anton Norko Sep 07 '15 at 14:21
  • yes but on internet i searched a lot some says it isn't work and some says you should write app domain for these static variables... thats why i need expert opinion.. – Waqas Sep 08 '15 at 04:45
  • @Waqas you don't need to have additional app domain. Your client application is already in app domain. You server-side application already in app domain. You never need to implement pure Session approach just like in web apps. You need simplified emulation. Could you please to tell more about structure of your application? Is it common client-server structure - you have client application which connects to server via web services approach or something like that. Please tell more so I can suggest you better. – Anton Norko Sep 08 '15 at 06:36
  • I got a simple solution that i should make my app just like Skype... data base will be on LAN server and give connection string having IP address of server then exe will be installed on each client system so it should work... am i right or not please give suggestion ... – Waqas Sep 08 '15 at 09:45
  • @Waqas - probably you can use WebDav approach. It will be just simple web application (generated automatically) on your LAN server (db server?). And you will have a link, then user should open that link in IE and IE initiates installation of application. And every time when user will start application it will check for updated first and then run apps. Web Dav natively supported by MS Visual Studio. See more about WebDav there: http://www.iis.net/learn/install/installing-publishing-technologies/installing-and-configuring-webdav-on-iis. – Anton Norko Sep 08 '15 at 18:03