I have method in a controller to run but every time the view reload the method run again. I tired running it from the application_start I got the same result every time the view reload, it the method runs again. How can I do it to just run once?.
From your description, I suggest you could do as the code below:
public static bool flag = true;
public ActionResult Index3()
{
if (flag)
{
//call the method
ViewBag.Message = "Fist time load";
}
else
{
ViewBag.Message = "Second time load";
}
flag = false;
return View();
}
No the web is stateless and won't persist anything unless asking for this explicitely (if coming from Web Forms, it uses an hidden field to automatically persist few things for you).
Also doing that from Application_Start doesn't seems to make sense. I'm really not sure what you are trying to do. A possible option might be to "cache" this page but for now I would suggest to explain what is your final goal.