我在一个asp.net页面上传视频,将资产保存在会话变量中,然后在另一个asp.net页面中,我使用该资产来希望对视频进行编码(使用azure媒体服务调用)。我提交编码作业时遇到错误(使用job.submit)。它表示访问被拒绝,例外的类型是:system.security.cryptography.cryptographicException。
我想知道原因是我在新页面中创建了一个上下文吗?
以下是第1页的代码:
Dim mediaServicesAccountName As String = ConfigurationManager.AppSettings("accountname")
Dim mediaServicesAccountKey As String = ConfigurationManager.AppSettings("accountkey")
Dim mediaCloud As New CloudMediaContext(mediaServicesAccountName, mediaServicesAccountKey)
Dim assetOptions As New AssetCreationOptions()
asset = mediaCloud.Assets.Create(Filename, assetOptions)
Session("azureasset") = asset
Dim assetFile As IAssetFile = asset.AssetFiles.Create(Filename)
Session("assetFile") = assetFile
以下是第2页的代码: Sub Page_Load 昏暗的资产作为IAsset asset = CType(Session(“azureasset”),IAsset) Dim assetname As String assetname = asset.Name'仅用于调试
_context = New CloudMediaContext(_accountName, _accountKey)
CreateEncodingJob(asset)
End Sub
Private Function CreateEncodingJob(asset As IAsset) As IJob
Dim job As IJob = _context.Jobs.Create("My encoding job")
Dim processor As IMediaProcessor = GetLatestMediaProcessorByName("Windows Azure Media Encoder")
Dim task As ITask = job.Tasks.AddNew("My encoding task", processor, "H264 Broadband 720p", Microsoft.WindowsAzure.MediaServices.Client.TaskOptions.ProtectedConfiguration)
task.InputAssets.Add(asset)
' Add an output asset to contain the results of the job.
' This output is specified as AssetCreationOptions.None, which
' means the output asset is not encrypted.
task.OutputAssets.AddNew("Output asset", AssetCreationOptions.None)
' Use the following event handler to check job progress.
Dim ev As New EventHandler(AddressOf StateChanged)
AddHandler job.StateChanged, AddressOf StateChanged
' Launch the job.
job.Submit()
由于
答案 0 :(得分:0)
我建议只在会话中保留AssetID。然后在创建CloudMediaContext后从CloudMediaContext获取IAsset引用。使用与此类似的代码(C#):
//var assetId = [Get this from Session, not the entire Asset object]
var asset = _context.Assets.Where(x => x.Id.Equals(assetId)).FirstOrDefault();
// no configure the job with this asset..
我最好的选择是确实你再次创建了CloudMediaContext,并且对资产的引用丢失了。您的新媒体上下文实例对您在会话中拥有的此资产对象一无所知。