Visual studio website - global variables/functions

demondan

Member
Joined
May 24, 2018
Messages
17
Programming Experience
1-3
Hi
Another beginner question...

I'd like to setup some global variables to use within a website, such as username of an active user/a database string that multiple pages would access. Is there a suitable file to set these up in? Same goes for common functions.

I've looked online for an answer and I keep coming across web.config but I don't seem to have this file? Please see the image to see what I do have.

cheers!
Dan

Untitled.jpg
 
username of an active user/a database string that multiple pages would access. Is there a suitable file to set these up in? Same goes for common functions.

You seem to be talking about two different things there. If you're talking about getting data at run-time and then putting that somewhere that it can be accessed for the remainder of the session, that is usually done via session variables. Common functions would be handled the same way as ever: each method would a member of an appropriate class in its own code file. Methods may be in different classes based on their area of functionality and you may or may not have a specific class for miscellaneous method that don't fit anywhere else.
 
Hi, thanks guys! I'll have a read a through that site. And see if I can work out what I am doing with session variables and create a new class/s for my methods.

Thanks for the help so far - appreciated!

cheers
Dan
 

Hi
I've ran into problems with the
link above - in much the same way that I seem to always fall with online tutorials. It sounded exactly what I wanted, I created the _AppStart.cshtml page (created it as a razor page) and first off I noticed that it created this:

@page
@model _AppStartModel
@{
}

_AppStartModel is underlined with red as though it doesn't recognised it so something is not right there. The tutorial tells me to paste of over this anyway which I do however it doesn't recognise
AppState either. Also I noticed that the tutorial says to create the file in the root folder of a WebMatrix website. I don't believe I am using a WebMatrix website.


As usual with online tutorials I am left confused - am I doing it wrong? Is this tutorial meant for another 'type' of website, it does mention WebMatrix but should it apply to others as well? Do I need to do something further for AppState to be recognised? It doesn't mention this in the tutorial.


cheers
Dan
 
Hi
I am trying to use session variables however I must be doing something wrong as it doesn't recognise the word Session? I tried following this https://msdn.microsoft.com/en-us/library/ms178581.aspx and it seems to describe it as pretty straight forward but its not a simple as it makes out as far as I can see anyway!

cheers
Dan
 
Back
Top Bottom