C# 在asp.net 3.5中使用多个查询字符串重写Url
我有一个与旅游相关的web应用程序,其中我的url看起来像C# 在asp.net 3.5中使用多个查询字符串重写Url,c#,asp.net,url,url-rewriting,C#,Asp.net,Url,Url Rewriting,我有一个与旅游相关的web应用程序,其中我的url看起来像 MyTravel/Tour/Inner.aspx?Pid=2&Cid=8 及 现在我想在我的应用程序上重写url,比如 MyTravel/Tour/Goa/new-year-goa 这里的goa和新年goa由pid和cid值获取 帮帮我 提前谢谢 [编辑:重新编写]URL重写可以按如下方式完成 void Application_BeginRequest(object sender, EventArgs e) { s
MyTravel/Tour/Inner.aspx?Pid=2&Cid=8
及
现在我想在我的应用程序上重写url,比如
MyTravel/Tour/Goa/new-year-goa
这里的goa和新年goa由pid和cid值获取
帮帮我
提前谢谢
[编辑:重新编写]URL重写可以按如下方式完成
void Application_BeginRequest(object sender, EventArgs e) {
string fullOrigionalpath = Request.Url.ToString();
if (fullOrigionalpath.Contains("/Tour/Inner.aspx?Pid=2&Cid=8")) {
Context.RewritePath("/Tour/Goa/new-year-goa");
}
else if (fullOrigionalpath.Contains("/Tour/Inner.aspx?Pid=2&Cid=8&DeptF=ND")) {
Context.RewritePath("/Tour/Goa/new-year-goa");
//This can be something else according to your requirements.
}
}
你可以看看这个
或者,您可以修改web.config
以实现此目标
这是样品
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
</system.web>
<rewriter>
<rewrite url="~/Tour/Inner.aspx?Pid=2&Cid=8" to="~/Tour/Goa/new-year-goa" />
//Some other re-writers to achieve specific requirements.
</rewriter>
</configuration>
//其他一些重写器可以达到特定的要求。
[编辑:以下可以是一个解决方案]
嗯。因此,正如您所说,您需要检查pid
和cid
以便相应地重定向
实现这一目标的一个方法是:
和Request.QueryString(“Pid”)
Request.QueryString(“Cid”)
- 将它们存储到一些变量中
- 使用一些switch…case机制检查这些变量,并根据传递的条件使用
Context.ReWritePath(“您指定的路径”)
- 创建一个包含三列的表,
、pid
和cid
location\u path
- 现在使用上述
请求获取
和cid
。QueryStringpid
- 使用sql查询,从表中选择与
获取的Request.QueryString
和cid
匹配的位置,并使用Context.ReWritePath进行设置pid
希望有帮助。URL重写可以按如下方式完成
void Application_BeginRequest(object sender, EventArgs e) {
string fullOrigionalpath = Request.Url.ToString();
if (fullOrigionalpath.Contains("/Tour/Inner.aspx?Pid=2&Cid=8")) {
Context.RewritePath("/Tour/Goa/new-year-goa");
}
else if (fullOrigionalpath.Contains("/Tour/Inner.aspx?Pid=2&Cid=8&DeptF=ND")) {
Context.RewritePath("/Tour/Goa/new-year-goa");
//This can be something else according to your requirements.
}
}
你可以看看这个
或者,您可以修改web.config
以实现此目标
这是样品
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
</system.web>
<rewriter>
<rewrite url="~/Tour/Inner.aspx?Pid=2&Cid=8" to="~/Tour/Goa/new-year-goa" />
//Some other re-writers to achieve specific requirements.
</rewriter>
</configuration>
//其他一些重写器可以达到特定的要求。
[编辑:以下可以是一个解决方案]
嗯。因此,正如您所说,您需要检查pid
和cid
以便相应地重定向
实现这一目标的一个方法是:
和Request.QueryString(“Pid”)
Request.QueryString(“Cid”)
- 将它们存储到一些变量中
- 使用一些switch…case机制检查这些变量,并根据传递的条件使用
Context.ReWritePath(“您指定的路径”)
- 创建一个包含三列的表,
、pid
和cid
location\u path
- 现在使用上述
请求获取
和cid
。QueryStringpid
- 使用sql查询,从表中选择与
获取的Request.QueryString
和cid
匹配的位置,并使用Context.ReWritePath进行设置pid
希望有帮助。我不确定SEO,你必须现场测试才能确认。谢谢先生,实际上我有很多包,所以ID(Pid=2&Cid=8)将超过200个,所以请告诉我如何动态(使用正则表达式/模式匹配)实现这一目标,我不想将其作为硬代码处理。此
fullOrigionalpath.Contains(“/Tour/internal.aspx?Pid=2&Cid=8”)
将检查url是否包含Pid=2&Cid=8
。在我们的例子中,如果您希望它们重定向到相应的url,则需要指定所有Cid
和Pid
。正则表达式将允许您检查是否存在Pid和Cid,但要重定向,您必须将它们进行比较以确定是否存在打包并相应地重定向它们…先生,实际上我想要的是,如果pid是33(agra),cid是540(tajmahal)然后它看起来像MyTravel/Tour/agra/tajmahal,如果没有查询,那么它就直接搬到家里去了。所以你怎么可能给我提供一个示例代码呢?这很紧急。嗯,我不确定SEO,你必须对它进行现场测试才能确认。谢谢先生,实际上我有很多包,所以ID(Pid=2&Cid=8)请告诉我如何动态地(使用正则表达式/模式匹配)实现这个目标,我不想把它当作硬代码来处理。这个fulloriginalpath.Contains(“/Tour/internal.aspx?Pid=2&Cid=8”)
将检查url是否包含Pid=2&Cid=8
。在我们的例子中,如果您希望它们重定向到相应的url,则需要指定所有Cid
和Pid
。正则表达式将允许您检查是否存在Pid和Cid,但要重定向,您必须将它们进行比较以确定是否存在打包并相应地重定向它们…先生,实际上我想知道,如果pid是33(agra),cid是540(tajmahal),那么它看起来像MyTravel/Tour/agra/tajmahal,如果没有查询字符串,那么它就简单地移动到家中。那么,您如何可能向我提供一个示例代码呢?这非常紧急。