Web 表单处理脚本,用于在服务器上执行后台作业,然后在准备好时发送电子邮件

发布于 2024-10-08 19:56:00 字数 669 浏览 2 评论 0原文

我正在 C# ASP.NET 中开发一个应用程序,允许用户使用其公司徽标自定义许多图形模板。

通常,

  1. 用户上传他们的公司徽标。
  2. 用户选择多个不同文件类型的模板(通过 HTML 表单)进行定制。
  3. 我的 Web 应用程序将接受用户的请求,检查请求的每个单独项目并确定其文件类型。然后,它将根据文件类型调用适当的模块(例如自定义 PDF),最后将徽标插入模板中。对每个请求的文件重复这些步骤。
  4. 一旦生成了用户请求的所有模板,它们就会被分组到一个 zip 文件中,并通过电子邮件发送下载链接。

我想要一些关于如何最好地接受用户的请求并在 ASP.NET 中处理文件的建议。

执行此操作的一种方法是让用户等待,直到生成所有文件,因此直到表单处理脚本完成其执行。我认为对于需要长时间处理的请求(请求大量模板或大量并发用户),这可能很容易触发脚本超时错误,因此这不是一个非常有效的解决方案。

另一种选择是注册用户的请求,随后立即将他/她重定向到另一个页面(解释说很快就会发送一封带有下载链接的电子邮件),然后使用某些后台作业或类似的作业继续处理服务器上的文件没有脚本超时的风险。生成该用户的所有文件后,将发送一封电子邮件。

我熟悉 Web 应用程序开发,但这是我第一次尝试 .NET 开发,因此非常感谢您的帮助。

如何在 C# 中实现第二个选项?

I am developing an application in C# ASP.NET to allow users to customise a number of graphics templates with their company logo.

Typically,

  1. User uploads their company logo.
  2. User selects a number of templates (through a HTML form) of different file types for customising.
  3. My web application will accept the user's request, go through each individual item requested and determine its file type. It will then call the appropriate module depending on the file type (e.g. to customise a PDF) and finally insert the logo in the template. These steps are repeated for each file requested.
  4. Once all requested templates for a user are generated, they are grouped together in a zip file and a link for downloading is sent via email.

I would like some advice on how best to accept the user's requests and process the files in ASP.NET.

One way of doing this is to keep the user waiting until all files are generated, therefore until the form handling script would have completed its execution. I reckon this is likely to trigger script timeout errors quite easily for requests that take long to be processed (large number of templates requested or sizable number of concurrent users), and as such is not a very efficient solution.

Another option would be to register the user's request, redirect him/her to another page immediately after (explaining that an email will be sent shortly with a download link), and then proceed to process the files on the server using some background job or similar without the risk of script timeouts. An email is sent when all files for that user are generated.

I am familiar with web application development but this is one of my first forays into .NET development so your help is greatly appreciated.

How can I implement the second option in C#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韶华倾负 2024-10-15 19:56:00

听起来您想要的是一个接受用户输入,然后将控制权传递给离线进程(例如 Windows 服务)以从网站异步执行更密集的任务,从而允许用户继续使用该网站(或者去做其他事情)在处理过程中。像这样的事情:

  1. 用户在网站上“启动”“批次”。无论是设置一些值,上传某种批次的东西来处理等等,完全取决于你在做什么。要点是用户启动它。
  2. 进程发挥其魔力所需的信息被保存到数据库中,并且用户被告知该进程已排队等待处理。用户现在可以去做其他事情了。
  3. 后端应用程序(或多个应用程序)定期(每分钟、每 5 分钟等)轮询数据库,或者在上传“批处理”文件的情况下可以使用 FileSystemWatcher 之类的东西来查找新内容做并做他们。使用多线程或任何您需要的方法来实现这一点,但要点是这是一个网站不会等待的“离线”进程。
  4. 当该过程完成时,会在数据库中设置一些标志(在正在处理的记录上,或者可能是用户“收件箱”中的“消息”记录或其他),指示该过程已完成。
  5. 网站 UI 有一些指示器,无论何时加载,都会检查上述标志,以向用户指示排队的进程已完成并准备好查看。

因此,本质上,您有一个由两个应用程序访问的数据库(您的 Web 应用程序和 Windows 服务(或由任务计划程序运行的控制台应用程序等))。

这基本上是您正在寻找的吗?我觉得我可以更具体一点,您对设置有什么具体的担忧吗?

It sounds like what you want is a web site which accepts the user input and then passes control to an offline process (such as a Windows Service) to perform the more intensive tasks asynchronously from the site, allowing the user to continue using the site (or go do something else) while processing takes place. Something like this:

  1. User "initiates" a "batch" on the website. Whether it's setting up some values, uploading some kind of batch of things to process, etc. is entirely up to what you're doing. The main point is that the user starts it off.
  2. The necessary information for the process to do its magic is persisted to the database and the user is told that the process has been queued for processing. The user can now go about doing other things.
  3. The back-end application (or multiple applications) polls the database periodically (every minute, every 5 minutes, etc.) or, in the case of an uploaded "batch" file could use something like a FileSystemWatcher, to look for new things to do and does them. Use multi-threading or whatever you need to make that happen, but the main point is that it's an "offline" process that the website isn't waiting on.
  4. When the process completes, some flag is set in the database (on the record being processed, or maybe a "message" record in the user's "inbox" or whatever) indicating that the process is done.
  5. The website UI has some indicator which, any time it's loaded, checks for the aforementioned flag(s) to indicate to the user that a queued process has been completed and is ready to be viewed.

So, essentially, you have a single database accessed by two applications (your web application and your Windows Service (or console app run by a task scheduler, etc.).

Is that basically what you're looking for? I feel like I could be more specific, do you have any specific concerns about the setup?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文