我用JavaScript和CSS(在一个模块内)开发了一个SharePoint2010WebParts。我在开发环境上没有问题,但在生产环境中。

在生产环境中,我有一个Web应用程序 (http://productionapplication/) 使用托管路径"公司" (http://productionapplication/corp/) 和SiteCollection"产品" (http://productionapplication/corp/product).

在加载我的WebParts时,我的JavaScript和CSS的HTTP请求失败。脚本和CSS内部正确部署 "http://productionapplication/corp/product/MyDocumentLibrary/"

如何解决我的问题?

谢谢你的支持。

有帮助吗?

解决方案

因为你在SharePoint Foundation(因此你不能使用$SPUrl表达式),我建议你诉诸一些经典ASP.Net 解决问题的技巧:

在link元素中添加runat="server"和id属性

<link id="css1" runat="server" rel="stylesheet" type="text/css" media="screen" href="" />

在Page_Load方法中,添加以下代码:

css1.Attributes["href"] = SPUrlUtility.CombineUrl(SPContext.Current.Web.ServerRelativeUrl, "/MyDocumentLibrary/Css/example.css");

其他提示

试试 SPUrl 令牌:

<link rel="stylesheet" type="text/css" media="screen" href='<% $SPUrl:~site/MyDocumentLibrary/Css/example.css %>' />

如果这不起作用,请尝试使用托管路径的完整相对路径:

<link rel="stylesheet" type="text/css" media="screen" href="corp/product/MyDocumentLibrary/Css/example.css" />
许可以下: CC-BY-SA归因
scroll top