asp.net 4.0中的URL重写 [英] URL Rewriting in asp.net 4.0
本文介绍了asp.net 4.0中的URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在我的代码中重写url。请帮我这个,我犯了一个错误。
1. Global.asax
< pre lang =cs> void Application_Start( object sender,EventArgs e)
{
// 在应用程序启动时运行的代码
RegisterRoute(RouteTable.Routes);
}
public static void RegisterRoute(RouteCollection routeCollection)
{
routeCollection.MapPageRoute( Customer, 客户/ {培训}, 〜/ Customer.aspx);
}
2. Default.aspx
< asp:HyperLink ID = HyperLink1 < span class =code-attribute> runat = server NavigateUrl = 〜/ Customer / Customer.aspx?Training = software > 客户< / asp:HyperLink >
3 .customer.aspx.cs
if (Page.RouteData.Values [ 培训]!= null )
{
string category = Page.RouteData.Values [ Training]。ToString()?? string .Empty;
Label1.Text = category;
}
解决方案
步骤-1将以下代码放在web.config中
< system.web >
<! -
设置编译debug =true将调试
符号插入编译页面。由于此
会影响性能,因此在开发期间将此值设置为true仅
。
- >
< urlMappings 已启用 = true >
< add url = 〜/关于@ 123 mappedUrl = Default2.aspx / >
< / urlMappings >
Step-2看按钮点击
受保护 void Button1_Click( object sender,EventArgs e)
{
Response.Redirect( 〜/关于@ 123跨度>);
}
I m unable to rewrite url, below in my code. kindly help me with this, where i made a mistake.
1. Global.asax
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoute(RouteTable.Routes);
}
public static void RegisterRoute(RouteCollection routeCollection)
{
routeCollection.MapPageRoute("Customer", "Customer/{Training}", "~/Customer.aspx");
}
2. Default.aspx
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Customer/Customer.aspx?Training=software">Customer</asp:HyperLink>
3. Customer.aspx.cs
if (Page.RouteData.Values["Training"] != null)
{
string category = Page.RouteData.Values["Training"].ToString() ?? string.Empty;
Label1.Text = category;
}
解决方案
step -1 Put the below code in web.config
<system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. --> <urlMappings enabled="true"> <add url="~/About@123" mappedUrl="Default2.aspx"/> </urlMappings>
Step- 2 See the Button click
protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("~/About@123"); }
这篇关于asp.net 4.0中的URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文