加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

asp.net url重写浅谈

发布时间:2021-07-13 08:03:02 所属栏目:Asp教程 来源:互联网
导读:ActionlessForm.dll------用来处理回发 URLRewriter.dll----- 是微软封装好了的一个URL重写组件 添加引用---- 具体的使用说明请去看 #XSLTsection123121120120 比我说得好得多。。 具体使用方法: 首先web.config的配置: 复制代码 代码如下: ?xml version=
ActionlessForm.dll------用来处理回发
URLRewriter.dll----- 是微软封装好了的一个URL重写组件
添加引用----
具体的使用说明请去看
#XSLTsection123121120120
比我说得好得多。。
具体使用方法:
首先web.config的配置:

复制代码 代码如下:


<?xml version="1.0"?>
<configuration>
<configSections>
<section type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,
URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/ListCategories.aspx</LookFor>
<SendTo>~/Default.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(d+).html</LookFor>
<SendTo>~/Cover.aspx?id=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<system.web>
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter"/>
</httpModules>
<compilation debug="true"/>
</system.web>
</configuration>


主要配置的代码是这些。其他的根据自己的需要和.net的版本自行添加。
然后Default.aspx,Cover.aspx,新建2个页面
Default.aspx:

复制代码 代码如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form runat="server">
<div>
<a href="http://www.jb51.net/article/ListCategories.aspx">ListCategories.aspx</a>
<a href="http://www.jb51.net/article/30.html">30.html</a>
</div>
</form>
</body>
</html>


Cover.aspx:

复制代码 代码如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cover.aspx.cs" Inherits="Cover" %>
<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Cover</title>
</head>
<body>
<skm:form runat="server">
<div>
Cover页面
<h4><a href="javascript:void(0)">返回上一页</a></h4>
<asp:Button runat="server" Text="Button" />
</div>
</skm:form>
</body>
</html>


Cover.aspx.cs:

复制代码 代码如下:


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Cover : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] == null)
{
Response.End();
}
else
{
int id = Convert.ToInt32(Request.QueryString["id"]);
Response.Write(id);
}
}
}


还要去对iis设置:

asp.net url重写浅谈

这样的话伪静态就可以用了
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_isapi.dll ---这是上面的路径

浏览Default.aspx页

ListCategories.aspx --页面其实在服务器上面是没有的。它里面的内容是Default.aspx的内容,因为配置文件里面设置了

写得有点乱。

本例子是和微软的重写url基本一样的。算是简单化了一点点呵呵。

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读