Silverlight文件上载控件无法在托管应用程序上运行。 [英] Silverlight file Upload control not working over hosted application.
本文介绍了Silverlight文件上载控件无法在托管应用程序上运行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在asp.net应用程序中使用银光文件上传控件。它的结构类似如下所示,现在调试localhost:55000 / FileUpload.ashx上传(最终在同一台机器上复制)文件正常,但是当我使用托管应用程序的/FileUpload.ashx时,是不做任何事情,实际上永远不会调用FileUpload.ashx。
I'm Using a silver-light file upload control in asp.net application. Its of similar structure as written below, now While debugging localhost:55000/FileUpload.ashx uploads (eventualy copy on same machine) the file properly, but when i use /FileUpload.ashx of an hosted application, is doesn't do any thing, infact FileUpload.ashx is never called.
public const int CHUNK_SIZE = 4096;
public const string UPLOAD_URI = "http://localhost:55000/FileUpload.ashx?filename={0}&append={1}";
private Stream _data;
private string _fileName;
private long
_bytesTotal;
private long _bytesUploaded;
private void UploadFileChunk()
{
string uploadUri = ""; // Format the upload URI according to wether the it's the first chunk of the file
if (_bytesUploaded == 0)
{
uploadUri = String.Format(UPLOAD_URI,_fileName,0); // Dont't append
}
else if (_bytesUploaded < _bytesTotal)
{
uploadUri = String.Format(UPLOAD_URI, _fileName, 1); // append
}
else
{
return; // Upload finished
}
byte[] fileContent = new byte[CHUNK_SIZE];
_data.Read(fileContent, 0, CHUNK_SIZE);
WebClient wc = new WebClient();
wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);
Uri u = new Uri(uploadUri);
wc.OpenWriteAsync(u, null, fileContent);
_bytesUploaded += fileContent.Length;
}
void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e)
{
if (e.Error == null)
{
object[] objArr = e.UserState as object[];
byte[] fileContent = objArr[0] as byte[];
int bytesRead = Convert.ToInt32(objArr[1]);
Stream outputStream = e.Result;
outputStream.Write(fileContent, 0, bytesRead);
outputStream.Close();
if (_bytesUploaded < _bytesTotal)
{
UploadFileChunk();
}
else
{
// Upload complete
}
}
}
推荐答案
您必须按照 Silverlight提升的权限
$ b所述提供高级权限$ b [ ^ ]。完全信任权限是您应该瞄准的目标..
You have to give elevated permissions as described at Silverlight Elevated Permissions
[^]. Full Trust permissions are what you should aim for..
这篇关于Silverlight文件上载控件无法在托管应用程序上运行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文