URL重写:使用微软的URLRewrite组件进行ASP.NET URL
概述
URL重写是截取传入Web请求并自动将请求重定向到其他 URL 的过程,比如浏览器发来请求hostname/101.aspx ,服务器自动将这个请求中定向为http://hostname/list.aspx?id=101。
url重写的优点在于:
* 缩短url,隐藏实际路径提高安全性
* 易于用户记忆和键入。
* 易于被搜索引擎收录
实现url重写的基本方法
下载MS的URLRewriter.dll,放到你的web程序的bin下,下载地址:download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi
下载完成后,在web.config里设置如下
<?xml version="1.0" encoding="utf-8" ?>
<!--overred-->
<configuration>
<configSections>
<section name="RewriterConfig"type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/d(\d+)\.aspx</LookFor>
<SendTo>~/default.aspx?id=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<system.web>
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
相关文档:
protected void Button6_Click(object sender, EventArgs e)
{
this.Label11.Text = HtmlEncode(this.TextBox3.Text);
}
protected static string HtmlEn ......
1、通过附加一个cookiecontainer到httprequest对象中,可以得到登录后返回的代表SESSION ID的COOKIE。
2、将此COOKIE包含在一个cookiecontainer中并附加到另一个HTTPREQUEST请求中,则可以实现SESSION的还原。
部分主要代码:
CookieContainer cookieContainer =& ......
web.config
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb=" ......
Default..aspx
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
Default..aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.We ......
#region 域名绑定方法
public static void AddHostHeader(int siteid, string ip, int port, string domain)//增加主机头(站点编号.ip.端口.域名)
{
DirectoryEntry site = new DirectoryEntry("IIS://localhost/W3SVC/" + siteid) ......