Response.redirect在URL错误400中添加额外的字符

时间:2010-06-23 20:30:23

标签: asp.net response.redirect

我试图在按钮单击事件服务器端使用response.redirect,但它给了我http 400错误的请求错误。我以前没有收到此错误,但我刚刚将项目移动到2010框架4.0,我开始收到此错误。 这就是我写的:

 protected void bOrganizationAddID_Click(object sender, EventArgs e)
    {
        string MyURL;
        MyURL = "addNewPopup.aspx?orgID=" + this.OrganizationID;

        Response.Redirect(MyURL);



    }

当我尝试构建它时,页面上显示错误的网址是: http://localhost:2504/padrap/pages/admin/%2fpadrap%2fpages%2fadmin%2faddNewPopup.aspx%3forgID%3d33

而不只是: 本地主机:2504 / padrap /页/管理/ addNewPopup.aspx ORGID = 33

请有人帮我。如何获取重定向带我到正确的URL? 谢谢!

2 个答案:

答案 0 :(得分:1)

try-- Server.UrlEncode(this.OrganizationID)

答案 1 :(得分:1)

所以,我认为这是4.0或其他什么的错误,因为我尝试了一切。解决方法是:

ScriptManager.RegisterStartupScript(this, this.GetType(), 
           "redirectFixOrg", string.Format("document.location = '{0}?orgID={1}'",
           this.ResolveClientUrl("~/pages/admin/addNewPopup.aspx"), this.OrganizationID), true);

这对我有用,但我不知道为什么response.redirect不起作用。

谢谢!