简体   繁体   中英

How do I initialize needed global variables in ASP.NET MVC?

In this article there is an explanation of the way of creating SharePoint 2013 add-in in web forms, I need MVC though.

They initialize accessToken, currentUser, and other variables in the Default.aspx.cs file:

In the Default.aspx.cs file of your web application, add these variables inside the Page class.

SharePointContextToken contextToken;
string accessToken;
Uri sharepointUrl;
string siteName;
string currentUser;
List<string> listOfUsers = new List<string>();
List<string> listOfLists = new List<string>();

Does it really matter where I initialize it in MVC and if it does, where do I have to initialize these? Is HomeController okay?

Sorry for the question's being probably dumb as I am new to both SharePoint and ASP.NET MVC.

PS: The question is indirectly connected with SharePoint so I asked it there and not at SharePoint StackExchange

You can declare global variables in app_code folder of your solution,and use it where ever you need.

In App-code you need to add a class file like Global.cs(you can give any name) and there you can declare global variables.

Create one BaseController and define required variable as public constant/read only , then inherit this BaseController to your Controller , you can access that variable.

Please look at here for more details:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM