0
I am using Fileupload in a register page of a logged area, but when the post runs my Session is lost.
I tried using Updatepanel and it didn’t solve the problem. Other solutions that I tried and also did not solve were: cookieless and use sessionstate=Stateserver (in this case because my hosting is not with the service enabled).
HTML
<asp:FileUpload runat="server" ID="uplImagem" CssClass="form-control-file" AllowMultiple="false" accept="image/jpeg, image/png" />
<asp:Button runat="server" ID="btnUploadImagem" Text="Carregar" OnClick="btnUploadImagem_Click" CssClass="btn btn-outline-primary" />
Button code
protected void btnUploadImagem_Click(object sender, EventArgs e)
{
try
{
if (!String.IsNullOrEmpty(uplImagem.PostedFile.FileName))
{
if (uplImagem.PostedFile.ContentType == "image/jpeg" || uplImagem.PostedFile.ContentType == "image/png")
{
if (uplImagem.PostedFile.ContentLength <= 512000)
{
String nomeArquivo = String.Concat("acao", hdnIdSorteio.Value.PadLeft(10, '0'), ".jpg");
String fullpath = String.Concat(MapPath(CaminhoUpload), nomeArquivo);
uplImagem.SaveAs(fullpath);
}
else
{
ExibirMensagem("Arquivo muito grande. Tamanho máximo permitido: 500 Kb.", TipoMensagem.Alerta);
}
}
else
{
ExibirMensagem("Tipo de arquivo inválido. Tipos permitidos: JPEG, JPG e PNG.", TipoMensagem.Alerta);
}
}
else
{
ExibirMensagem("Nenhum arquivo selecionado.", TipoMensagem.Informacao);
}
}
catch (Exception ex)
{
ExibirMensagem("Erro ao carregar imagem. Tente novamente.", TipoMensagem.Erro);
Logger.GravaLog(ex);
}
}
Does anyone know what might be going on?
Thank you.
How did you make the diagnosis of session loss? At what point is it abandoned?
– Leandro Angelo
I identified the session loss by the application log, the error happens where I recover the logged user code I save in Session. Whenever I upload the image the problem happens, on the same page I Insert/update in Mysql and it works perfectly.
– Rodrigo Dias
I meant in your code, because introducing you, does not work at any time with session... but you say that if you upload by the above method it leaves the session? Debugging, you checked if it is exactly at this point?
– Leandro Angelo