: EDIT: this method requires the .aspx extension I recently did this and it was suprisingly very easy to do. In my App_Data folder I have a xml file like the folowing: <urlrewrites>
EDIT: this method requires the .aspx extension
I recently did this and it was suprisingly very easy to do.
In my App_Data folder I have a xml file like the folowing:
<urlrewrites>
<rewrite url="/hy2345.aspx" to="~/propertydetails.aspx?id=hy2345" />
<rewrite url="/hy2346.aspx" to="~/propertydetails.aspx?id=hy2346" />
</urlrewrites>
And in my global.asax this quick routine:
void Application_Beginrequest(object sender, EventArgs e)
{
string ext = System.IO.Path.GetExtension(Context.Request.Path);
if (ext != ".aspx")
{
return;
}
string root = Request.Url.GetLeftPart(UriPartial.Authority);
string fullOriginalPath = Request.Url.ToString();
string relativePath = fullOriginalPath.Replace(root, "");
System.Xml.XmlDocument objXML = new System.Xml.XmlDocument();
objXML.Load(Server.MapPath("~/App_Data/URLRewrites.xml"));
foreach (System.Xml.XmlNode node in objXML.DocumentElement.ChildNodes)
{
if (node.Name.ToLower() == "rewrite")
{
string url = node.Attributes.GetNamedItem("url").Value.ToString();
if (relativePath.ToLower() == url.ToLower())
{
string to = node.Attributes.GetNamedItem("to").Value.ToString();
Context.RewritePath(to);
break;
}
}
}
}
If your page is handling postbacks you will need to implement the form browser yadda from here as a post back will expose the unwritten url.
More posts by @Murray432
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.