我从 asp.net 4 ashx 获取字符串的简单方法有问题。我正在运行此 asp.net 应用程序托管的 silverlight 应用程序的方法。
private void LoadPlugins()
{
var serviceAddress = _baseAddress
+ "PluginsService.ashx?"
+ DateTime.Now.Ticks;
var client = new WebClient();
client.DownloadStringCompleted += client_DownloadStringCompleted;
client.DownloadStringAsync(new Uri(serviceAddress));
}
void client_DownloadStringCompleted(
object sender,
DownloadStringCompletedEventArgs e)
{
var plugins = e.Result.Split(
new string[] { Environment.NewLine },
StringSplitOptions.RemoveEmptyEntries);
foreach (var plugin in plugins)
{
AddXap(_baseAddress + plugin);
}
}
PluginsService.ashx.cs:
namespace MefPlugins.Web
{
/// <summary>
/// Summary description for PluginsService
/// </summary>
public class PluginsService : IHttpHandler
{
private const string PluginsFolderName = "Plugins/";
public void ProcessRequest(HttpContext context)
{
//var pluginFolder = new DirectoryInfo(
// HttpContext.Current.Server.MapPath(
// PluginsFolderName));
//var response = new StringBuilder();
//if (pluginFolder.Exists)
//{
// foreach (var xap in pluginFolder.GetFiles("*.xap"))
// {
// response.AppendLine(
// PluginsFolderName + xap.Name);
// }
//}
var response = new StringBuilder();
response.Append("test");
context.Response.ContentType = "text/plain";
context.Response.Write(response);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
我收到一个错误:
System.Reflection.TargetInvocationException 未被用户代码处理 Message=操作过程中发生异常,导致结果无效。检查 InnerException 以获取异常详细信息。StackTrace: w System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() w System.Net.DownloadStringCompletedEventArgs.get_Result() w MefPlugins.MainPage.client_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e) w System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e) w System. Net.WebClient.DownloadStringOperationCompleted(Object arg) InnerException: System.Net.WebException Message=WebClient 请求期间发生异常。InnerException: System.NotSupportedException Message=无法识别 URI 前缀。
哪里可能是错误?这是来自http://www.galasoft.ch/sl4u/code/chapter20/20.02-Mef/MefPlugins.zip的示例