c#

位置:IT落伍者 >> c# >> 浏览文章

浅谈.NET重写URL


发布日期:2023年08月11日
 
浅谈.NET重写URL

具体使用方法

首先nfig的配置

<?xml version=?><configuration> <configSections>

<section name=RewriterConfig type=URLRewriterConfigRewriterConfigSerializerSectioHandlerURLRewriter />

</configSections>

<RewriterConfig> <Rules> <RewriterRule> <LookFor>~/ListCategories\aspx</LookFor>

<SendTo>~/Defaultaspx</SendTo> </RewriterRule> <RewriterRule>

<LookFor>~/(\d+)l</LookFor> <SendTo>~/Coveraspx?id=$</SendTo> </RewriterRule> </Rules>

</RewriterConfig> <systemweb> <httpModules>

<add type=URLRewriterModuleRewriter URLRewriter name=ModuleRewriter/> </httpModules>

<compilation debug=true/></systemweb>

</configuration>

主要配置的代码是这些其他的根据自己的需要的版本自行添加

然后DefaultaspxCoveraspx新建个页面

Defaultaspx

<%@ Page Language=C# AutoEventWireup=true CodeFile=Defaultaspxcs Inherits=_Default %>

<!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

<html xmlns=><head runat=server>

<title>无标题页</title></head><body> <form id=form runat=server>

<div>

<a >ListCategoriesaspx</a>

<a >l</a> </div> </form></body><

/html>Coveraspx

<%@ Page Language=C# AutoEventWireup=true CodeFile=Coveraspxcs Inherits=Cover %>

<%@ Register TagPrefix=skm Namespace=ActionlessForm Assembly=ActionlessForm %>

<!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

<html xmlns=><head runat=server>

<title>Cover</title></head><body> <skm:form id=form runat=server>

<div> Cover页面 <h><a javascript:void() onclick=historygo()>返回上一页</a></h>

<asp:Button ID=Button runat=server Text=Button />

</div>

</skm:form></body></html>Coveraspxcs

using System;

using SystemCollections;

using SystemConfiguration;

using SystemData;

using SystemLinq;

using SystemWeb;using SystemWebSecurity;

using SystemWebUI;

using SystemWebUIHtmlControls;

using SystemWebUIWebControls;

using SystemWebUIWebControlsWebParts;

using SystemXmlLinq;public partial class Cover : SystemWebUIPage{

protected void Page_Load(object sender EventArgs e)

{

if (RequestQueryString[id] == null)

{

ResponseEnd();

}

else

{

int id = ConvertToInt(RequestQueryString[id]); ResponseWrite(id);

}

}

}

还要去对iis设置

这样的话伪静态就可以用了

C:\WINDOWS\MicrosoftNET\Framework\v\aspnet_isapidll 这是上面的路径

浏览Defaultaspx页

ListCategoriesaspx 页面其实在服务器上面是没有的它里面的内容是Defaultaspx的内容因为配置文件里面设置了

具体使用方法

首先nfig的配置

<?xml version=?><configuration> <configSections>

<section name=RewriterConfig type=URLRewriterConfigRewriterConfigSerializerSectioHandlerURLRewriter />

</configSections> <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/ListCategories\aspx</LookFor>

<SendTo>~/Defaultaspx</SendTo> </RewriterRule> <RewriterRule>

<LookFor>~/(\d+)l</LookFor> <SendTo>~/Coveraspx?id=$</SendTo>

</RewriterRule> </Rules> </RewriterConfig>

<systemweb> <httpModules> <add type=URLRewriterModuleRewriter URLRewriter name=ModuleRewriter/>

</httpModules> <compilation debug=true/>

</systemweb>

</configuration>

主要配置的代码是这些其他的根据自己的需要的版本自行添加

然后DefaultaspxCoveraspx新建个页面

Defaultaspx

<%@ Page Language=C# AutoEventWireup=true CodeFile=Defaultaspxcs Inherits=_Default %>

<!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

<html xmlns=><head runat=server>

<title>无标题页</title></head><body> <form id=form runat=server>

<div>

<a >ListCategoriesaspx</a>

<a >l</a> </div> </form></body>

</html>Coveraspx

<%@ Page Language=C# AutoEventWireup=true CodeFile=Coveraspxcs Inherits=Cover %>

<%@ Register TagPrefix=skm Namespace=ActionlessForm Assembly=ActionlessForm %>

<!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

<html xmlns=><head runat=server>

<title>Cover</title></head><body>

<skm:form id=form runat=server> <div> Cover页面 <h><a javascript:void() onclick=historygo()>返回上一页</a>

</h>

<asp:Button ID=Button runat=server Text=Button />

</div>

</skm:form>

</body>

</html>Coveraspxcs

using System;

using SystemCollections;

using SystemConfiguration;using SystemData;

using SystemLinq;

using SystemWeb;

using SystemWebSecurity;

using SystemWebUI;

using SystemWebUIHtmlControls;

using SystemWebUIWebControls;

using SystemWebUIWebControlsWebParts;

using SystemXmlLinq;public partial class Cover : SystemWebUIPage

{

protected void Page_Load(object sender EventArgs e)

{

if

(

RequestQueryString[id] == null)

{

ResponseEnd();

}

else

{

int id = ConvertToInt(RequestQueryString[id]); ResponseWrite(id);

}

}

}

还要去对iis设置

这样的话伪静态就可以用了

C:\WINDOWS\MicrosoftNET\Framework\v\aspnet_isapidll 这是上面的路径

浏览Defaultaspx页

ListCategoriesaspx 页面其实在服务器上面是没有的它里面的内容是Defaultaspx的内容因为配置文件里面设置了

               

上一篇:.NET中的企业库异常处理块简述

下一篇:关于C#中动态加载AppDomain的问题