ASP .Net MVC - Images not being shown in published build - asp.net-mvc

I am developing an ASP .Net MVC application and on my dev machine, the application runs as expected and, more importantly, the images mentioned in the CSS file are displaying correctly too.
However, when I publish this application to a testing server, the web app runs fine, but the images are not shown.
If I modify the URL in IE when testing the output from the test server, the image is returned, meaning that the file is there but it just won't appear within the view page when using the site normally.
I have tried alternative servers too, but the result is the same.
To confirm, here's a line from the CSS page referencing the image...
background-image: url('/Content/Images/Logo/myLogo.jpg');
Any suggestions?
Cheers
Brett

The URLs are not correct, likely due to the fact that you are publishing in a subfolder and so they are no longer at the root of the server. I usually use Url.Content( "~/Content/Images/..." ) to build the url instead of hard-coding it. That way it will take into account the routes when building the path.
Example:
<img src='<%= Url.Content( "~/Content/Images/banner.jpg" ) %>' alt="Banner" />

I had the same issue, but I found the reason why it was forcing authentication on the Contents folder.
When a user is not logged in yet, they are classified as Anonymous Authentication. In IIS7 (which is what I am using, guessing it is the same in IIS6) you need to open the authentication window in features view. Then edit the Anonymous Authentication, to use your application pool identity, or the default one, just make sure that user has permissions to read in that folder.
That fixed it for me, hope it works for you.

Possible relative paths are wrong...Possible that they are wrong for CSS file itself. You can use FireBug to see if CSS loaded correctly, then you can examine image request, often in such situations you will see red(error) items. This could help to localize problem.

Related

Azure Changes not getting published

I have made changes to my css on my MVC5 project that are working as intended on my local version but when I deploy to Azure the changes are not working.
I have tried creating a min.css file but this did not work
Have you done a hard refresh and pulled a copy of the stylesheet from the server to see if the changes you made are actually there? Http caching could be the culprit depending on how you're packaging your CSS.
Next, check the page source to make sure that your page is actually requesting the stylesheet you think it is. For example, if your site is requesting styles.min.css but you only made changes to styles.css and didn't create a new minified version, that'll cause problems.
Third, I'd check the elements that do not have the styles you're expecting and trace the styles with something like Chrome Developer Tools to ensure that your styles aren't being overridden in a way you're not expecting.

URL Routes In IIS7 MVC 5 (Single Paged Application)

After publishing a MVC5 web application of mine to my IIS server (Individual User Accounts), it would seem that the URL is accessed incorrectly.
During debug, it would be e.g http://localhost:1234/api/Account/UserInfo?=XXXXX
The debug works just fine. The only issue kicks in after I've published it via my IIS7 server.
After publishing and using Google Chrome's console, it would appear that the page is requesting for a resource at mydomainname.com/api/Account/UserInfo?=XXXX instead of mydomainname.com/WEBAPPLICATIONNAME/api/Account/UserInfo?=XXXX.
My best guess is to modify the URLs in /Scripts/app/app.datamodel.js but it would just cause more parsing problems.
I've searched around and can't seem to find any related problems. I hope someone here will be able to lend a hand.
Look like you are using relative path like "/api/Account/UserInfo". Instead i'll recommend you to use #Url.Content("/api/Account/UserInfo"). This will solve your problem
Explanation
In local system when we run application in WebDev server it never have sub folder (like WEBAPPLICATIONNAME) therefore you relative path work correctly. but when you host your application in IIS under Default website in another new website /Virtual folder (like 'WEBAPPLICATIONNAME') then "/api/Account/UserInfo" fall back to Default Website because for '/' in starting. #Url.Content or #Url.Action make sure to add virtual directory name, hence changing your path to "/WEBAPPLICATIONNAME/api/Account/UserInfo" in IIS.

Why is contents of _Layout.cshtml missing when running locally on IIS7.5?

I am testing an mvc4 site locally and have set up my hosts file / IIS so that I can run it from a test domain name. I am following instructions from here: http://ben.onfabrik.com/posts/oauth-providers
When I access it via the bound domain set up in IIS it does 'work'... but the entire contents of _Layout.cshtml are missing. All that displays is the html from the View being called.
When I run the site using the Debugger, or on live hosting it comes up as expected. So I don't think there's any problem with paths, or using ViewStart.
It's only when accessing it via the domain (bound to localhost on IIS) that the _Layout.cshtml content is missing.
Any ideas as to why this might happen and how I can resolve it? Thanks
This doesn't answer the question, but until somebody can offer a better response, it might help others in a similar position.
I had to run the site from VWD using the Debug button - that runs the app on the standard .Net Development Server, which gives you a port number.
Adding that port number to the end of my domain name made my _Layout.cshtml display.
e.g. http://testdomain.com:54829/

download source code, but not working

I had a problem with part 3 of an orchard tutorial...
so I was attempting to download the source code for part 4 and continue on from there (which can be found about 3/4 of the way down at the end of the tutorial on the page http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-4
However when I run part 4 from webmatrix I get the error(see below)
im guessing this is because iv only downloaded the code but i need to put it inside a seperate project? is this correct? can someone advise me how to do this?
thanks for any replies
The error states that there is no default document configured in IIS. Attempt to access the document using the full URL.
For instance http://localhost:28266/default.aspx (or similar)
You can then adjust IIS to have the correct default document (if desired)
Edit: After reviewing the referenced ZIP archive.
This looks like a changed file zip for the application. This isn't a complete ASP.NET MVC application by itself and, as such, isn't viewable stand alone. I don't have the time to parse the exact steps required to make this application work alongside the demos provided, but be sure you're either combining all of the previous files and folders in order or follow the instructions detailed by the author.
As referenced, this is not a complete ASP.NET MVC application and isn't ready to be immediately rendered by IIS.
The problem is probably that the application can't start for some reason, which causes IIS to attempt to respond to the request with other handlers. Because there is no default document defined (and there shouldn't), it tries to do a directory listing, which is not allowed in your configuration. Do not focus on what IIS is telling you but rather on why your application doesn't run.
Things to check:
you have built the application
you are running in full trust
you are running in integrated mode
there is no exception in app_data/logs
you added the module to a working Orchard instance, in its Modules directory

ASP.NET web site on IIS7 on Vista

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" />

Resources