asp.net
2012-06-22 35 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; 
    } 
} 
相關問題