Image is not loaded in MVC5 JQuery during initial Load requested via IIS - asp.net-mvc-5

1.When pointing the URL as "http:/servername/virtualdirectory" and for example i am setting image path as ../Content/Images/xx.png using jquery in js file then the images is not loaded
2.When pointing the URL as "http:/servername/virtualdirectory/controllername/action" and for example i am setting image path as ../Content/Images/xx.png using jQuery in js file then the Images is loaded.
Questions is why the image is not loaded during IIS request from routeconfig.cs ie 'http:/servername/virtualdirectory' in MVC5

Try using <img src="~/Content/Images/xx.png"> in your Razor syntax. This will generate a correct path to your image.

Related

How to check if image is loaded in Express and replace with default local image?

I have collection with image, where the src is external URL.
I want when the image is not found(not working url), to be replace it with local default image?
Is there a way to check if the image is loaded and replace it in middleware? Some equivalent onError event in the browser?
I found front-end solution, in which is added event listener for 'onerror' event to every image and replace its src attribute. I need back-end solution!

Non-english url path

In next.js that uses php-like approach - files in pages folder became url paths. Like /pages/reader.js will be loaded by url http://localhost/reader.
Problem is that i can't undersand how to use non-english url path in next.js?
Codesandbox example. (Update page to load from server)
Url example:
http://localhost/читатель
That changes internally by chrome to:
http://localhost/%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C
In next.js pages folder file named:
pages/читатель.tsx // not working
pages/%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C.tsx //working but i can't name files like that, i will not find what i need later.
Maybe php users resolved this somehow ;)
try to use encodeURI() of core javascript which can convert the specific characters to the required url form
const url=encodeURI('читатель.tsx');
console.log(url);//%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C.tsx
Then we can use this path to navigate

Image(s) not showing when using nodejs with handlebars (.hbs)

I have tried to search for an answer here but nothing so far worked, not many threads about handlebars. Im at my 2nd year of coding and struggling to get images to show up on my node app.
I have this on app.js and below that the code im trying to get image to show up on the .hbs file:
app.use(express.static('img/'));
<img src="bckground.jpg" alt="teeest" />
Thank you in advance if someone knows what to do.
Supposing that you are serving your application at "http://localhost:3000", and your web page is "http://localhost:3000/index.html", you are requesting the image "bckground.jpg", so the browser will try to load "http://localhost:3000/bckground.jpg". This is wrong, because you are serving the static images folder under the "img" path, so the image is available at "http://localhost:3000/img/bckground.jpg".
If your application is being served at the "root" path of the domain, then this should work for you:
<img src="/img/bckground.jpg" />
Note the initial "/" at the image path. This means that the path will be calculated from the root folder of the domain. You should take this into account if you are serving your application in a subfolder.

When serving files with nginx , the browser shows the html file content in all javascript files

I have build a project on node, express,angular js and have deployed using nginx but when I see the source code in the browser , I find that all the javascript files are loaded with HTML content. What could be the possible reason.?enter image description here

AS3 - URLRequest not working

My flash SWF needs to load "photo.jpg" using URLRequest but in vain. Heres how I am doing it
imLoader = new Loader();
imLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
imLoader.load(new URLRequest("photo.jpg"));
The SWF and photo are both located in the same directory on my localhost server. When i render it in the browser, photo doesn't load. But when i do it manually by simply opening the SWF, photo loads up properly.
Is it something related to crossdomain or what is the problem?
The path is relative to the HTML document. So if your image and SWF are not in the same directory as the HTML you need to provide a path (absolute or relative to the HTML).
So if your SWF and image are in 'media' directory you would need:
imLoader.load(new URLRequest("media/photo.jpg"));
//or
imLoader.load(new URLRequest("/media/photo.jpg"));
//or (if SWF and image are on different server)
imLoader.load(new URLRequest("http://www.domain.com/media/photo.jpg"));

Resources