ICAL 文件验证 (ICAL .NET)
ICAL File Validation (ICAL .NET)
我用 ICAL .NET to create a webcalendar link in my ASP .NET Core application. My service code is inspired from this post :
[AllowAnonymous]
[HttpGet("ical/{icalSecret:Guid}")]
public IActionResult GetICalFeed(Guid icalSecret)
{
var calendar = this.eventService.GetUserCalendar(icalSecret);
var serializer = new CalendarSerializer();
var serializedCalendar = serializer.SerializeToString(calendar);
var contentType = "text/calendar";
var bytes = Encoding.UTF8.GetBytes(serializedCalendar);
return File(bytes, contentType, "calendar.ics");
}
以及生成日历的方法:
public Calendar GetUserCalendar(Guid icalSecret)
{
var user = this._userRepository.GetByICalSecret(icalSecret);
var events = this._eventRepository.GetUserFutureEvents(user.Id);
var calendarEvents = events.Select(evt => new CalendarEvent()
{
Start = new CalDateTime(evt.Start),
End = new CalDateTime(evt.End),
Attendees = evt.Participations.Select(p => new Attendee(){CommonName = p.User.Username, Value = new Uri($"mailto:{p.User.Email}")}).ToList(),
Description = evt.Description
});
var calendar = new Calendar();
foreach (var calendarEvent in calendarEvents)
{
calendar.Events.Add(calendarEvent);
}
return calendar;
}
返回的 ical fil 对我来说似乎很好:
BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:STRING
ATTENDEE;CN=test mail:mailto:test@test.fr
ATTENDEE;CN=test droits:mailto:test@test.fr
ATTENDEE;CN=jm:mailto:test@test.com
ATTENDEE;CN=test:mailto:test@test.fr
DESCRIPTION:string
DTEND:20200610T093036
DTSTAMP:20200602T093344Z
DTSTART:20200610T093036
SEQUENCE:0
UID:a8845fea-6d16-49df-aa5e-a8cf61e1575a
END:STRING
END:VCALENDAR
但是 windows 日历应用程序无法打开它(说它已损坏)并且它在 this ICAL validator.
上验证失败
你知道我做错了什么吗?
好吧,原来我在 ICAL.NET 中使用了错误的字段来存储我的活动名称。应该使用字段 Summary
而不是字段 Name
.
我用 ICAL .NET to create a webcalendar link in my ASP .NET Core application. My service code is inspired from this post :
[AllowAnonymous]
[HttpGet("ical/{icalSecret:Guid}")]
public IActionResult GetICalFeed(Guid icalSecret)
{
var calendar = this.eventService.GetUserCalendar(icalSecret);
var serializer = new CalendarSerializer();
var serializedCalendar = serializer.SerializeToString(calendar);
var contentType = "text/calendar";
var bytes = Encoding.UTF8.GetBytes(serializedCalendar);
return File(bytes, contentType, "calendar.ics");
}
以及生成日历的方法:
public Calendar GetUserCalendar(Guid icalSecret)
{
var user = this._userRepository.GetByICalSecret(icalSecret);
var events = this._eventRepository.GetUserFutureEvents(user.Id);
var calendarEvents = events.Select(evt => new CalendarEvent()
{
Start = new CalDateTime(evt.Start),
End = new CalDateTime(evt.End),
Attendees = evt.Participations.Select(p => new Attendee(){CommonName = p.User.Username, Value = new Uri($"mailto:{p.User.Email}")}).ToList(),
Description = evt.Description
});
var calendar = new Calendar();
foreach (var calendarEvent in calendarEvents)
{
calendar.Events.Add(calendarEvent);
}
return calendar;
}
返回的 ical fil 对我来说似乎很好:
BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:STRING
ATTENDEE;CN=test mail:mailto:test@test.fr
ATTENDEE;CN=test droits:mailto:test@test.fr
ATTENDEE;CN=jm:mailto:test@test.com
ATTENDEE;CN=test:mailto:test@test.fr
DESCRIPTION:string
DTEND:20200610T093036
DTSTAMP:20200602T093344Z
DTSTART:20200610T093036
SEQUENCE:0
UID:a8845fea-6d16-49df-aa5e-a8cf61e1575a
END:STRING
END:VCALENDAR
但是 windows 日历应用程序无法打开它(说它已损坏)并且它在 this ICAL validator.
上验证失败你知道我做错了什么吗?
好吧,原来我在 ICAL.NET 中使用了错误的字段来存储我的活动名称。应该使用字段 Summary
而不是字段 Name
.