I am new to mvc. I have created one web application in asp.net-mvc-2.
src="../../images/1.jpg"
This is working when I debug from project but it is not loading from iis. Can anybody help me?
I will suggest you to use UrlHelper.Content Method, It converts a virtual (relative) path to an application absolute path.
Example
#Url.Content("~/images/1.jpg")
Here The ~ character matches the root of the site /.
<img alt="Picture Display" src="<%= Url.Content("~/images/1.jpg")" />
this solved my problem
Related
I have images sitting within my project root at Data\Images\articles. I am trying to render the image using the code below in MVC:
<img src="#Url.Content(Model.Image)" alt="Image" />
It's not displaying the image, however the rendered html code is correct.
<img src="/Data/Images/Articles/16fd7bc5-3bac-474a-a806-b8d72b974960.PNG" alt="Image">
I am running the project from Visual studio server, not through IIS. Any idea what I am doing wrong here?
Different file name was generating as compare to what was expecting in logic causing 404 error when validating the image file name
So I have hosted my laravel app in a subfolder lets now refer the root of my project as subfolder. I have a constant base file which has header and footer of the website, I used link of images as
<img src="/img/img1.png">
so it goes to domain.com/img/img1.png instead of domain.com/subfolder/img/img1.png
and if I do
<img src="img/img1.png">
it works fine for the first page but when I navigate to subfolder/user/1 my images brake again because now they are finding images on subfolder/user/1/img/img1.png. I remember once I ran into such situation and someone helped me to set the path of images by adding one line in the header of the website but now I am not able to find it.
Check your root Folder is correct
To avoid this problem, make use of asset() or url() function:
<img src="{{ url(img/img1.png) }}">
Edit: if you plan to attach "subfolder" in url path, then try to edit .htaccess file:
RewriteEngine on
RewriteRule ^/img/(.*)$ http://%{HTTP_HOST}/subfolder/img/$1 [L,R=301]
The code above searches the image /subfolder/img/img1.png when /img/img1.png is found.
We have configured NFS (Network File Share) and created a Virtual Directory Link to NFS in the ASP.NET MVC Website. <br>
Here is the configuration.
\172.0.0.1\Webs\Images is Network File Share (from UNIX)
"https://www.testsite.com/Images" - Virtual Directory Link to NFS
When we try to Insert an Image from tinymce editor, the MCImageManager does not show any images and it says "File/Folder was not found". Are there any other settings/permissions we are missing?
Another question,
Can we use MCImageManager on load balanced configuration? Our ASP.NET MVC site is load balanced and configured to use SQL Session State. Does it create any problem ?
Thanks in advance for your help.
This answer is probably too late for you, but since I just went through a slightly different exercise - I am using a folder outside of the website root, not a NFS.
So if you are storing images in a folder configured like this:
<!-- General file system options -->
...
<add key="filesystem.rootpath" value="C:/temp/Upload" />
...
and you configure the preview section like this:
<!-- Preview options -->
...
<add key="preview.wwwroot" value="C:/temp/Upload" />
<add key="preview.urlprefix" value="{proto}://{host}/ExternalImage/" />
...
And an image like this C:/temp/Upload/anawesomepic.jpg is going to be served at {proto}://{host}/ExternalImage/anawesomepic.jpg
TinyMCE then uses preview URL when inserting the image in edited document.
If you look at ImageManager source code in ImageManagerPlugin.cs you will see that at one point in OnCustomInfo method it calls this line:
info["thumbnail_url"] = man.ConvertPathToURI(thumbFile.AbsolutePath);
ConvertPathToURI is where the plugin removes the prefix defined in preview.wwwroot config item. Then ImageManager prepends that with preview.urlprefix, probably somewhere in javascript.
In my case I have an HttpHandler that handles images in ExternalImage, so the setup is definitely not quite like yours but maybe it helps.
I have one MVC view page in which I show different links and I am using ThickBox to show a different page when ever one of these links is clicked. In these pages, I am using jQuery functions to do some changes, but I am not able to resolve the jquery file path on the view pages. I need to give absolute path something like "http://test.com/js/jquery.js". But is there any way to make it relative?
I also tried getting the host url and using <%=%> and <%# %> but none is working.
Any help?
Thanks
Ashwani
This is when you run the MVC app from visual studio? If so set you're MVC application's virtual path to start at "/" instead of the default that is probably your project name.
This can be done by right-clicking on the MVC project in the solution explorer > Click Properties > Click the Web tab > Type "/" (without the quotes) in the Virtual path textbox. Then use Andrew Florko's suggestion of leading it with a slash <script src="/js/jquery.js"> </script>
alt text http://img707.imageshack.us/img707/3765/virtualpath.jpg
What about trying something like:
<script src="<%=Url.Content("~/js/jquery.js")%>" type="text/javascript"></script>
Maybe you should try
<script src="/js/jquery.js" ...
instead of intellisence-generated path with ".."
<script src="../../js/jquery.js" ...
I am having a wierd error and jQuery not working depending on how the url is written.
if the url is
/index.cfm?show=about-us
all is good. BUT if the url is
/index.cfm/show_about-us
jQuery doesn't seem to load correctly and I get a "$ is not defined" error in fireBug
I can't use the standard ?= query string I need to be able to use the re-write method.
Any ideas are appriciated
Lance
What does your <script src="..."> say? I have a feeling it's looking for /index.cfm/jquery.js which doesn't exist.
Sorry this was a reference issue to the files. Evendently in that re-write sytle the dom is still trying to navigate the file system starting in the /show_about-us/ directory which isn't truely a directory.
That's it. #recursive got it in one.
Consider using the absolute path from the root of your domain in src attributes. For example: <script src="/jquery.js">