I have 2 image files in my App_Data directory and I want to show them in my view like this:
#foreach (var media in Model)
{
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
<a class="thumbnail"><img src="#Url.Content("~/App_Data/uploads/" + #media.URL)" alt="image" /></a>
</div>
}
When I check the link in the browser I get this :
<img src="/App_Data/uploads/Warnings.png" alt="image">
It says he can't find the image. How can I set the correct link?
The App_Data folder is a special .NET "system" folder in which IIS is configured to not allow the contents of that folder to be visible to web users. Create a different folder to store your images as you really should not allow App_Data to be web visible (if you can even change the setting).
From iis.net:
For example, on Web servers that are hosting ASP.NET content, IIS 7
blocks several of the ASP.NET-related paths for you; Web.config, bin,
App_Code, etc. Blocking these URL segments reduce the chance of an
attacker being able to exploit these URLs for information.
Related
In the Index.cshtml file, I'm trying to display the header image in the wwwroot/images folder, so I do
<img src="../../wwwroot/images/header.png" />
but the file won't show when I run the ASP.NET MVC project. I've spent a hours trying to mess around with the file paths and googling but the browser keeps giving me a "failed to load resource" error. What is the filepath?
Screenshot of the project directory
Try this
<img src="~/wwwroot/images/header.png" style="height:200px;width:200px;"/>
Refer these links for more options
How to display an image from a path in asp.net MVC 4 and Razor view?
Image display on MVC view
This will point the path to IIS folder path(C:\Program Files (x86)\IIS Express) if your image is not residing in this path then the image won't get displayed. You might consider using a relative path like below
<img src="#Url.Content("~\\Gallery\\" + item.Source)" />
I am using telerik DatePicker in my MVC3 project like :-
<ul class="floatleft width25">
<li>
<%: Html.LabelFor(model => model.AppointmentDate)%>
<%: Html.Telerik().DatePickerFor(model => model.caseSearchRequest.AppointmentDate).OpenOnFocus(true).ShowButton(true)%>
</li>
</ul>
Please tell mo how i to add a image for opening calendar for this datepicker.
Are you looking to change the icon which comes with each DatePicker? This can easily be done by just modifying the sprite.png file which is tied to each of the provided Telerik skins. Just open up that file (located in the [install directory]/content/[version number]/[skin name]/) in your favorite image editor and change the icon around.
If for some reason this icon is not being displayed at all then I believe there are issues related to the CSS files not being sent to the client. I would use the Developer Tools of the browser to check if any issues appear with sprite.png not getting downloaded properly.
I'm working on ASP.NET MVC application. On my master page, I have a form that I need to submit to another action. Below is the relevant code:
<form id="form1" action="/Stock/PerformSearch" method="post" runat="server">
//some other stuff
</form>
As you can see, when I submit the form I want to go to the "PerformSearch" action in the "Stock" controller. This works fine on my local machine hosting. But when I try to publish the site on the server, MVC doesn't recognize this path anymore. My question is how should I specify the paths to actions in aspx pages such that it will work both locally and on live. I know that I can use the "using Html.BeginForm" and that will solve the problem, but I really don't want to use it for other reasons and also, I always need to specify paths to actions in many other tags other that form tag.
By the way, changing the path to "http://cse454db.cs.washington.edu/BestBet/Stock/PerformSearch"
will make it run on the server since the given path is the exact path for where the application will live (including the virtual directory) but I know this is not the perfect solution since I have to keep changing the path back and forth whenever running it locally or live. Also, I have the same problems in specifying the paths to actions in javascript files. I know there should be an easy solution for it, but I have been looking and couldn't find anything so any help will be greatly appreciated. thanks a lot,
I think you are confusing ASP.NET and ASP.NET MVC. You should use HTML helpers and never ever put a runat="server" tag in an ASP.NET MVC view. So your form could look like this:
<% using (Html.BeginForm("PerformSearch", "Stock")) { %>
//some other stuff
<% } %>
This will take care of generating the proper form tag.
I have an application that uses ASP.NET MVC. I have it deployed to a Crystal Tech server (hence, no direct access to IIS control panel).
Initialy this was running in the root directory and everything was OK. The client then decided that it needed to run in a subdirectory. I moved the app there and the home index page comes up, but every other page tries to access the the controller/action/page/view in the original root directory. I don't understand this, since the references were all contextual (i. e. using ../controller/action as opposed to mysite.com/controller/action).
Am I doing something wrong here? What are my options?
Thanks,
James
I would use the UrlHelper to generate the links. This would ensure that they are relative to the application path.
Link Text
and
<img src="<%= Url.Content( "~/images/myimg.jpg" ) %>" alt="My Image" />
I have dev an MVC app and deployed it to my local IIS as I am using dev server to dev.
This is on Vista Ultimate.
When i browse the site all the images are not showing and also the
login page is displayed.
what would be causing the images not to show and also why
the login page showed when I have not set up security
in web.config?
I tried to see if the ASPNET account had permissions
but there is user of that name and there is no
Add option in properies either.
Malcolm
This could be a deployment issue, rather than a permissions issue. Did you try to browse directly to an image via your browser?
So if you have an image located in your project as
\images\login.png
open in your browser to:
http://hostname/images/login.png
If this works, then you have got a referencing problem in your html. From memory, most images in asp.net mvc are located with:
src="../../images/login.png"
This could break down if your pathing is different to the current location.
I usually prefer this:
src="/images/login.png"
or even better:
src="<%= ResolveUrl("~/images/login.png")%>"
I had a problem with images displaying in an MVC app until I coded the image tags like this:
<img src="<%= Uri.Content("./content/images/image.png") %>" alt="text" />