Web 表单处理脚本,用于在服务器上执行后台作业,然后在准备好时发送电子邮件
我正在 C# ASP.NET 中开发一个应用程序,允许用户使用其公司徽标自定义许多图形模板。
通常,
- 用户上传他们的公司徽标。
- 用户选择多个不同文件类型的模板(通过 HTML 表单)进行定制。
- 我的 Web 应用程序将接受用户的请求,检查请求的每个单独项目并确定其文件类型。然后,它将根据文件类型调用适当的模块(例如自定义 PDF),最后将徽标插入模板中。对每个请求的文件重复这些步骤。
- 一旦生成了用户请求的所有模板,它们就会被分组到一个 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,
- User uploads their company logo.
- User selects a number of templates (through a HTML form) of different file types for customising.
- 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.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想要的是一个接受用户输入,然后将控制权传递给离线进程(例如 Windows 服务)以从网站异步执行更密集的任务,从而允许用户继续使用该网站(或者去做其他事情)在处理过程中。像这样的事情:
因此,本质上,您有一个由两个应用程序访问的数据库(您的 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:
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?