Can't load image from project folder in Orchard module
Asked Answered
M

1

5

I'm trying to insert a image in my Orchard module, but I'm having some problems.

<img  src="@Href("~/Modules/Orchard.Slider/Content/img/other.jpg")"/>

In my view i wrote thibut the image is not loading, it says that resource is not found. However, if I put my picture in Orchard.Users module folder, it is working:

<img  src="@Href("~/Modules/Orchard.Users/Content/img/other.jpg")"/>

Does anyone know why this is happening? Is this a bug, or I'm missing something?

Just to add, that when I tried to build the same module for the first time, I loaded image from my folder normally (with the first line of code), but I couldn't include css file, as

@{Style.Include("slider_style.css");}

didn't produce anything. It isn't the case that I had in my html source, with the 'resource not found thing' - there wasn't any line considering the inclusion of slider_style.css

Then I created same project again, and now I can include css, but can't load images. The thing is that i just copy/pasted the code, only change was that I actually made a new Orchard module project and new .cs and cshtml. files.

Thanks in advance, Stefan

Magel answered 24/2, 2012 at 9:50 Comment(0)
M
8

Try placing the following web.config file inside the img folder.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>
  <system.web>
    <httpHandlers>
      <!-- iis6 - for any request in this location, return via managed static file handler -->
      <add path="*" verb="*" type="System.Web.StaticFileHandler" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers accessPolicy="Script,Read">
      <!--
      iis7 - for any request to a file exists on disk, return it via native http module.
      accessPolicy 'Script' is to allow for a managed 404 page.
      -->
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
    </handlers>
  </system.webServer>
</configuration>
Magnolia answered 24/2, 2012 at 10:1 Comment(2)
Thanks man, it's working. The thing is that I somehow managed to load image without the web.config before, so it confused me and I totally forgot about it.Magel
no problem, i'm glad it's working. And i have no idea why it was working before, because u just need this config to tell IIS that files can be read from there :)Magnolia

© 2022 - 2024 — McMap. All rights reserved.