Can someone please advise on how to store the output of this method return in a usable string or char format that could be used as a variable in a different method? I’ve tried passing by value, by reference, in array format, char format implementations, string format implementations, Char.ToString(), String.ToCharArray(), etc.
I defined a timer to have accessTokenRequest() execute at set intervals:
protected void accessTimer_Tick(object sender, EventArgs e)
{
var test = randomCharGen();
//accessLiteral.Text = randomCharGen(); //this generates automated new values upon each refresh interval as what is stored in the variable
accessLiteral.Text = test;
}
<asp:Timer ID="accessTimer" runat="server" Interval="10000" OnTick="accessTimer_Tick"></asp:Timer>
<asp:UpdatePanel ID="accessUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Literal ID="accessLiteral" runat="server"></asp:Literal>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="accessTimer" EventName="tick" />
</Triggers>
</asp:UpdatePanel>
This response is what I am trying to store for later use in the Web.UI.Timer function:
private static string accessTokenRequest()
{
var client = new RestClient("'api'");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "refresh_token");
request.AddParameter("refresh_token", "'token'");
request.AddParameter("client_id", "'id'");
IRestResponse response = client.Execute(request);
dynamic access = JsonConvert.DeserializeObject(response.Content);
string[] accessTokenArray = new string[1];
accessTokenArray[0] = access.access_token.ToString();
return accessTokenArray[0];
}
I can parse the JSON response to obtain the desired field, however, I have not been able to find a way to or create the result where I can just store the target value in a variable for later use without the method being called again. Short of implementing a database to store the responses and then consume from there (undesired), I’m not too sure what other options I might have. Any suggestions are appreciated.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Thought about using
window.localStorage – stores data with no expiration date
window.sessionStorage – stores data for one session (data is lost when the browser tab is closed)
*https://www.w3schools.com/html/html5_webstorage.asp
Also maybe consider using Session variables
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0