why not just a state variable?
Can you explain this?
Do you mean in a cookie or session?
thanks,
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
How to Encrypt and decrypt the state file in ASP.net core or blazor?
regards,
why not just a state variable?
Can you explain this?
Do you mean in a cookie or session?
thanks,
You mean where should I save it? can you describe more?
When I try to enter Instagram keep getting this message "loading state from file".
If you have seen the code, do you think which part is wrong?
why are you saving state to a file in a blazor app? why not just a state variable? also are all blazor users the same or is this a single user site?
also in the sample::
https://github.com/ramtinak/InstagramApiSharp/blob/master/samples/Examples/Program.cs
at line 91 it says not to use if .net core
note: I've never used this library, but you appear to be off track
I mean session state. I want to encrypt the state.bin.
The app is serverside:
@code{
public static IInstaApi _instaApi;
public static string username { get; set; }
public static string password { get; set; }
public static string message = string.Empty;
public static string ExceptionMessage = string.Empty;
private static async Task StartInstagram()
{
var userSession = new UserSessionData
{
UserName = Enterance.username,
Password = Enterance.password
};
var _instaApi = InstaApiBuilder.CreateBuilder()
.SetUser(userSession)
.UseLogger(new DebugLogger(LogLevel.All))
.Build();
const string stateFile = "state.bin";
try
{
// load session file if exists
if (File.Exists(stateFile))
{
//Console.WriteLine("message = "";");
message = "Loading state from file";
using (var fs = File.OpenRead(stateFile))
{
//_instaApi.LoadStateDataFromStream(fs);
//_instaApi.LoadStateDataFromString(new StreamReader(fs).ReadToEnd());
////////////////////////////////////////////////////////////////////
//_instaApi.LoadStateDataFromString(new StreamReader(fs).ReadToEnd());
_instaApi.LoadStateDataFromStream(fs);
}
}
}
catch (Exception e)
{
ExceptionMessage = $" error: {e}";
}
if (!_instaApi.IsUserAuthenticated)
{
// login
message = $"Logging in as {userSession.UserName}";
var logInResult = await _instaApi.LoginAsync();
if (!logInResult.Succeeded)
{
//Console.WriteLine($"Unable to login: {logInResult.Info.Message}");
message = $"Unable to login: {logInResult.Info.Message}";
return;
}
}
// save session in file
var state = _instaApi.GetStateDataAsStream();
using (var fileStream = File.Create(stateFile))
{
state.Seek(0, SeekOrigin.Begin);
state.CopyTo(fileStream);
}
}
}