Url重写 及重写之后POSTBACK问题

bin目录中添加 Intelligencia.UrlRewriter.dll 文件 http://urlrewriter.net/
并在项目中添加该文件的引用
在IIS中配置让*映射到aspnet_isapi.dll
网站属性>配置>插入(在偏下位置)>


复制.aspx 的可执行文件路径 粘贴到这里,去掉确认文件是否存在的勾
 

web.config 配置
<!--在 web.config 配置--> 
<!--此节点只能作为位于web.config的第一个节点--> 
<configSections>
<section name="rewriter" requirePermission="false" 

type
="Intelligencia.UrlRewriter.Configuration.
RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"
 /> 
</configSections>

<!--在根节点中添加此节点-->
<rewriter>
    
<rewrite url=”~/lmh$” to=”~/Users.aspx?user=lmh” processing=”stop” />
</rewriter>
<!--3.在 <httpModules>节点中添加 -->
    
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter"/>

两个参数的重写

        <rewrite url="^~/shop/(\w{6,20})/(\w+)$" to="~/shop/?user=$1&amp;id=$2" processing="stop" />

 重写URL后 PostBack  出错: 

先看下这个方法,在页面中添加这样几行代码

<script language="javascript" type="text/javascript">
    document.getElementsByTagName(
"form")[0].action = window.location;
</script> 

虽然这样可以解决回传的问题,但是如果用户看源码之后还是可以看到你提交的目标文件

如: 

<form name="aspnetForm" method="post" action="/company/OnlineOrder.aspx" id="aspnetForm">

用 Request.RawUrl 解决这个问题

Request.RawUrl的内容是用户浏览器地址栏请求的页面地址(Request.Url属性才是页面的实际地址这点要搞清楚),
既然这样我们就可以直接在Load事件中处理这个回传的地址

        //网页重定向  
            form1.Action = Request.RawUrl;

之后查看页面源代码

<form name="aspnetForm" method="post" action="/company/15/OnlineOrder.html" id="aspnetForm">

看不到,看不到,真的看不到哈哈!

原文地址:https://www.cnblogs.com/Qbit/p/1670198.html