博文

如何在Windows Form中实现URL Encoding/Decoding?(2006-08-31 14:22:00)

摘要:如果你想在Windows Forms中实现URL Encoding,HttpUtility类有一个shared (static)方法实现对字符串的URL 编码。下面就是一个例子:【注意要在工程的引用里添加引用System.Web】using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Web; namespace WindowsApplication1 { /// /// Form1 的摘要说明。 /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Button button2; /// /// 必需的设计器变量。 /// private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.......

阅读全文(8438) | 评论:0

使用c#建立虚拟目录 (2006-08-10 15:02:00)

摘要:最近在CSDN论坛里看见网友的一片偏关于使用.net 创建虚拟目录的帖子, 以前一直以为不能用托管代码实现这个功能...            在此总结一下:)         下面是创建虚拟目录的代码              const String constIISWebSiteRoot = "IIS://localhost/W3SVC/1/ROOT";                string virtualDirName = "virtualName";//虚拟目录名称                string physicalPath = @"c:\1";                DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);                 DirectoryEntry tbEntry = root.Children.Add(virtualDirName, root.SchemaClassName);                ......

阅读全文(2467) | 评论:0

处理HTML代码的若干函数 (2006-08-10 15:01:00)

摘要:经过了上个星期的努力学习,对处理html又有了新的发现感觉真的很不错可以说js的威力在处理html代码方面我又有所领悟了1、截取特定长度字符串     Public Shared Function CutString1()Function CutString1(ByVal str As String, ByVal length As Integer) As String        Dim i As Integer = 0        Dim j As Integer = 0        For Each chr As Char In str            If Asc(chr) > 127 Then                i = i + 2            Else                i += 1 &......

阅读全文(2648) | 评论:0

page事件顺序(.net2.0) (2006-08-10 15:00:00)

摘要:   Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit 如果有MasterPage的话,在这里执行MasterPage里面的page事件,事件顺序在这篇文章里有写道  Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init   Protected Sub Page_InitComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.InitComplete  Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete Protected Sub Page_SaveStateComplete(ByVal sender As Object, ......

阅读全文(4648) | 评论:0

ASP.NET 中执行 URL 重写 (2006-08-10 14:59:00)

摘要:URL 重写就是把URL地址重新改写(汗^_^)。详情:http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx优点:把url缩短等用法:1.下载ms的URLRewrite.dll,放到你的bin下2.在web.config里设置如下:~/d(\d+)\.aspx~/default.aspx?id=$1type="URLRewriter.RewriterFactoryHandler, URLRewriter" />然后在cs里写:private void Page_Load(object sender, System.EventArgs e){// 在此处放置用户代码以初始化页面Response.Write(Request.QueryString["id"]+"");Response.Write("haha");}只要输入localhost/overred/d123.aspx(注意:开头必须为d,后为数字)其实这个d123.aspx是虚拟的,并不是实际存在的。只要符合格式就行。他就会跳到http://localhost/overred/default.aspx而且他在default里可以捕捉一些参数比如id,就是你的d后的数字(后必须为数字),这样你就可以显示id为123的文章。在重写后的url里如果产生回发将会传递到d123.aspx,这样用户在点button时会看到哪个实际的地址,msdn上说的:但从用户的角度考虑,如果单击按钮时突然看到 URL 更改会使他们感到不安。可见ms把客户捧为他的上帝!(真的?#¥%……—*)继续引用ms:出现这种情况的原因是:在呈现 Web 窗体时,它会将其操作属性直接设置为 Request 对象中文件路径的值。当然,在呈现 Web 窗体时,URL 已从 /Products/Beverages.aspx 重写为 ListProductsByCategory.aspx?CategoryID=1,这表明 Request 对象报告用户要访问 ListProductsByCategory.aspx?CategoryID=1。只需使服务器端窗体不呈现操作属性即可解决此问题。(默认情况下,如果窗体不包含操作属性,浏览器将会回发。)不幸......

阅读全文(3098) | 评论:0

URL 重写的常见用法(2)(2006-08-10 14:55:00)

摘要:使用 HTTP 模块执行 URL 重写 创建 HTTP 模块与创建可以实现 IHttpModule 接口的类一样简单。IHttpModule 接口定义了两种方法: • Init(HttpApplication)。此方法在初始化 HTTP 模块后触发。在此方法中,您将把事件处理程序绑定到相应的 HttpApplication 事件。 • Dispose()。当请求已完成并已发送回 IIS 时调用此方法。您应当在此处执行所有最终的清除操作。 为了便于为 URL 重写创建 HTTP 模块,我将从创建抽象基类 BaseModuleRewriter 开始介绍。此类将实现 IHttpModule。在 Init() 事件中,它将 HttpApplication 的 AuthorizeRequest 事件绑定到 BaseModuleRewriter_AuthorizeRequest 方法。BaseModuleRewriter_AuthorizeRequest 方法将调用该类传入被请求的 Path 的 Rewrite() 方法,以及传入 Init() 方法的 HttpApplication 对象。Rewrite() 方法是抽象的,也就是说,在 BaseModuleRewriter 类中,Rewrite() 方法没有方法主体;从 BaseModuleRewriter 派生而来的类必须覆盖此方法并提供方法主体。 具有此基类后,只需创建由 BaseModuleRewriter 派生的类即可,该类可以覆盖 Rewrite() 并在那里执行 URL 重写逻辑。下面显示了 BaseModuleRewriter 的代码。public abstract class BaseModuleRewriter : IHttpModule { public virtual void Init(HttpApplication app) { // 警告!此代码不适用于 Windows 身份验证! // 如果使用 Windows 身份验证, // 请改为 app.BeginRequest app.AuthorizeRequest += new Eve......

阅读全文(3972) | 评论:0

ASP.net的URL重写(2006-08-10 14:48:00)

摘要:ASP.net的RUL重写 有关于URL的重写,本文也只是拿来主意。相继有MS的组件“URLRewriter”和在Global.asax里的“Application_BeginRequest()”编码方式,以及IIS里的ISAPI设置。娜列下来,实现方法也都很简单。方法一:MS组件这里也不用详解了,相关请看:http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx用法很简单,只需要把组件URLRewriter.dll拷到应用程序的bin目录下,然后在web.config下加入如下代码:在中加入:~/(\d{4})/(\d{2})/Default\.aspx~/Default.aspx?ID=$1然后在中加入: ......

阅读全文(3741) | 评论:0

c#写的asp.net程序url重写问题,解决有分(2006-08-10 14:40:00)

摘要:对于高手来说,这个问题是老生常谈了 可我一直很困惑,不知道如何在c#写的asp.net中实现; 占时使用的是三方的 ISAPI_Rewrite,这样才程序中有很多就发挥不了效果了 .... 请教各位大虾,如何在c#写的asp.net程序中实现 url的重写功能能 ! 问题解决着有分 !!! 最简单的 http://support.microsoft.com/kb/308001/zh-cn: HOW TO:使用 Visual C# .NET 创建 ASP.NET HTTP 处理程序 概要 实现处理程序 部署处理程序 配置系统 测试模块 参考 .toc{display: none;} 概要 本分步指南演示如何使用 Visual C# .NET 创建简单的自定义 HTTP 处理程序。本文演示如何创建、部署和配置该处理程序。 实现处理程序 1. 打开 Microsoft Visual Studio .NET。 在 Visual C# .NET 中,新建一个名为 MyHandler 的类库项目。 2. 设置一个对 System.Web.dll 程序集的引用。 3. 将以下指令添加到该类中: using System.Web; 4. 重命名类 SyncHandler.cs,然后相应地更改类定义。 5. 实现 IHttpHandler 接口。您的类定义应如下所示: public class SyncHandler : IHttpHandler 6. 实现 IHttpHandler 接口的 IsReusable 属性和 ProcessRequest 方法。因为这是一个同步处理程序,所以为 IsReusable 属性返回 False 以使该处理程序不共用。 public bool IsReusable { get {return false;} } public void ProcessRequest(HttpContext context) { context.Response.Write("Hello from custom handler."); } 7. 编译项目。 部署......

阅读全文(3913) | 评论:1

如果使用HTML传递和接收参数值(2006-08-10 14:36:00)

摘要:如果使用HTML传递和接收参数值? 将以下代码另存为HTML文件:alixixi.htm,然后打开站点:http://127.0.0.1/alixixi.htm?log_id=111&cat_id=222&page=333 回车即可显示演示效果,正常接收由HTML文件传递的值. <script language="JScript"><!-var LocString=String(window.document.location.href);function GetQueryString(str){var rs=new RegExp("(^|)"+str+"=([^\&]*)(\&|$)","gi").exec(LocString),tmp;if(tmp=rs)return tmp[2];return "没有这个参数";}alert("日记编号:"+GetQueryString("log_id"));alert("分类编号:"+GetQueryString("cat_id"));alert("所在页数:"+GetQueryString("page"));--></script> ......

阅读全文(5033) | 评论:0

利用WebClient和WebRequest类获得网页源代码(2006-08-10 14:28:00)

摘要:利用.NET框架提供的 WebClient类 和 WebRequest类,我们可以很轻易地得到给定URL地址的源代码,很简单,以下是C#的完整的例子. 查看例子 GetPageHtml.aspx 得到网页源代码 得到任意网页源代码 http://dotnet.aspx.cc/content.aspx GetPageHtml.aspx.csusing System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using System.Net; using System.Text; using System.Text.RegularExpressions; namespace eMeng.Exam { /// /// GetPageHtml 的摘要说明。 /// public class GetPageHtml : System.Web.UI.Page { protected System.Web.UI.WebControls.Button WebClientButton; protected System.Web.UI.WebControls.Button WebRequestButton; protected System.Web.UI.WebControls.TextBox ContentHtml; protected System.Web.UI.WebControls.TextBox UrlText; ......

阅读全文(2255) | 评论:0