Deploying MVC Application to Web Server doesn't run correctly - asp.net-mvc

I have reading posts all night looking for an answer to my issue and haven't found anything that works for me yet. I am sure there is a simple way to do this but I haven't been able to discover it yet.
Details:
MVC 2 Preview
Asp.net 3.5 sp1 framework
VS 2008 C# web application
Windows Server 2008
IIS 7
I have the application running well through VS 2008 no problem. When I hit the play to run in debug mode it starts the ASP.NET Development Server the application loads fine and works as expected, great!
When I publish the application locally or to my web server both on IIS 7 the application doesn't run correctly. Some of the icons are missing and the google maps map is missing. When I view the source it appears correct at first glance, but I can see the paths to the images are looking for the MVC paths and it isn't finding them. It appears the app is running as a regular asp.net app and not an mvc app, maybe?
I also tried to just hit the full source code locally on localhost and the exact same issue is present.
So, I guess my question is how do I deploy a MVC application to run the same in IIS as it does through the development server.
PS The environments are clean and pretty much out of the box.

#user68137 is correct in saying that you need to use relative paths for the images.
I got caught out on this one too, and here's my previous SO question about it...
In short, you need to do something like this...
<img src='<%= Url.Content( "~/Content/Images/banner.jpg" ) %>' alt="Banner" />
Hope this helps!

I had the relative paths set, but what I didn't realize is when I deployed it to the server it went to wwwroot\subsite... I had the relative paths set to src="....\image.jpg" to get back to the root of the site. My error was that if the site is not in the root then the subsite drills back to the root to find the images and of course doesn't find them. Same thing was happening with the JS files. I used the Url.Content and it worked great! problem solved!
The interesting this is when running through the VS dev server with a subsite it still worked well and found the paths even though it shouldn't have. VS dev server <> IIS
Thanks for your help on this!
Simon.

Once you know the virtual path to the location you are deploying the project to, you should go into the project configuration in Visual Studio and add it to your project. This way the visual studio development server will use the same path structure as the deployment server. This will save you countless hours of work when deploying.

When you run your website through Visual Studio, every single request gets processed through the ASP.NET pipeline, including images, CSS and other resources. IIS by default only processes specific extensions (e.g., aspx) unless you tell it otherwise through configuration. Paths like '/content/images/yourimage.jpg' should work just fine...I suspect it's something amiss in your IIS configuration.
Another possibility which I've run into is any custom ISAPI filters you may have installed on the IIS server (e.g., ISAPI_rewrite). It's easy to set up rules in its configuration that lead to some very unexpected results.

Related

Razor views not generating html after deploying Umbraco 7.2 in IIS 7

I am new to Umbraco, so I started creating a site to play a bit with it. While I had my site running on IIS express (either from VS or WebMatrix) everything worked fine. After deploying the site to IIS 7, the razor views of the front end are display in plain text, meaning that I actually see Razor syntax in the browser. Umbraco back office is working perfect though, except when I hit preview, in that case I get the plain Razor syntax again. I then try to deploy a simple new MVC project to IIS and the Razor engine worked just fine, so I guess is not a problem in IIS but in Umbraco configuration. Is there any configuration tweak I need to take care in Umbraco configuration to solve this problem? Thanks in advance for the help.
I also tried to deploy it in the IIS of my local development machine (the same in which it runs OK in IIS-express) which has the right framework and everything and I got the same cshtml display in the browser.
After struggling a bit more with the problem I found the issue causing this behavior. After installing the starter kit a lot of files are generated in the folder and subfolders of the solution. In order to publish the solution to generate the contents of your website the VS project needs to have all these files included as project files. I found out that some views were excluded of the project and thus not being generated when publishing. I included the missing views and double check that all important files were part of the project and problem solved.

ASP.NET4.0 MVC4 IIS7.5 Error 403.14 I'm Literally Pulling Out My Hair

I want to get away from developing in PHP but doing that is proving to be a massive headache.
I am trying to set up a website with MVC 4, ASP.NET 4.0, on Win7 Professional (64-bit). The website is just the basic site that is set up with Visual Web Developer 2010 Express selecting New Project > C# > Website > ASP.NET MVC 4 Application.
After setting up the application in IIS7.5 I am getting an HTTP Error 403.14 - Forbidden. I've done a ton of research and tried multiple different suggestions on how to solve the problem but NOTHING is working. Here are some things I tried:
Install/Register v4 of ASP.NET. This has been the most annoying
thing because everyone else's issue is fixed when they do this but
mine is not.
Changing the application pool settings:
Set to classic/integrated mode
Change the user/permissions used by the application pool
Made sure 32-bit applications were enabled
Added security permissions to folders related to the website (on multiple accounts)
I can get a regular html document to show up if I add it to the websites root directory. It seems that the MVC stack is not being called at all. The server wants to display the directory, which I can enable/disable, but the website is not being displayed.
Please can I have more potential fixes before I resort to my last desperate act? A baseball bat.
p.s. I'm more than willing to do a skype conversation or a share screen kind of thing if someone wants to dig in deep. I am beyond frustrated with this.
So it seems, in my indefinite well of stupidity, I was pointing the webserver to the incorrect folder. I needed to point the webserver to the folder with actual files of the application rather than the folder containing the .SLN file. Sorry to waste your time!
try running the aspnet_regiis
http://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx
open the command line in %windir%\Microsoft.NET\Framework64\v4.0.30319 and run
aspnet_regiis -ir
other possible solutions:
quit skype, or any other similar applications

MVC - Routing not working within intranet

I don't know anyone can help but I'd appreciate any. I am developing an app in mvc (c#), now I had various routes working on my local development machine when the app was stand alone however now I've tried adding the project to the test intranet at work and none of the routes are working.
So where Localhost/Admin/Create worked fine locally where admin is the controller and Create is the action, when I try to get to testintranet.mywork.com/intranetsection/myproject/admin/create I'm getting a file not found error. I'm not sure what I need to change to get it to pick up the routing again rather than look for the literal path. The default.aspx page works fine and gets called but apart from that nothing. Is routing only viable when in a standalone project?
Cheers for any help.
It looks like you're either running on IIS 6 or IIS 7 classic mode. If you can, I'd recommend updgrading to IIS 7 integrated mode. If not, I have a walkthrough for getting up and running on IIS 6.
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
You don't say what version of IIS you have deployed to, but you may be running into the issues described here:
http://blog.codeville.net/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
I believe that most people chose to resolve this using a wildcard mapping for the aspnet_isapi.dll.

Can MVC run on 3.5 IIS6? NON SP1

I was lead to believe that MVC apps were BIN-deployable, so could be deployed to any ASP.net 3.5 compatible server. I'm trying to deploy to a Windows Server 2003 x64 with 3.5 (no SP1) and am having trouble getting it working.
I get the following when hitting the homepage, which redirects to the /Account/LogOn view due to our app config.
The page cannot be found
I've got the three (plus Extensions, I can't remember why) MVC dll's set to Copy Local, so they end up in the bin-folder. I'm publishing and then copying over the app to the server:
System.Web.Abstractions.dll
System.Web.Mvc.dll
System.Web.Routing.dll
System.Web.Extensions.dll
Does anyone know what I'm doing wrong? The app works on another machine we have with 3.5 SP1, and on development machines, also SP1 and with MVC installed.
I've gone over everything I can think of, ensured the permissions are correct, etc.
IIS 6 does not handle .mvc extensions correctly. Among other things you have to map .mvc to the ASP.NET handler. Here is a walkthrough for you: http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
Have you set up wildcard mapping on the server that does not work? See "Deploying ASP.NET MVC to IIS 6" for an example. You basically need to map all requests to the ASP.NET ISAPI DLL and tell IIS not to try to verify that the file exists. Don't know if that's your issue, but it has bitten me a few times in deployments.
With IIS6, you can't do extensionless URLs like /Account/LogOn. You have to do something like /Account.aspx/LogOn The ".aspx" can really be almost any arbitrary extension, but you need that extension. Your routes need to take the extension into account as well.
Check to make sure the app pool your site is running under is configured to run ASP .Net 2.0, sometimes it defaults to 1.1 which causes issues similar to yours.

Disable Visual Studio Web Server Directory Browsing

I'm using Visual Studio's built in web server to test and EPiServer applicaiton. When I have the app running in IIS, if I hit the root of the virtual directory, EPiServer will take over and server the defaul page to me. Using the Visual Studion server (which I am doing for license reasons with the SDK), it always gives me the 'Directory Listing' view of my site. Does anyone know how to configure this web server to not allow the directory listing/browsing?
Additional Information:
This problme only seems to effect the root of the visual studion web server (i'll call it cassini from here on in). As an example, if I run a site from localhost:6666, then what I will find is that localhost:6666/en/ will work just fine and the EPiServer VPP will know what it is doing. If I use localhost:6666/, then the VPP never kicks in (or so it seams). It seems to me that when the root of cassini is hit, it checks to see if the page exists (which it does not as I have no default). If it decides that the page does not exist, then it serves up the directory listing, rather than 404. The first thing to do for me is to dispable directory browsing in cassini, then look at why the VPP is not being actioned correctly.
So I suppose the base of the question is: Is there a way to modify these settins in Cassini when it is Visual Studio starting everything off?
(EPiServer may be a red herring, but just in case, it's CMS version 5)
Further Update
I managed to get hold of the source for Cassini 3.5 and gave that a whirl. 3.5 works just fine and behaves like IIS in this instance. I.e. the lack of default document does not lead to a Directory listing, rather if allows the HTTP handlers to kick in and then EPiServer does the rest! So the question is, can I achieve the same in Visual Studios effort at a web server?
Make sure you have a ~/Default.aspx file. It won't render, but it's needed in cassini for the virtual path providers to get a chance to handle the request for '/'.
Of course, if you make it anyway you might as well use it for the start page :-)
Even if you could get the server to not show the directory listing, could you get EPiServer to take over?
EDIT: From comments
The fact that it works with /en/ makes me think this is something that Microsoft could fix. I suggest you ask the vendor if they have a workaround. If they do not, then please create a suggestion at http://connect.microsoft.com/visualstudio/. Be sure to specify details about EPIServer, URL to the vendor, etc.
Be clear that it works with /en, but you want a setting permitting it to work at the root.
Once you create the suggestion, please edit your question to include the link to the suggestion you create. That way, others reading your question can vote on how important they think this is.
The EpiServer part confuses me. However, if you are asking how to set the default page for the VS development server (based on the Cassini code), you're expected to do that in the project properties (right click on web project), Web, Start Action, Specific Page, foo.aspx.
I suspect the cassini/VS development server doesn't have a default page feature-- the source code for the cassini server (the ancestor of the VS development server) is on the web and you can check that and add a default page by building a custom version. And it doesn't have a very long list of other features that IIS has.
Which EPiServer version are you running?
Did you install it using EPiServer Manager?
There has always been some differences in the configuration between running the site at the root of a host name or as a (virtual) directory.
Check the site settings block in web.config and make sure you have a default.aspx at the project root.

Resources