WebParts con JavaScript non funziona con il percorso gestito
-
10-12-2019 - |
Domanda
Ho sviluppato WebParts SharePoint 2010 con JavaScript e CSS (all'interno di un modulo).Non ho problemi sull'ambiente di sviluppo ma nell'ambiente di produzione.
Nell'ambiente di produzione ho un generatore di webapplication (http://productionapplication/)
con il percorso gestito "Corp" (http://productionapplication/corp/)
e un "Prodotto" di SiteCollection (http://productionapplication/corp/product)
.
Ottieni la richiesta HTTP fallisce per il mio JavaScript e CSS sul caricamento dei miei WebParts.Script e CSS sono correttamente implementati all'interno "http://productionapplication/corp/product/MyDocumentLibrary/"
Come posso risolvere il mio problema?
Grazie per il tuo supporto.
Soluzione
Because you're on SharePoint Foundation (thus you cannot use the $SPUrl expression), I would suggest that you resort to some classic ASP.Net tricks to workaround your issue:
Add a runat="server" and id attributes to the link element
<link id="css1" runat="server" rel="stylesheet" type="text/css" media="screen" href="" />
Within the Page_Load method, add this code:
css1.Attributes["href"] = SPUrlUtility.CombineUrl(SPContext.Current.Web.ServerRelativeUrl, "/MyDocumentLibrary/Css/example.css");
Altri suggerimenti
Try the SPUrl
token:
<link rel="stylesheet" type="text/css" media="screen" href='<% $SPUrl:~site/MyDocumentLibrary/Css/example.css %>' />
If that doesn't work, try the full relative path to you managed path:
<link rel="stylesheet" type="text/css" media="screen" href="corp/product/MyDocumentLibrary/Css/example.css" />