Do I need to duplicate the script connection in child pages? - asp.net

In the master page, my script is connected in this way:
<script src="scripts/jquery-3.4.1.min.js" type="text/javascript"></script>
And on the pages at the root, the browser developer console does not show errors,
but the following error appears on the child pages:
... /Pages/Scripts/jquery... (Not Found)

No you don't need to duplicate the script tags, it is being rendered on all your pages which use the master page the script just can't be found on pages outside your root. With your current code when a page is rendered it is starting from its current path and appending the src path to determine where to find the script. So your pages in root work but pages in subfolders will not. To correct this resolve your urls properly:
Webforms:
<script src="<%=ResolveUrl("~/scripts/jquery-3.4.1.min.js")%>" type="text/javascript"></script>
Razor:
<script src="#Href("~/scripts/jquery-3.4.1.min.js")" type="text/javascript"></script>

Related

SharePoint App Model - 500 Server Error loading JS from SharePoint

We are trying to get up and running with SharePoint App Model development. However, we are running into a problem.
Firstly, let me state that we have a DNS entry that routes all sundomains in the form of:
*.ourdevserver.ourappdomain.net to the IP of our devserver.
When our app loads, it runs out and attempts to load three js files from SharePoint. Those requests look like this:
MS Ajax:
http:// apps-13c02829da8acd.ourdevserver.ourappdomain.net/_layouts/15/MicrosoftAjax.js
sp.runtime.js:
http:// apps-13c02829da8acd.ourdevserver.ourappdomain.net/_layouts/15/sp.runtime.js
and finally sp.js:
http:// apps-13c02829da8acd.ourdevserver.ourappdomain.net/_layouts/15/sp.js
The GET for each of these files fails with a 500 server error (not a DNS error). This, in turn, prevents the app from working correctly. The code that loads these files is the default code that is created when you start a new SP app project in Visual Studio:
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
Now, I can change the script reference to dispense with the app-xxxxx subdomain and it will work just fine pulling the three files from ourdevserver.ourappdomain.net/_layouts/15/MicrosoftAjax.js. So, it feels like this is an issue with IIS being able to handle the request.
Any ideas?
You can try like this
<script type="text/javascript" src="_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="_layouts/15/sp.js"></script>
It work for me, becasue your app want get parent side's js files which not allowed.

Loading resources while using ASP.NET Forms Authentication

This problem is driving me crazy...
I'm using ASP.Net's Forms Authentication. As you may know, forms authentication adds a query string to the url stating what page to return to after authenticating. This parameter is called ReturnURL.
My problem is, I can't seem to be able to load .js and .css files. I have to use a relative path.
This is how i'm finding the path to my resource files:
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src='<%# ResolveUrl("~/Scripts/jquery-1.4.1.js")%>'></script>
This seems to be resolving the urls as it should. What i get in the page source, under the src atrribute are the actual correct paths to the files.
the thing is, i'm getting errors in the console saying:
Uncaught SyntaxError: Unexpected token < Login.aspxReturnUrl=%2fClickCloudWeb%2fScripts%2fjquery1.4.1.js:3
it seams like he's adding the resource files path as the ReturnURL in the query string and isn't actually loading it.
Doe's anyone have an idea how to overcome this issue?
Thanks,
Uri
Try with <%= instead of <%#. The latest is used for data bind contexts.
<script type="text/javascript" src='<%=ResolveUrl("~/Scripts/jquery-1.4.1.js")%>'>
</script>

how to link css file to aspx in azure host?

I have asp.net app that I am trying to upload to azure host.
first I have try to link in the traditional way with Css folder and link to it
<link href="http://mysite.azurewebsites.net/css/style.css"
rel="stylesheet" type="text/css" />
NOT WORKING
then i create blob and reference to it :
<link href="http://mysite.blob.core.windows.net/scripts/style.css"
rel="stylesheet" type="text/css" />
NOT WORKING
now I dont get error but nothing happend to the styling (after empty my cache and restart the site)
I am not using master pages in my site just normal asp.net page.
i saw in some place that they are doing it with master page but there is other way to do it without master page.
Thanks.

Why is Facebook inserting a preload script for my app's css in HTTP when my page's reference is in HTTPS?

In our app (https://apps.facebook.com/testedenivel), we explicitly reference the page css in a https link like this:
<link rel="stylesheet" href="https://d2asm4nez8zghw.cloudfront.net/content/app-teste-de-nivel.css?v=0.96.02" type="text/css" media="screen">
But strangely, Facebook is preloading this this css file as a HTTP link. At some point before, we used this HTTP url but later we changed it to HTTPS, and now it seems that Facebook is using a former, cached version of that url:
<script type="text/javascript">
new Image().src = "http:\/\/www.talkfast.com.br\/content\/app-teste-de-nivel.css";
</script>
The problem is that when the user enters our app via secure browsing, the HTTP link preloading is causing the browser to alert our users that some insecure content is about to be loaded. We'd like to know how to tell Facebook to remove this preloading script, or at least to use our current HTTPS url, like this:
<script type="text/javascript">
new Image().src = "https://d2asm4nez8zghw.cloudfront.net/content/app-teste-de-nivel.css?v=0.96.02";
</script>
There seems to be scarcity of reference regarding this issue on the web, so any help would be appreciated.
I'm not test this solution in facebook app but on wild web you can use this
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
as proof :)
http://paulirish.com/2010/the-protocol-relative-url/
With this all resources loaded with page protocol, so user don't see confirmation about unsecured elements on page.
Just create test app with Heroku and my chromium not angry about https resouces inside frame so problems depends on browser.

404 Object Not Found for Javascript files

I have a .Net 1.1 webapp.
I have a usercontrol (.ascx) that has links to 3 JS files in
script tags.
When I run the app and load a page with the usercontrol
all is fine and Firebug shows the js files listed.
But when I load another page that loads the usercontrol in a .aspx
in a new browser window Firebug reports 404 object not found
for the 3 JS files.
What could cause this??
Malcolm
You other .aspx page is in a different folder? Possible at a different level in the folder hierarchy? You need to adjust you JS file paths so that they are absolute paths.
You probably have the other page in a different location in the folder hierarchy. Perhaps reference you JS with a server side tag with a ~ in it.
So try changing your JS path to something like this:
<script type="text/javascript" src='<%=ResolveUrl("~/someFolder/functions.js")%>'></script>
Use a tool like Microsoft Fiddler to help you understand the issue.
You could try using a basepath in you pages. In that case each url/image/css/js reference in your website will be relative to the basepath. Using a basepath in your site will prevent big issues when moving files into/from folders.
I usually place the base tag into the master page.
<base href="<%=MyWebsite.Library.Configuration.BasePath%>" />
As you can see the basepath is requested from my configuration, but you can also use .NET code to dertermine the basepath.
Using this constructions saves me a lot of issues when developing my pages. Only problem is that Visual Studio does not completely known how to handle this which causes some warnings about incorrect CssClasses or links.

Resources