C# 用于语言本地化的URL重写将删除默认页面功能

C# 用于语言本地化的URL重写将删除默认页面功能,c#,asp.net,webforms,C#,Asp.net,Webforms,我在我的WebForms站点中使用这段代码是为了使用对SEO更友好的 而不是我之前打算使用的基于cookie的系统 然而,现在我已经这样做了,如果我没有使用指定文件的URL,我会得到一个500错误。例如,不起作用,但是/en/default起作用-什么是正确的方法来处理这一问题,使两者都起作用?创建一个多语言站点 比如 请发布您用来重写URL的代码。我看不出任何人能在没有看到代码的情况下帮助你。它在上面提供。。。上面写着protectedvoidapplication_BeginR

我在我的WebForms站点中使用这段代码是为了使用对SEO更友好的

而不是我之前打算使用的基于cookie的系统


然而,现在我已经这样做了,如果我没有使用指定文件的URL,我会得到一个500错误。例如,不起作用,但是/en/default起作用-什么是正确的方法来处理这一问题,使两者都起作用?

创建一个多语言站点

比如


  • 请发布您用来重写URL的代码。我看不出任何人能在没有看到代码的情况下帮助你。它在上面提供。。。上面写着protectedvoidapplication_BeginRequest(objectsender,EventArgs e)的一段话,我刚想到通过视频URL从其他方面做类似的事情
    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");
            }
    
        }