0
Good guys, I have a problem that so far could not solve. It only starts to occur after a ajax request, in which I submit a document and return to url in a json, to be caught in the javascript, be assigned to a link and be downloaded.
How it happens: after generating the first report, if the user tries to create another one soon after, the application kind that calls the Application_start again, and thus losing the "linkage" that had the Session. The funny thing is that in the browser (I’m using the Chrome), Session continues to appear in Cookies.
Another interesting fact, is that when I click on the link to download, it also calls again the Application_start...
NT: Utilizo ASPNET MVC 5
Example of how I create the 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’m 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);
}
From what I understand, you’re calling the application on Cors. We understand that js is on the client machine and that the session cookie is not sent at the time of the ajax request, so the system understands that it is another client requesting...
– DiegoSantos
Good, but you know how this situation could be corrected?
– Márcio Cristian
It depends on several things, but you can try taking concatenation from endpoint, if the address is the same clear. It would be possible?
– DiegoSantos
How could I do that?
– Márcio Cristian
For example, here: Appconfig.baseUrl + "/Gerarrelatorio/Gerar", it would look like this: "/Gerarrelatorio/Gerar". However, once again. It depends on how your environment was set up, how your logic was built...
– DiegoSantos
I get it... I’ll test it here.
– Márcio Cristian