protected override void Render(HtmlTextWriter writer)
    {
        if (HttpContext.Current.Items["VirtualURL"] != null)
        {
            string sVirURL = HttpContext.Current.Items["VirtualURL"].ToString();
            RewriteFormHtmlTextWriter oWriter = new RewriteFormHtmlTextWriter(writer, sVirURL);
            base.Render(oWriter);
        }
    }HttpContext.Current.Items["VirtualURL"]在什么情况下是有值的?如果这样获得不了,那应该怎么获得?

解决方案 »

  1.   

    你是看别人的代码吧?整个项目里搜索一下“VirtualURL”就有了。
    术语是:当前请求的上下文。就是表示一个请求的周期中的一个存储空间,这么理解就好了。
      

  2.   

    Item 存储在页上下文中的对象的列表。
      

  3.   

    Step1
    Create a new C# Class Library project in Visual Studio.NET and name it "MyHandler". Visual Studio.NET will automatically add a class named "Class1.cs" into the project. Rename it "NewHandler"; open this class in the code window and change the class name and constructor name to "NewHandler". 
    The following is the code for the NewHandler class. using System;
    using System.Web;namespace MyHandler
    {
     /**//// <summary>
     /// Summary description for NewHandler.
     /// </summary>
     public class NewHandler : IHttpHandler
     {
      public NewHandler()
      {
       //
       // TODO: Add constructor logic here
       //
      }  Implementation of IHttpHandler#region Implementation of IHttpHandler
      public void ProcessRequest(System.Web.HttpContext context)
      {
       HttpResponse objResponse = context.Response ;
    objResponse.Write("<html><body><h1>Hello 15Seconds   Reader ") ;
       objResponse.Write("</body></html>") ;
      }  public bool IsReusable
      {
       get
       {
        return true;
       }
      }
      #endregion
     }
    }
    As you can see in the ProcessRequest method, the HTTP handler has access to all ASP.NET intrinsic objects passed to it in its parameter through the System.Web.HttpContext object. Implementing the ProcessRequest method is simply extracting the HttpResponse object from the context object and then sending some HTML out to the client. Similarly, IsReusable returns true to designate that this handler can be reused for processing the other HTTP requests. 
    Let's compile it and place it in the bin directory of the webapp virtual directory. Step 2
    Register this handler by adding the following text in the web.config file: <httpHandlers>
      <add verb="*" path="*.15seconds" type="MyHandler.NewHandler,MyHandler"/>
    </httpHandlers>Step 3
    Since we are creating a handler for handling files of a new extension, we also need to tell IIS about this extension and map it to ASP.NET. If we don't perform this step and try to access the Hello.15seconds file, IIS will simply return the file rather than pass it to ASP.NET runtime. As a consequence, the HTTP handler will not be called. 
    Launch the Internet Services Manager tool, right click on Default Web Site, select Properties, go to Home Directory tab and press Configuration button. This will popup Application Configuration dialog. Click Add button and fill the Executable field with the path to the aspnet_isapi.dll file and fill .15seconds in the Extension field. Leave the other fields as is; the dialog box should look as follows: Now we are good to go. Launch Internet Explorer and go to the following url: http://localhost/webapp/hello.15seconds You should see the following page: 
      

  4.   

    是的,我在codeproject里找到一个示例关于Url Rewriting的,根据他的配置,我执行到上面所说的那一步,因为HttpContext.Current.Items["VirtualURL"] 的值得不到,执行不下去了.是关于重写的回发处理.
    http://www.codeproject.com/KB/ISAPI/URLRewriting.aspx