asp.net - Constant in global.asax -
is using constant in global.asax idea?
it's go to, what holding in such variable?
i keep main settings (read only) variables in web.config file in <appsettings> area, example:
<appsettings> <add key="amazons3:calendarpath" value="http://mycloud.s3-eu-west-1.amazonaws.com/calendar/" /> </appsettings> and access such values
string calpath = system.configuration.configurationmanager.appsettings["amazons3:calendarpath"]; either in views or controllers.
this lovely place hold read-only variables as, no mater if web application built or not, compiled or showing source files, can change variable need, without opening compiled file, change , compile project again... saves lot of trouble , gives dynamic hole application settings.
if other hand want read/write way of saving variables across application, have 3 ways, pros , cons
use session state save variables used, it's terrible on cloud platforms request can change servers , new server received continue request of user, not have session
use cookies save user variables cookies can modified on fly user, use save settings minor changes, ui definitions.
use cache layer hold variables used in cloud platforms not can save settings, can save portions of data access of time.
there application settings on global.asax witch used classic asp days, since never have used them have same flow session variables, witch placed in memory... application pool reset, new build, session lost.
there also, plenty of posts ca search have better knowledge of options have save variables cross application on asp.net project.
Comments
Post a Comment