Well guys, I have a problem that I have not been able to solve until now. It only starts to occur after an ajax request , where I generate a document and return it to url in a json , to be fetched in javascript , be assigned to a link and be downloaded.
As it happens: after generating the first report, if the user tries to create another logo then the middle application that calls the Application_Start again, and thus losing the "linkage" strong> session . The funny thing is that in the browser (I'm using Chrome ), the session keeps appearing in Cookies.
Another interesting fact is that when I click on the link to download, it also calls the Application_Start ...
NT: I use ASPNET MVC 5
Example of how I create Sessions:
[HttpPost]
[AllowAnonymous]
public ActionResult LoginRequest(string login, string pass)
{
string loginCache = "usuario";
string senhaCache = "123123";
if (login == loginCache && pass == senhaCache)
{
System.Web.HttpContext.Current.Session["Nome"] = "Admin";
System.Web.HttpContext.Current.Session["Email"] = loginCache;
return Json(
new
{
sucesso = true,
href = "GerarRelatorio/Index"
}
);
}
else
{
return Json(
new {
sucesso = false,
msg = "Login e/ou Senha estão incorretos."
}
);
}
Example of how I am returning the url:
var newCaminhoContent = Path.Combine(urlDownloadFolder, arquivoModel.Nome);
var urlDownloadHTML = ( newCaminhoContent.Substring(newCaminhoContent.IndexOf(@"Content")) );
return Json(new
{
hasError = false,
msg = "O arquivo foi gerado com sucesso!",
href = urlDownloadHTML,
nome = arquivoModel.Nome,
ext = arquivoModel.ExtensaoString
});
Example of how to get the url in javascript:
$.post(
AppConfig.baseUrl + "/GerarRelatorio/Gerar",
{
cm: cm,
tr: tr
},
function (data, status) {
console.log(data);
try {
if (data.hasError === false) {
getTimeToShowLink(data);
//var win = window.open(AppConfig.baseUrl + data.href);
//win.focus();
//$('#modal-status').modal('hide');
}
else {
$('#div-modal-loading').hide();
$('#div-modal-msg').html(data.msg);
}
}
catch (e) {
console.log(e);
}
finally {
//$btn.button('reset');
$('#modal-status').modal('hide');
}
}
);
function getTimeToShowLink(data) {
$('#btn-download')
.attr('href', AppConfig.baseUrl + data.href)
.attr('download', data.nome)
.show()
var tempo = 10;
var sec = 0;
var interval = setInterval(function () {
sec = pad(++sec % 60);
if (parseInt(sec) <= parseInt(tempo)) {
$("#div-msg-download").html(
'Se o download não começar automaticamente em até ' + (tempo - sec) + ' segundos, clique aqui...');
}
else {
$('#div-msg-download').html('Clique aqui para fazer o download...');
clearInterval(interval);
}
}, 1000);
}