首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • Url重写问题 [已结贴,结贴人:jack20080808]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-21 10:59:14 楼主
       
    C# code
    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"]在什么情况下是有值的?如果这样获得不了,那应该怎么获得?
    20  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • iuhxq
    • 等级:
    发表于:2008-05-21 11:24:111楼 得分:10
    你是看别人的代码吧?

    整个项目里搜索一下“VirtualURL”就有了。


    术语是:当前请求的上下文。

    就是表示一个请求的周期中的一个存储空间,这么理解就好了。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-21 11:26:412楼 得分:2
    Item 存储在页上下文中的对象的列表。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-21 13:46:413楼 得分:8
    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:

    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-21 14:59:494楼 得分:0
    引用 1 楼 iuhxq 的回复:
    你是看别人的代码吧?

    整个项目里搜索一下“VirtualURL”就有了。


    术语是:当前请求的上下文。

    就是表示一个请求的周期中的一个存储空间,这么理解就好了。

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


    http://www.codeproject.com/KB/ISAPI/URLRewriting.aspx
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-05-21 15:01:405楼 得分:0
    也就是说我不想通过字符串组合的方式来得到重写后的地址,想知道有没有属性或方法能得到重写后的伪地址?
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-07-15 15:44:476楼 得分:0
    我已經用另一種方法做了,上面雖然沒有我要的答案,但來者有分
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    世纪乐知(北京)网络技术有限公司 版权所有 京 ICP 证 020026 号
    Copyright © 2000-2007, CSDN.NET, All Rights Reserved