There is some debate as to the "correctness" of doing so (linked below), but you can store the variable in HttpContext.Current.Application["BandProfile"]
.
if (bandProfile != null)
{
userManager.AddToRole(UserId, "Band");
//Store the bandprofile ID anywhere?
HttpContext.Current.Application["BandProfile"] = bandProfile;
return RedirectToAction("Index", "Welcome");
}
Alternatively, you can use a static
variable in a class somewhere.
public static class BandProfile
{
public static whatever Profile;
}
if (bandProfile != null)
{
userManager.AddToRole(UserId, "Band");
//Store the bandprofile ID anywhere?
BandProfile.Profile = bandProfile;
return RedirectToAction("Index", "Welcome");
}
Here is a related question that deals with the same issue, and here is another.
EDIT:
To then access these variables, you can use
var bandProfile = HttpContext.Current.Application["BandProfile"];
or
var bandProfile = BandProfile.Profile;
According to Microsoft:
ASP.NET includes application state primarily for compatibility with classic ASP so that it is easier to migrate existing applications to ASP.NET. It is recommended that you store data in static members of the application class instead of in the Application object.
That said, you should use the static
variable method. Static variables are available by calling ClassName.Variable
and will exist for the duration of the app running. If the app is closed or the variable is otherwise changed, you will lose this information.
In order to save the information, it's necessary to write the contents of this variable to an external source (DB, file, etc.) and read it in when the app starts.