Mobile app version of vmapp.org
Login or Join
Murray432

: 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>

@Murray432

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.

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Murray432

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme