Hi,
I migrated my legacy webapplication written in html to asp.net . every thing working except the html pages. when the user is requesting for .html page i need to give corresponding aspx page which is created with same name.
ex: when user requests for http://techpalle.com/net-training-in-bangalore.html to another page with the extension
http://techpalle.com/net-training-in-bangalore.aspx.
i have written the code for doing the same in my global.asax file which is working in my development server ( asp.net development server cassini) but not in the live server where iis8.0 is used.
code in global.asax
void Application_BeginRequest(object sender, EventArgs e) { string fullOrigionalpath = Request.Url.Segments[Request.Url.Segments.Length - 1].ToLower(); if (fullOrigionalpath.Contains(".html")) { fullOrigionalpath = fullOrigionalpath.Replace(".html", ""); } bool isAspxPage = true; foreach (var item in new string[] { ".png", ".gif", ".jpeg", ".jpg", ".tiff", ".bmp",".css",".js" }) { if (fullOrigionalpath.Contains(item)) isAspxPage = false; } if (isAspxPage)//execute this code only when the request is not coming for any image files. { try { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(Server.MapPath(ConfigurationManager.AppSettings["urlmappingfile"])); System.Xml.XmlNode node = doc.SelectSingleNode(string.Format("{0}{1}", "urlmappings/", fullOrigionalpath)); if (node != null) { Context.RewritePath(node.InnerText); string meta_desc=ConfigurationManager.AppSettings["meta_desc"]; meta_desc=meta_desc.Replace("{0}", fullOrigionalpath); //string.Format(meta_desc, fullOrigionalpath); string meta_key = fullOrigionalpath; HttpContext.Current.Items.Add("meta_desc", meta_desc); HttpContext.Current.Items.Add("meta_key", meta_key); //Context.Session["meta_desc"] = meta_desc; //Context.Session["meta_key"] = meta_key; } else if (fullOrigionalpath.Contains(".aspx")) { Context.RewritePath(fullOrigionalpath); } else { Context.RewritePath("home.aspx"); } } catch (Exception ex) { //Log exception details. } } //bool b1=fullOrigionalpath.Contains<string>(".gif"); }
regards
Lokanatha Reddy Palle