Loading resources while using ASP.NET Forms Authentication - asp.net

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>

Related

Do I need to duplicate the script connection in child pages?

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>

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.

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.

Controller factory receiving request for "favicon.ico"

I've noticed that a request to "favicon.ico" is being passed to my ASP .NET MVC controller factory when using Google Chrome and the Visual Studio Development Server. The controllerType parameter has a value of null which is unsurprisingly resulting in an unhandled exception, which I only know about because of an error log.
Any ideas where the request is coming from and why ASP .NET is letting it get to the controller factory? CSS files and images for example are being correctly filtered out.
With IIS7 in integrated mode all requests are tunneled to the pipe. you can add it to your ignore routes
asp.net mvc does it handle all requests? - iis 7 integrated mode
Another resource
http://weblogs.asp.net/gunnarpeipman/archive/2009/02/26/asp-net-mvc-ignore-requests-to-favicon-ico.aspx
Bear in mind to you only seeing this as you are in debug mode. Your users wont see it (Not optimal still, but hey I didn't design it)
I have also noticed this occuring with chrome. I believe it is the browser looking for the site favicon (little icon next to its tab) with the default path of /favicon.ico. MVC trys to find a controller matching that route and comes up blank.
Easiest fix is probably just to add favicon image in your root directory called favicon.ico or using a link tag in the head section of your html to point it somewhere else.
eg
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />

ASP.NET MVC IIS7 Better configuration

I have a simple but script and css fashioned ASP.NET MVC Application, within the VS2008 Development server everything goes well, but when I bring it to IIS7 I experiment some ugly script and images issues.. Scripts are not found by relative paths (this expecially in the default routed page) and images too.
After some research and googlin' I found many examples and provided solutions, but anything really solves the problem, Someone says one solution soude be using the Url.Content method but I hate to use it because I lost all the javascript intellisense feature in VS2008..
I found too this issue maybe different if the mvc project is shipped in a root web site or in a web application.. I know in a root web site it could works because referencing relative paths like
<script src="../../Scripts/myScript.js" type="text/javascript" />
in a web application folder is resolved without the root.
Anybody has some suggestion or someting else? I Intend after to start something to build a sort of configuration "guide"..
Thaks in advance
It may have been me that suggested using Url.Content. If so, I neglected the other half of what I do -- wrapping a relative path in an if (false) block to retain intellisense. Below is a (full) example of how I handle javascript.
<% if (false) { %>
<script type="text/javascript"
src="../../Scripts/jquery-1.3.1.min.js">
</script>
<% } %>
<script type="text/javascript"
src='<% Url.Content( "~/Scripts/jquery-1.3.1.min.js" ) %>'>
</script>

Resources