在异步调用时,是不是不能使用Server 属性.
Server 属性:获取提供用于处理 Web 请求的方法的 HttpServerUtility 对象。
例如:
1:context.Server.Execute("ActualPage2.aspx");[注:context为HttpContext对象]
2:string fname = Server.MapPath(fname);在异步调用时,以上两个例子都报错,为什么?怎么解决?
代码:
public class Handler:IHttpAsyncHandler
{
private delegate void CreateCommand(HttpContext context);
public Handler()
{
}
public void ProcessRequest(HttpContext context)
{

// Command command = CommandFactory.Make(context.Request.Params);
// command.Execute(context);
// context.Response.Write("sdsfsfsfsfsdfsf");
try
{
lock(this)
{
context.Server.Execute("ActualPage2.aspx");
}
}
catch(Exception err_)
{
context.Response.Write(err_.ToString());
}
}
public bool IsReusable
{
get
{
return true;
}
}
public IAsyncResult BeginProcessRequest(HttpContext ctx, AsyncCallback cb, object obj)
{
CreateCommand command = new CreateCommand(ProcessRequest);
IAsyncResult ar = command.BeginInvoke(ctx,cb,command);
// if (ar.IsCompleted == false)
// {
// System.Threading.Thread.Sleep(500);
// }
ar.AsyncWaitHandle.WaitOne(500,true);
if (ar.IsCompleted)
{
command.EndInvoke(ar);
}
return ar;
}
public void EndProcessRequest(IAsyncResult ar)
{
}
}