1. Add a global.asax file to your project: <%@ Application Language="C#" %> <script language="C#" runat="server"> protected void Application_BeginRequest(object sender, EventArgs e) { string[] s = Context.Request.Url.AbsoluteUri.Split('/'); if (s.Length > 0) { string q = s[s.Length - 1]; Context.RewritePath("WebForm4.aspx?a=" + q); }
}</script> For the simplicity I hardcoded the rewrited path. 2. In WebForm4.aspx add following code to test: protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["a"] != null) { Response.Write(Request.QueryString["a"]); } } 3.http://localhost:port/aaa
<system.web>
下加入 urlMappings
下添加如下代码
如:<urlMappings enabled="true">
<clear/>
<add url="~/default.aspx" mappedUrl="~/news.aspx"/>
</urlMappings>
<%@ Application Language="C#" %>
<script language="C#" runat="server">
protected void Application_BeginRequest(object sender,
EventArgs e)
{
string[] s = Context.Request.Url.AbsoluteUri.Split('/');
if (s.Length > 0) {
string q = s[s.Length - 1];
Context.RewritePath("WebForm4.aspx?a=" + q);
}
}</script>
For the simplicity I hardcoded the rewrited path.
2. In WebForm4.aspx add following code to test:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["a"] != null) {
Response.Write(Request.QueryString["a"]);
}
}
3.http://localhost:port/aaa