0

我在我的 aspx 页面中使用了这个脚本管理器。

ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('Registered Successfully !!'); window.location='" + Request.ApplicationPath + "/admin/CreateSubAdmin.aspx';", true);

当我在本地服务器中使用它时,它工作正常。和 url 看起来像:主机 url:xyz.aspx/admin/CreateSubAdmin.aspx

下划线部分在管理部分。

但在服务器上这不能正常工作。它看起来像:/admin/CreateSubAdmin.aspx 而已。

但我希望它显示为 www.xyz.com/admin/CreateSubAdmin.aspx。

所以我写错了。请帮助我。

提前致谢..

4

2 回答 2

0

您唯一必须做的就是删除ApplicationPath, 或删除第一个斜线。

ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit",
 "alert('Registered Successfully !!'); window.location='" + Request.ApplicationPath + "admin/CreateSubAdmin.aspx';", true);

或者

ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", 
 "alert('Registered Successfully !!'); window.location='/admin/CreateSubAdmin.aspx';", true);

这里的问题是如何制作适用于您的案例的完整网址。

您可以选择使用 来构建它"http:" + Request.Url.Host以获得完整的 url

于 2012-06-22T11:48:47.223 回答
0

我使用这样的辅助函数:

public static string GetApplicationRoot()
{
    string host = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
    string applicationPath = HttpContext.Current.Request.ApplicationPath;
    if (applicationPath == "/")
    {
        return host;
    }
    else
    {
        return host + applicationPath;
    }
}
于 2012-06-22T11:58:28.483 回答