网址在asp.net 3.5有多个查询字符串重写 [英] Url rewriting in asp.net 3.5 with multiple querystring

查看:99
本文介绍了网址在asp.net 3.5有多个查询字符串重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旅游相关的Web应用程序中,我的网址看起来像

I have a travel related web application in which my url looks like

MyTravel/Tour/Inner.aspx?Pid=2&Cid=8

MyTravel/Tour/Inner.aspx?Pid=2&Cid=8&DeptF=ND

现在我想URL重写我的应用程序像

Now I want url rewriting on my application like

MyTravel/Tour/Goa/new-year-goa

这里

果阿和新年果阿是通过PID和CID值进账。

here goa and new year goa are fetched by pid and cid values.

帮我。

在此先感谢

推荐答案

URL重写可以做如下,

URL rewriting can be done as follows,

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.
    }
} 

您可以看看这个的http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

否则你可以修改的web.config 来实现这一目标,

Or else you can modify your web.config to achieve the goal,

下面是样品,

<?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 那么相应的重定向,

ok. So as you are saying you need to check pid and cid so redirect accordingly,

要实现这一点的一种方式是以下,

One way to achieve this is below,


  • 的Request.QueryString(PID)的Request.QueryString(CID)

  • 它们存储到一些变量,

  • 检查这些变量与一些开关...案件的机制,并根据情况通过使用设置 Context.ReWritePath(您指定的路径)
  • Request.QueryString("Pid") and Request.QueryString("Cid")
  • store them into some variables,
  • check those variables with some switch...case mechanism and according to the passed condition set the path using Context.ReWritePath("Your Specified Path")

另一种方式做,这是使用数据库,

The other way to do this is using database,


  • 创建包含三列, PID CID location_path

  • 现在,让 CID PID 使用上述的Request.QueryString

  • 使用SQL查询,可从中选择与 CID PID 按<$获取配衬表中的位置C $ C>的Request.QueryString 并使用Context.ReWritePath设置

  • create a table containing three columns, pid, cid, and location_path
  • Now get the cid and pid using above mentioned Request.QueryString
  • using sql query, select the location from the table which matchs with the cid and pid fetched by Request.QueryString and set it using Context.ReWritePath

希望这是清楚你现在。

希望它帮助。

这篇关于网址在asp.net 3.5有多个查询字符串重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆