重定向具有编码查询字符串的URL时出现404错误 [英] 404 error when redirecting the URL with encoded querystring

查看:130
本文介绍了重定向具有编码查询字符串的URL时出现404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个字符串,它们使用以下代码编码



i have couple of strings and they are encoded using below code

protected void page load()
{
DataTable dt = new DataTable();
               
 dt.Columns.Add("a");
 dt.Columns.Add("b");
 dt.Columns.Add("c");
 dt.Columns.Add("d");
 dt.Columns.Add("e");
 dt.Columns.Add("f");
              
 dt.Rows.Add("value1","value2","value3","value4");

 byte[] ba = ConvertToBytes(dt);

 string data = Convert.ToBase64String(ba);
 string dataEncoded = Server.UrlEncode(data);

Response.Redirect("http://www.project.com/page1.aspx?q=" + dataEncoded, false)

}


  public static byte[] ConvertToBytes(Object obj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, obj);
                return ms.ToArray();
            }
        }





我的尝试:



代码是编码,它重定向到response.redirect中指定的页面。

但重定向后显示404文件或目录未找到错误,



但是Page1.aspx在现场活跃。

如果我省略了查询字符串并重定向正确加载的页面。



有人可以帮我解决这个问题



What I have tried:

The code is encoding and it is redirecting to the page specified in response.redirect .
but after redirecting it is showing 404 file or directory not found error,

but the Page1.aspx is active in live.
if i have omitted the query string and redirects the page it is loading correctly.

can someone help me regarding this

推荐答案

正如你在问题中已经提到的,这个问题当您使用查询字符串并且URL重写无法处理时发生。 Microsoft的文档中也提到了这一点, URL Rewrite模块配置参考| Microsoft Docs [ ^ ]。您可能错过了web.config文件中映射中的 QUERY_STRING 配置; 你有吗?



也是来自SO的类似帖子: IIS URL重写不能使用查询字符串 - Stack Overflow [ ^ ]
As you have already mentioned in your question, this problem occurs when you are using query string and URL rewrite is unable to process that. That is also mentioned in Microsoft's documentation, URL Rewrite Module Configuration Reference | Microsoft Docs[^]. You might have missed the QUERY_STRING configuration in your mappings in web.config file; did you?

Also a similar thread from SO: IIS URL Rewrite not working with query string - Stack Overflow[^]


这篇关于重定向具有编码查询字符串的URL时出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆