ASP.NET Routing for URLRewriting with QueryStrings
In the last post I showed how to use the ASP.NET 3.5 Routing Engine
for URLRewriting purposes. I want to go further in this post by adding
the ability to add variables into a route path and forward and append
query string variables to the destination Web Form request.
A route can contain one or more variables expressed by its {name}.
RouteTable.Routes.Add(
new
Route(
"articles/{id}"
,
new
devcoach.Web.RoutingPageHandler()));
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
Inside of the RoutingHandler we can iterate through the variables by
accessing them by the RouteData property on the parameter passing the
RequestContext:
var queryString = new
StringBuilder("?"
);
foreach
(var aux in
requestContext.RouteData.Values)
{
queryString.Append(
requestContext.HttpContext.Server.UrlEncode(aux.Key));
queryString.Append("="
);
queryString.Append(
requestContext.HttpContext.Server.UrlEncode(
aux.Value.ToString()));
queryString.Append("&"
);
}
queryString.Remove(queryString.Length - 1, 1);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0e
Ïà¹ØÎĵµ£º
¿Í»§¶ËÑéÖ¤·½Ê½£º
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
&nbs ......
ÔÚASP.NETÖÐʹÓÃTreeview¿Ø¼þºÍXML
ÒÔÇ°£¬ÔÚWEBÒ³ÃæÖÐÈç¹ûÏëʹÓÃÊ÷ÐοؼþµÄ»°£¬ÍùÍù»áÓÐЩÂé·³£¬ÓÐʱÉõÖÁÒª×Ô¼ºÐ´´úÂëÀ´´ïµ½ÓÃÊ÷ÐÎÁбíÏÔʾÊý¾ÝµÄÄ¿µÄ¡£ÔÚasp.netÖУ¬ÎÒÃÇ¿ÉÒԺܷ½±ãµØʹÓÃÓÉ΢ÈíÌṩµÄInternet Exploer Web Controls¿Ø¼þÀ´ÊµÏÖÊ÷ÐÎÁÐ±í¡£ÔÚ΢ÈíÌṩµÄÕâÌ×Internet Exploere Web Controls¿Ø¼þ¼¯ºÏÖУ¬°üÀ ......
ûÓÐÏëµ½ÕæµÄÕâô·½±ã!¸ü¼Ó¼á¶¨ÎÒѧϰASP.NETµÄ¾öÐÄ! ÏÖÔÚÎÒÃÇÒ»ÆðÀ´¿´¿´°É
1,ÇëÈ·¶¨ÄãµÄµçÄÔ°²×°ÁËÒÔϵÄÈí¼þ£¡
1.1£¬ WINDWOS 2000ÒÔÉÏ°æ±¾(±Ø×°)
1.2£¬ .NET Framework(±Ø×°)
1.3£¬ Visual Studio .NET 2005(±Ø×°)
2,½¨Á¢Ò»¸öACCESSÊý¾Ý¿â,
3,Í϶¯VS2005 µÄGRIDVIEW µ½Éè ......
asp.netÖÐʹÓûùÓÚ½ÇÉ«roleµÄFormsÑéÖ¤£¬´óÖ¾¹ý¼¸ÏÂËIJ½£º
1.ÅäÖÃϵͳweb.config
timeout="20" path="/" />
ÆäÖÐ ±íʾ±¾Ó¦ÓóÌÐò²ÉÓÃFormsÑéÖ¤·½Ê½¡£
1). ±êÇ©ÖеÄname±íʾָ¶¨ÒªÓÃÓÚÉí·ÝÑéÖ¤µÄ HTTP Cookie¡£Ä¬ÈÏÇé¿öÏ£¬name µÄÖµÊÇ .ASPXAUTH¡£²ÉÓôËÖÖ·½Ê½ÑéÖ¤Óû§ºó,ÒÔ´ËÓû§µÄÐÅÏ¢½¨Á¢Ò»¸öFormsAuthenticati ......
1. ´ò¿ªÐµĴ°¿Ú²¢´«ËͲÎÊý£º
¡¡¡¡´«ËͲÎÊý£º
response.write("£¼script£¾window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)£¼/script£¾")
¡¡¡¡½ÓÊÕ²ÎÊý£º
string a = Request.QueryString("id");
string b = Request.QueryStrin ......