Results 1 to 6 of 6

Thread: Visual studio website - global variables/functions

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    4

    Visual studio website - global variables/functions

    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

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Location
    Norway
    Posts
    417
    Rep Power
    105
    [xcode=c#] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,865
    Rep Power
    145
    Quote Originally Posted by demondan View Post
    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.

  4. #4
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    4
    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

  5. #5
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    4

    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

  6. #6
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    12
    Rep Power
    4
    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

Similar Threads

  1. Using ExtentReports in Visual Studio
    By m_finn in forum Third Party Products
    Replies: 2
    Last Post: 11-20-2017, 11:54 AM
  2. Question How do I avoid global variables or static class? - Best practice?
    By reyes in forum C# General Discussion
    Replies: 4
    Last Post: 10-16-2017, 9:54 AM
  3. Visual Studio on mac
    By theo3401 in forum C# General Discussion
    Replies: 2
    Last Post: 06-05-2017, 11:26 AM
  4. Replies: 2
    Last Post: 05-27-2015, 2:47 AM
  5. Question Easiest way to use Github with Visual Studio?
    By Mothil in forum C# General Discussion
    Replies: 0
    Last Post: 02-01-2015, 2:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •