ASP.NET MVC Application in Sharepoint 2007 virtual directory - asp.net-mvc

I have MOSS 2007 installed at lets say http://localhost:4999/ and I want to have my custom ASP.NET MVC (1.0) application at http://localhost:4999/mvcapp/ - logic dictates that, in IIS, i should create a new application virtual directory under my MOSS site and point it at my custom MVC app.
I've done this and it works for executing my controllers etc, however, none of my /Content content is being returned! All referenced images, javascript and css aren't retrieved.
If I put this app into it's own site, or a virtual application within a non-sharepoint site, this works fine and pulls down the images, js and css as normal.
Note - I'm creating a new application in IIS, not just a virtual directory and I have no requirement for integrating with sharepoint, I just want it to have the same domain and port number.
Any ideas?
Cheers
Tony
** EDIT **
To clarify - the URL's that are being generated aren't the issue - they are correct and are being generated in the same way as they would be if this wasn't hosted under sharepoint. IE: /mvcapp/Content/Scripts/jquery.js etc.
** EDIT 2 **
More clarification - the MVC app has it's own web.config file - but it appears that when using a virtual directory withn a sharepoint site, many of the handler mappings still get pushed up to the child site (Note: This is a virtual directory configured as a seperate application not just a virtual directory).
Whilst I don't want or need SharePoint integration, I need my MVC app to come from the same domain and port to overcome some cross domain issues (a lot of MVC content is iframed into sharepoint in various ways). So sharepoint would be at http://site and my app at http://site/mvc

I would keep them on separate web sites (MVC and SharePoint that is). You could create a new website entirely for your MVC app, and then through IIS, right click your MVC web site, edit bindings, and redirect the traffic from your MVC website to URL you want.

I set up a couple of WebForms apps to run in much the same way you say that you want: a separate virtual application with its own web.config, etc. I had to tweak the web.config to make it work, though. My app uses things like session state and view state, but I reckon those aren't applicable to your MVC app. As I look at my web.confing, I think this section might be applicable for what you're trying to do:
<location>
<system.web>
<xhtmlConformance mode="Legacy" />
<trust level="Full" />
<httpModules>
<remove name="PublishingHttpModule" />
</httpModules>
</system.web>
</location>
Hope that helps. I also have an <authorization> section in there, but it wasn't necessary to make the app work.

Look at the following:
Configuring Specific Files and Subdirectories (MSDN)
Disabling Configuration Inheritance For ASP.NET Child Applications (Blog)
HTH

Related

Routing not working for MVC application under a Webforms website?

I'm creating a Reporting application in MVC that I want to use in multiple websites. I want to be able to simply create an application in IIS under each of the consuming websites and point them to the same directory where the Reporting application is located.
When I tried doing this in an MVC website it worked fine. However, when I tried adding this application under a Webforms website I got a "403.14 - Forbidden" error because it's trying to use the Static File handler.
How can I correct it to use the right handler to route to the Home controller?
The problem was that the base website's app pool was using the 2.0 clr. Once I realized this I made the necessary web.config adjustments and recompiled the app to run under the 4.0 clr and then everything worked.
I also have a bunch of <location path="." inheritInChildApplications="false"> sections. Not sure if those are necessary now, but I'm leaving them since it works and the sub app doesn't need to inherit anything from the base website.
This post (Expression of type 'System.Web.Mvc.MvcWebRazorHostFactory' cannot be used for return type 'System.Web.WebPages.Razor.WebRazorHostFactory') also helped me in trying to get the web.config stuff sorted out while converting from 2.0 to 4.0. That was kind of a pain because there were several errors I had to work through, but I think I mostly just had to remove some sections of the web.config that are no longer necessary (because they're now included in the machine config).

MVC website running on localhost

I've built a little time recording website with MVC4, which I'd like to use to record my time.
Previously, coming from a WebForms background, I'd build an app like this and set it up in IIS as an Application off Default Web Site pointing to the folder, so the URL would be http://localhost/Timesheet
I tried that with the MVC project, but I get a 500 Internal Server error. I assume this is because it's a project vs. a website. If the project is "running" in Visual Studio, then it works, but I don't want to have to open Visual Studio every time I want to record some task I worked on.
I tried adding it as a separate site under the "Sites" folder in IIS, but then I'm not sure what the Host name should be - it won't allow localhost/Timesheet for example.
Is this even possible?
Turns out I just needed to wrap the root web.config's system.web section in:
<location path="." inheritInChildApplications="false">
<system.web>
...
</system.web>
</location>

Hosting an MVC and a webforms site on the same IIS7 instance - web.config inheritance

We have a website that was written in classic ASP, then I started to extend it using web forms. These extensions exist in a subfolder of the main folder. Now we've decided we'd prefer to use MVC3. Also, as we'd like to convert all our site to MVC3 over time, we are hosting the MVC code in the application root. I've found some other questions where people have a similar issue to mine, but no solution. The issue is simply that my web forms app can't seem to be stopped from inheriting the web.config settings from the root folder, and as a result, it won't run, it either complains about missing dlls, or complains about running the wrong version of .NET, or complains I need to remove some settings ( which I try and can never get to work right ). The app in the subfolder is also hosting a webservice that is called by our application, and it also runs HTTP handlers to protect our imaging content, so it's got a bit of stuff in it. Do I need to run my MVC site in a subfolder ? Is there any way to have MVC in the folder above a web forms app ? I'd prefer to set things up so they share session data, but that's looking likely to be impossible at this stage...
So to be clear the folder structure is:
<root>
contains asp site and MVC site.
<subfolder>
contains webforms application
</subfolder>
</root>
and my issue is getting the subfolder to run, preferably in the same session as the MVC app.
There is no reason you can't run regular .aspx files on an MVC site. You are correct though, web.config settings are inherited from the parent (chain), but you just add a new web.config in your directory with relevant settings.
What you will have to do is play with the routes, because by default MVC will route all requests into your controller classes. But if you google around its fairly simple to add an exception to the routing.
If you post some of the specific errors we can probably help further.
Oh and do you mean Classic ASP? i.e. not Classic ASP.NET? Because you'll have fun sharing session data between ASP & ASP.NET.

asp.net MVC 3 no default page

Has anyone tried to deploy an asp.net mvc 3 website that uses the razor templates? The project does not create a default page and not sure if this changes in some way?
I have several projects in the pipeline that work on both IIS 7 and 6 (test servers) without any issues with a missing default.aspx page. I don't have any production code in effect but so far it's not an issue.
I would say the issue with a missing default.aspx page would rely on the server not using the <modules runAllManagedModulesForAllRequests="true" /> in the web.config. Otherwise a default.aspx page isn't necessary for handling. As long as IIS uses the mvc module to handle requests.

How to authenticate users entering Dynamic Data admin area in ASP.NET MVC site?

I have an ASP.NET MVC 1.0 front-end site that is working well, and features as part of it, a Dynamic Data section that I'm using as the back-end admin area for the site.
I haven't messed about too much with authentication yet, but this seems like quite a logical web-site design for any new .NET sites being put together these days. I'm hoping someone might have some advice to share on how to lockdown the Dynamic Data section of a site (Dynamic Data uses plain old ASPX pages) using Froms Authentication, while leaving the MVC front end components freely browsable.
FYI - the site is hosted on Win2k3/IIS6.0, and the server does not have MVC installed, so I'm including the DLLs in the \bin directory and using the routing engine to append the .aspx suffx onto the controllers, so as IIS can understand the MVC parts of the site.
Thanks...
Bernard.
You should be able to lock those pages down in the same way you'd lock down pages in a standard asp.net site - add the folder name in a location block in a web.config:
<!--
The location element is only needed if this is in root web.config.
You could also create a web.config in the folder containing the dynamic data
pages and just have the elements from system.web
-->
<location path="DynamicDataFolder">
<system.web>
<authorization>
<allow roles="Admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
This assumes that you've set up the Membership and Roles providers - there are examples of these in the default MVC project and created a login page.

Resources