Files
BeWoPlaner/Host/Download.aspx.cs

56 lines
1.7 KiB
C#
Raw Normal View History

2016-06-27 01:45:38 +02:00
using System;
using System.IO;
using System.Security;
using System.Web.UI;
using BeWo.Data;
using BS.Shared.Core;
using BeWo.Service.Security;
2025-06-03 12:24:30 +02:00
using SecurityUtils = BeWo.Service.Security.SecurityUtils;
2016-06-27 01:45:38 +02:00
public partial class Download : Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!SessionFacade.IsUserLoggedIn())
{
throw new SecurityException("Invalid authentication");
}
var token = this.Request.Params["token"];
2021-03-30 10:58:50 +02:00
if (SecurityUtils.CheckToken(token, Request.Url.ToString()))
2016-06-27 01:45:38 +02:00
{
string lFileID = this.Request.Params["fileid"];
string lPath = BS.Shared.Core.Utils.CreateSavePath(AppDomain.CurrentDomain.BaseDirectory, lFileID + ".tmp");
2016-06-27 01:45:38 +02:00
using (FileStream uFileStream = File.Open(lPath, FileMode.Open))
{
using (StreamReader uSr = new StreamReader(uFileStream))
{
this.Response.Write(Utils.MyHtmlEncode(uSr.ReadToEnd()));
}
}
File.Delete(lPath);
this.Response.AddHeader("content-disposition", "attachment;filename=BeWoDokument" + Path.GetExtension(lFileID));
this.Response.Charset = string.Empty;
this.Response.ContentType = "application/" + Path.GetExtension(lFileID);
this.Response.End();
}
else
{
this.Response.Write("Ungültiger Link!");
}
}
catch (Exception ex)
{
this.Response.Write(ex.ToString());
}
}
}