Csharp/C#教程:SharePoint在后面的代码中获取当前页面的完整URL分享


SharePoint在后面的代码中获取当前页面的完整URL

在SharePoint中,如何从后面的代码中获取您所在页面的URL? 例如,包括blah.aspx页面……

SPContext.Current.Web.Url给出http:// vm / en /

我需要它与http://vm/en/Pages/blah.aspx

您仍然可以获取HttpContext,然后使用HttpContext.Current.Request.Url

SPContext.Current.Web是围绕您所在页面的SPWeb,因此其URL是Web的URL,而不是页面。

尝试: SPContext.Current.File 。 url

您也可以使用HttpContext.Current 。 Request.Url

尝试:SPContext.Current.Web.Url +“/”+ SPContext.Current.File.Url

这应该返回您需要的SPContext.Current.ListItemServerRelativeUrl

此代码适用于我,适用于_layouts下的页面以及网站下的“普通”页面:

  string thisPageUrl; if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("_layouts")) { thisPageUrl = SPContext.Current.Web.Url + context.Request.Path; //note: cannot rely on Request.Url to be correct ! } else { thisPageUrl = HttpContext.Current.Request.Url.ToString(); } 

我使用涵盖_layouts案例的解决方法

上述就是C#学习教程:SharePoint在后面的代码中获取当前页面的完整URL分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 ///  /// Builds real URL considering layouts pages. ///  private Uri CurrentUrl { get { return Request.Url.ToString().ToLower().Contains("_layouts") ? new Uri( SPContext.Current.Site.WebApplication.GetResponseUri( SPContext.Current.Site.Zone).ToString().TrimEnd('/') + Request.RawUrl) : Request.Url; } } 

  string filename = Path.GetFileName(Request.Path); 

 string PageTitle=SPContext.Current.File.Title 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/956546.html

(0)
上一篇 2021年11月20日
下一篇 2021年11月20日

精彩推荐