Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Main Class of the Application
Message
De
14/10/2013 14:15:58
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01585436
Message ID:
01585457
Vues:
36
>>>In the WinForms project I am converting to Web Forms there is a Main Class (MainClass.cs) which is the entry point of the application.
>>>In this class there are number of "public static string SomeName" properties declared (at the top of the class). Then the application sets the values of these properties based on user selection(s).
>>>
>>>In Web Forms there is a main page of the application but no main class (if I understand correctly). So I am thinking of creating a 'public sealed class' where to declare all these properties that WinForm MainClass declares.
>>>Does it make sense? Or is there a better place?
>>
>>If the values are truly static (i.e. the same for all users) then a separate static class is probably the best way to go. Something like:
   public static class Globals
>>    {
>>        public static readonly int MaxInt = 10;
>>        public static readonly string SomeString = "This is the string";
>>    }
>
>The value is not static for all users but - maybe - for one user. For example, user selects a file he/she wants to work with. The original WinForms program then stores the name of this file into the MainClass. Then user changes the file that he/she wants to work with, and the value is updated. So it is not really static for all user; not even for the current user. But I think the current user program should be able to "get" this name from various other parts of the application (otherwise, I see no reason why the developer stores the value in MainClass). So I think I need something different than the Static Class (as you suggested).
>Thank you for your help.

Assuming the size of the data is small and should be global for the user, you could store it in the session. Your pages should have a session property, so you can just use the following to set or get the value:
Session["MySessionKey"] = someVariable;
var someVariable = Session["MySessionKey"];
You'll want to avoid keeping any page specific information in there in case the user opens multiple windows. You will also need to check for null values and cast to the appropriate type. Finally, if you are in a web farm situation, the data will need to be serialized to a common server or to the client.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform