protected void Application_BeginRequest(object sender, EventArgs e)
{
string file_path = Request.RawUrl.ToLower();
char[] separator = new char[] { '/' };
string[] parts = file_path.Split(separator, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length > 0 && parts[0] == "de")
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("de");
Context.RewritePath("~/" + file_path.Substring(4), true);
}
else if (parts.Length > 0 && parts[0] == "en")
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en");
Context.RewritePath("~/" + file_path.Substring(4), true);
}
else
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en");
}
}
I am using this code in my WebForms site in order to use the more SEO friendly structure of https://example.com/en/some/url
Rather than the cookie-based system I previously intended to use.
However, now that I have done this I get a 500 error if I don't use a URL that specifies the file also. For example https://example.com/en/ does not work, however /en/default does - what is the proper way to handle this so that both work?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.