IIS - Not serving my JS and CSS files over the internet - iis

I have got my website to work localhost on Windows Server 2019 dedicated IIS 10, but I am trying to reach my site on the internet using my IP address so like this:
http://142.11.195.158/ but my CSS file and JS files are not loading.
and is that why i cant load my CSS and JS files because I am using the IP address to view the website remotely?
I have allowed anonymous access to enabled to my Apppool aswel. my mime types are setup of having these files.
Where am i going wrong?
In my index page im loading the images as so:
<img src="img/service-icon/diamond.png" alt="Service 1">
and
<img class="slide-img" src="~/images/image3.png" alt="Slide 3" />
Im using MVC core 3.1
The files are pointing to here external files:
https://142.11.195.158/css/youtube.css
In my root folder in IIS the css and js files are inside wwwroot, this is how the website got published from visual studio, so my root is wwwroot and inside here is the published css an js files inside wwwroot
--wwwroot (website)
--wwwroot
css
js
Static files is ticked also when i installed Web Server or IIS

I think for the moment, you need to remove this line:
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

Related

Laravel: I can not visualize images when uploading the web to my Hosting

I have a web developed in Laravel, in local I can visualize all the content of the web without problems, I have uploaded the web to my hosting in the domain folder where I want to have the web (it is a shared hosting with several domains), I configured the base of data and modified the .htaccess file. The web loads, however it does not display the logo or the images stored in public / images.
Any idea what this is? I appreciate any guidance
I advance that my web is not in the public_html folder, because that folder is occupied by another web. All the files are in a domain.com folder
This is the method I'm using to call the images src="{{asset('images/test/home/banner-home.jpg')}}"
I have already checked and there are no syntax errors between uppercase and lowercase.
this is the error that I receive in each image:
Failed to load resource: the server responded with a status of 404 (Not Found)
you can do it this way:
in your domain.com, create another folder and move all the files and folders to the newly created folder.
from the newly created folder, copy all the files and folders in public back to domain.com
open your index.php in domain.com and configure this:
i. require DIR.'/newlycreatedfolder/vendor/autoload.php';
ii. $app = require_once DIR.'/newlycreatedfolder/bootstrap/app.php';
i hope all your header files are called using: {{ asset() }} and your logo using {{ url() }}

Serving StyleSheet and JS with Sails

I am a newbie at working with nodeJS and especially with the framework Sails.
I did my research and found that with sails you just need to put CSS-files under the the folder "assets" and call them directly with the URL, e.g. if I put the file custom.css in the folder "assets/foo" I should be able to access it via the URL "localhost:1337/foo/custom.css".
The problem is that my local server throws a 404 Error not being able to find the files, but strangely when I deployed the app to Heroku it works perfectly and I am able to access the css files.
Why is this not working locally?
Welcome to Sails! CSS is served automatically if you put it in your assets/styles folder. Your JS should be in assets/js folder as well. This way you can access it like localhost:1337/assets/js/myjs.js.
In your view - if you don't want to serve it everywhere with a layout - just put your tag like this: <link rel="stylesheet" href="/styles/myawesomestyle.css"> or <script src="/js/mypowerfuljs.js"></script>.
Remember, everything in assets will be made publicly available.
I really recommend that you read the docs HERE.

IIS paths ignoring application folder

I lack the know-how with IIS and IIS manager to even have the proper google terms here, so I hope you'll keep that in mind if you're tempted to click that downvote button.
Thanks.
Okay, so I have an angular application that I just moved over to an an IIS server after developing it locally, without using IIS.
The IIS-based copy of the application works, in that it will serve index.html as expected. Unfortunately, links to external files (.ccs, .js, etc) are all broken.
The application lives in this folder:
\\iis.dev.local\c$\inetpub\wwwroot\the-application
And it's .css file lives here:
\\iis.dev.local\c$\inetpub\wwwroot\the-application\css\main.css
As originally written, the link to that .css file, which we'll call "link 1":
<link rel="stylesheet" href="/css/main.css">
Which worked fine in development, but doesn't work on IIS.
However, this does work, which we'll call "link 2":
<link rel="stylesheet" href="/the-application/css/main.css">
See how I had to add the folder that the application itself sits in? Which is strange, because relative to index.html, "link 1" should be correct--but it isn't.
How can I convince my application that its base url should be the folder it's sitting in, and not one level above?
Random partial guesses and/or useful information?
1) The application sits in the default application pool.
2) Something, something web.config?
EDIT: screwed up some paths.
Try using the <base> HTML Element to set the root.
https://www.tutorialspoint.com/html/html_base_tag.htm
In your example it would be:
<base href="https://www.the-application.com" />
Then the rest should flow, with relative paths.
When developing on your local machine you are most likely running under a Virtual Folder under the DEFAULT website.
When you move to a server you are now running at the ROOT of the site.
Options:
Create a new site on your DEV Machine at the Root of IIS. Then use this path to test your site. When you migrate to production the paths will be the same.
Create a variable with the correct path, and if running LOCALHOST (in the url) use one path, else the other. Use JavaScript to add the link to your HTML (Something I have done with a JavaScript site under IIS for Cordova Development).
Change your page extension from .html to .aspx (yeah I know who wants to do that...) then change your links as follows. (I had to remove the starting < and ending /> in the code below, it would not format in the post)
link rel="Stylesheet" type="text/css" href="<%= ResolveUrl("~/css/main.css") %>"
When you browse your source afterward you will see... (or when you navigate to sub-pages it will put the correct relative path in place for you)
<link rel="Stylesheet" type="text/css" href="css/main.css"/>

node.js - how do i avoid server.js file being downloaded

I am working on MVC4 application. This is how my directory structure looks like:
App_Data
App_Start
Content
Controllers
Images
Models
node_modules
Scripts
Views
server.js //This is where my server script resides
Node.exe
This is how it all fits together:
Server.js is running on a server. User goes to a index.cshtml page and a connection to the server is created. If there are multiple users on the same page, they all can share data/thoughts etc. using "kind of" chat. each user's action is relayed to other connected users.
What i am wondering is how do i avoid someone directly pointing to my server.js file from the browser and view the content of it.
You appear to be running two separate web servers.
The first serves your MVC4 ASP files while the second serves your node.js application.
Placing the node.js files under the webroot of your ASP application makes them visible to browsers that visit your ASP application.
node.js is a web server in it's own right and does not require any other web server to operate.
I would move your node.js application outside of your ASP webroot. This will make its files inaccessible to browsers.

.asp Extension Configuration in IIS

I have installed IIS, and then browsed to a URL representing a file containing:
<!DOCTYPE html>
<html>
<body>
<%
response.write("hello world ");
%>
</body>
</html>
but got this error:
Error Summary
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
What kind of extension configuration have I missed? There is also short summary:
It is possible that a handler mapping is missing. By default, the static file handler processes all
content. The feature you are trying to use may not be installed. The appropriate MIME map is not
enabled for the Web site or application. (Warning: Do not create a MIME map for content that users
should not download, such as .ASPX pages or .config files.) If ASP.NET is not installed.
You need to install ASP support into IIS.
Under Windows 7 (and, as I understand it, Vista): Control Panel | Programs and Features | Turn Windows features on or off | select ASP (under IIS, World Wide Web Services | Application Development Features).

Resources