当我尝试创建按需流定位器时,服务器有时会返回以下错误:
发生了一个或多个错误。微软WindowsAzure。媒体服务。客户端:处理此请求时出错。
定位器的ExpirationDateTime不能为过去
.
以下是部分代码:
using System.Net;
using Microsoft.WindowsAzure.MediaServices.Client;
...
public static readonly TimeSpan ExpirationTimeThreshold = TimeSpan.FromHours(5);
public static readonly DateTime TimeSkew = DateTime.UtcNow.AddMinutes(-5);
...
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
string assetId = req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "assetId", true) == 0).Value;
IAsset wantedAsset = _context.Assets.Where(a => a.Id.Equals(assetId)).FirstOrDefault();
if (wantedAsset == null)
{
return req.CreateResponse(HttpStatusCode.BadRequest,
"No asset matches the Id");
}
originLocator = wantedAsset.Locators.Where(l => l.Type == LocatorType.OnDemandOrigin).FirstOrDefault();
if (originLocator == null)
{
IAccessPolicy policy = _context.AccessPolicies.Create("Streaming policy",
ExpirationTimeThreshold,
AccessPermissions.Read);
originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, wantedAsset,
policy,
TimeSkew); //This is where the exception is returned
}
...
}
有一次,当这种情况发生时,我试图将日志语句放入Azure函数中,当我保存更改时,该函数按预期工作。
TimeSkew
变量将不会更新,直到我保存对Azure函数的更改。
这意味着第一次运行时
例如,下午5:00,5小时后
TimeSkew公司
ExpirationTimeThreshold
和
TimeSkew公司
制作
然后局部变量应该解决我的问题?