asp.net
2012-06-22 30 views 0 likes 
0

我在我的aspx页面中使用了此脚本管理器。asp.net中的aspx和.cs页面上的警报脚本和response.redirect

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

当我在本地服务器使用它比它正常工作。和URL看起来像:主机网址:xyz.aspx /管理/ CreateSubAdmin.aspx

下划线部分是在管理部分。

但在服务器上,这是不正确的工作。它看起来像:/admin/CreateSubAdmin.aspx。

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

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

在此先感谢..

回答

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); 

这里的问题是如何使完整的URL是你的案件工作。

可以替代想到用"http:" + Request.Url.Host有完整的URL

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; 
    } 
} 
相关问题