Reputation: 1003
I have a travel related web application in which my url looks like
MyTravel/Tour/Inner.aspx?Pid=2&Cid=8
and
MyTravel/Tour/Inner.aspx?Pid=2&Cid=8&DeptF=ND
Now I want url rewriting on my application like
MyTravel/Tour/Goa/new-year-goa
here goa and new year goa are fetched by pid and cid values.
Help me.
Thanks in advance
[EDIT: Reformation]
Upvotes: 1
Views: 5574
Reputation: 995
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.
}
}
You can look at this http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Or else you can modify your web.config
to achieve the goal,
here is the sample,
<?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>
[EDIT: Following Can be one solution]
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")
and Request.QueryString("Cid")
Context.ReWritePath("Your Specified Path")
The other way to do this is using database,
pid
, cid
, and location_path
cid
and pid
using above mentioned Request.QueryString
cid
and pid
fetched by Request.QueryString
and set it using Context.ReWritePathHopefully this is clear to you now.
Hope it helps.
Upvotes: 1