ASP.NET web site on IIS7 on Vista - asp.net-mvc

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

Related

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.

Running ASP.NET MVC application in a subdirectory, getting 404 errors

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

Deployment of Asp.Net MVC app on Win2k3 issue

I’ve created an ASP.net mvc application on my windows XP machine. Now, I’m at the stage where I want to deploy my application. I’ve done some googling on how to install/configured MVC apps under IIS 5.1 and 6.0 but I’m still having issues although I’ve done everything, so I believe, by the book.
On my XP box, I’ve created a Virtual Directory and added the Application Mapping “.*” and unchecked the “Check that file exists”.
When I navigate to localhost/vince/ my page displays great! Once logged, I’m being redirected to:
localhost/vince/Transaction/Index
The view (Transaction/Index.aspx) simply displays business information…
The user, has the liberty to edit his account by clicking the MyAccount link which brings him to:
localhost/vince/Account/Index
I have a cancel button at the bottom of that view which basically brings you back to:
localhost/vince/Transaction/Index
The view source of that cancel button is this:
<input onclick="location.href='/Transaction/Index'"
type="button" value=" Cancel " />
The problem is when the user clicks the cancel button he is being sent to localhost/Transaction/Index
And I get a 404 page not found…Notice how the name of my virtual directory “vince” was removed.
To further my testing…I’ve decided to deploy my MVC app on Win2k3 with IIS 6.0. Created the exact same thing, Virtual Directory and added the Application Mapping, only to realize that it was doing the same thing. Now instead of creating a Virtual Directory, I created a WebSite. Oddly enough, it now works without having to change anything…does anyone know why it now works within a new WebSite as opposed to a new Virtual Directory.
Thanks
Your cancel button is sending the browser to /Transaction/Index. The important thing to note is the leading slash on that URL. This is sending you to the root of the site (with no virtual directory included). That's why it works on IIS 6 when you create a website - there is no virtual directory being used there.
The fix for this is to use the Routing infrastructure to generate the link for the cancel button - it sounds like you are already doing this for the other links in your application.
It doesn't sound like a server setting, os version, or iis version issue... What is the exact url that your cancel button is requesting?
Change your HTML to:
<input onclick="location.href='<%= Url.Action("Index", "Transaction") %>'"
type="button" value=" Cancel " />

asp.net mvc - site works fine locally but not after deployment

i have an asp.net mvc website. http:/mywebsite.com (just for this example)
I have been testing this asp.net mvc website locally on my machine and everything works fine on my local machine during testing. When i deploy to my web server
when i bring up http://mywebsite.com it goes to HomeController and load the view Views/Home/Index.aspx (which is perfect). So the main default page is fine.
The issue is, if i click any other other links (again that all seem to work fine locally) i get the following error:
The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
Please try the following:
* Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
* If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted.
* Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)
some examples would be:
http:/mywebsite.com\Photos
http:/mywebsite.com\Links
there definitely are controllers and views setup for this (or it wouldn't work locally).
does anyone have any idea how this might work fine locally but somehow on the webserver it doesn't
Are you running the site on II7 in integrated mode? If not, you need to add a wildcard handler so that all URLs get mapped to your application. See Phil Haack's blog post on running ASP.NET MVC ON IIS 6.
Something else to watch out for. I had a static website - deployed on IIS 7.5. Added some MVC Controllers to handle some simple server side apps and then re-deployed it. I didn't copy the web.config file, because I wrongly assumed that everything that was needed was in the one that was automatically created by the server.
You must copy the web.config up as well.

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

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.

Resources