我想生成頁(yè)面文件路徑,然后修剪 .aspx...我已經(jīng)嘗試了下面的代碼,但這不起作用。Windows 世界的新手,我已經(jīng)習(xí)慣了 Linux,所以請(qǐng)保持友善 :D編輯:下面我的代碼的錯(cuò)誤是:編譯器錯(cuò)誤消息:CS1525:表達(dá)式術(shù)語(yǔ)“[”無(wú)效,但是一旦修復(fù),它就會(huì)不斷地吐出錯(cuò)誤。我相信我可能只是弄錯(cuò)了這項(xiàng)任務(wù)的基本原理。public partial class MasterPage : System.Web.UI.MasterPage{protected void Page_Load(object sender, EventArgs e){ string thepath = Page.ResolveUrl(Request.RawUrl); string thepath = Trim([.aspx] trimChars); string[] a = thepath.Split('/'); for (int i = 0; i < a.Length - 1; i++) { thepath += a[i].ToLower() + "/"; ; } Canonical.Text = "<link rel=\"canonical\" href=\"https://example.com" + thepath.ToLower() + "\" />\n";}}
1 回答

largeQ
TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊
[.aspx]無(wú)效,您沒有修剪任何東西。將其更改為以下內(nèi)容:
string thepath = Page.ResolveUrl(Request.RawUrl);
thepath = thepath.Replace(".aspx","");
這將根據(jù)您的需要進(jìn)行,但如果您在字符串中的其他任何地方都有 .aspx,它也會(huì)替換那里。如果你只想要結(jié)尾,你仍然可以使用,TrimEnd但恕我直言,它有點(diǎn)老套。
string thepath = Page.ResolveUrl(Request.RawUrl);
thepath = thepath.TrimEnd(".aspx".ToCharArray());
- 1 回答
- 0 關(guān)注
- 182 瀏覽
添加回答
舉報(bào)
0/150
提交
取消