c# - c#为Outlook生成ics文件
问题描述
我创建了一个 ashx 文件,该文件生成一个用于 Outlook 的 ics 文件。我的 1 个日历代码运行良好。我现在添加了这样一个事实,即 ashx 页面接受一个 guid,该 guid 用于检查数据库应该生成哪个日历。
因此,人们可以通过在其末尾添加另一个 guid,从单个 ashx 文件中添加多个日历。现在的问题是第一个日历生成正常,但第二个失败。我看到它在 ashx 文件中达到了我的断点,它生成的一切都很好,但 Outlook 似乎没有收到它。我假设 Outlook 阻止了 ics 文件的生成,因为对他来说它是相同链接的两倍。
然后我在我的网络服务器上实现了 url 重定向,使其看起来像是多个不同的 url 到 Outlook。我再次看到它两次命中断点,但只生成了 1 个日历,另一个给我错误“无法验证或将日历添加到 Outlook,......”并且链接有效。
因为它来自同一个 ashx 文件,outlook 是否仍然阻止刷新多个日历?
public class CalendarService : IHttpHandler
{
private readonly OutlookCalendarDomainLogic _domainLogic = InitializeDomainLogic();
private static OutlookCalendarDomainLogic InitializeDomainLogic()
{
var repository = new OutlookCalendarRepository();
OutlookCalendarDomainLogic logic = new OutlookCalendarDomainLogic(repository);
return logic;
}
public void ProcessRequest(HttpContext context)
{
if (!Guid.TryParse(context.Request["Guid"], out Guid guid))
{
return;
}
var co = _domainLogic.GetOutlookCalendarByGuid(guid);
..... Event generation code
//send the calendar item to the browser
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "text/calendar";
HttpContext.Current.Response.AddHeader("content-length", CalendarItem.Length.ToString());
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=\"" + CalendarName + ".ics\"");
HttpContext.Current.Response.Write(CalendarItem);
HttpContext.Current.Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
有任何想法吗?
解决方案
推荐阅读
- reactjs - 如何在 saga 中测试 firebase 功能?
- reactjs - 如何在 reactjs 的 CKEditor5 工具栏中添加下划线选项和对齐选项
- javascript - 获取触发事件的复选框的 ID
- django - 可以将用户/配置文件链接到先前创建的名称,该名称通过外键链接到模型
- spyder - 如何在 Spyder 4 中禁用代码折叠?
- python - 使用烧瓶更新 Web 应用程序中的变量
- java - TimerTask Scheduler 在静态引用其他类对象后不起作用
- swift - 如何在 Swift 中嵌入文件?
- c++ - 使用 `emplace_back` 而不是 `push_back` 时没有缩小警告
- excel - Excel 数据中的变音符号