Is it possible to use global variables in C #? I come from the main background of PHP, so the variables are available either everywhere or simply global.
My main problem: I have a class Userthat I created to wrap the current table usersin my company database. I define it in MasterPage, but I can’t access it from real pages (I don’t know if there is a better word for their description, but these are pages that inherit the styles and format from MasterPage)
Any general tips or implementation practices for me?
EDIT : here are some code snippets of what I'm trying to do:
Site.master.cs
public partial class SiteMaster : System.Web.UI.MasterPage
{
public User user = new User();
}
logout.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="logout.aspx.cs" Inherits="logout" %>
<%@ MasterType virtualPath="~/Site.master"%>
logout.aspx.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
User user = Master.user;
}
}