I am trying to open an MVC3 solution in a newly installed Visual Studio Express 2012 RC. So far, I've had issues that for some reason VS2012 doesn't know that the projects are MVC projects, so it won't add Views/Controllers. Got past this by adding the following GUID to the ProjectTypeGuids node of the .csproj file of each project in the solution:
{E53F8FEA-EAE0-44A6-8774-FFD645390401}
However, when I open razor views, it shows these errors (among other related ones):
Error 20 The name 'model' does not exist in the current context c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml 2 2 EventManagement
Error 21 The name 'T' does not exist in the current context c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml 5 14 EventManagement
Error 22 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor' and no extension method 'LabelFor' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?) c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml 6 11 EventManagement
Intellisense is working in the razor view, but it only gives limited amount of fields for the Html helper method. For instance, none of the model specific methods like LabelFor and TextboxFor.
I have MVC 3 and 4 installed. The solution worked fine in VS2010.
UPDATE:
When adding a new MVC3 project in VS2012, it works fine. So that means it is definately something to do with the project, and not the installation.
UPDATE 2:
I think that the issue is that the view doesn't have access to the referenced libraries in the root config:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="System.Linq"/>
<add namespace="System.Collections.Generic"/>
<add namespace="Orchard.Mvc.Html"/>
</namespaces>
</pages>
</system.web.webPages.razor>
It does at runtime, but the intellilsense and error console doesn't pick it up
Any help is appreciated.
Thanks
For me this problem was resolved by adding:
<add key="webpages:Version" value="1.0.0.0"/>
in my appSettings section of my root web.config
e.g.
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
Check this Link:
http://msdn.microsoft.com/en-us/library/hh266747(v=vs.110).aspx
Make sure you know that project is MVC3.
Make sure that project was created with VS2010 with SP1.
I fixed this by uninstalling MVC4 RC. Doesn't seem compatible with my system (or the 3 other systems I tested with). Will just have to wait for the release version of MVC4
From MVC 4 release notes:
Required updates
In the root Web.config file, add a new entry with the key webPages:Version and the value 1.0.0.0.
In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
Locate the following assembly references:
< Reference Include="System.Web.WebPages"/>
< Reference Include="System.Web.Helpers" />
Replace them with the following:
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
4.List item
Save the changes, close the project (.csproj) file you were editing, and then right-click the project and select Reload.
You may install both MVC3 and MVC4 on the same computer, please configure in web.config like below
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Related
I am having a hard time describing the exact issue, but is appears to be "just" an IntelliSense problem that only shows in razor (.cshtml) views. Been looking at this for 2 days now so I could really use some help.
I am using VS2015 Pro, started a new Web MVC application (WebApplication2 ) using the standard template. Inside that application everything works just fine.
Now I have added a class library project (the default one, not the "Package" template), and added the WebPages, MVC and razor nuget packages to it (in case that is relevant). The problem becomes visible as soon as I create a new view in the class library. It appears that all references to System libraries are unavailable in the cshtml file.
With no files opened I get no errors at all, but when I open the view all system classes have the red squiggly line under them, and the Error list (Build + IntelliSense) suddenly contains a lot of errors for every system* library, example:
The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
These include Linq, and the WebApplication2 (the test project), so not just System.Web.
Things that I have checked and done bases on similar answers on stack:
The web.config in the Views folder contains the correct versions, also tried just copying the one from the web application.
Reinstalled the nuget packages (Mvc, Razor, Webpages).
Resetting the userdata and removing the .vs folder.
Copy local is set to true on assemblies.
The actual case where we discovered this is our larger web application which was working fine in VS2010, but then we decided to upgrade to 2015 and .Net 4.6. The views in the class library are marked as embedded resource and loaded using a virtual path provider. The case above is a super simplified reproducible project, the symptoms are the same on my and my 2 colleagues' computers.
If I missed a crucial bit of information, please just ask.
Image visualizing the issue
A reply in the article Stephen Muecke commented with got me started in the right direction. The solution is a mix of probably my confusion of which config needs to be where, and what feels like a workaround to something...
Set the [Output Path] of your class library project to [bin/]. Mohammad Chehab mentions this in his (currently offline?) blog post which was referenced in this article: http://thetoeb.de/2014/01/05/enabling-mvc5-intellisense-in-a-classlibrary-project/
In your [ClassLibrary/Views] folder you should have a Web.config which includes the correct razor versions and namespaces. I just copied the contents of the Web.config from our working Web application project and added/changed some namespaces. Example below.
In your [ClassLibrary] root folder you should change the App.config so that it also contains the system.web section with the compilation setting. Example below.
After changing these to a clean, close the solution, delete the bin folders, open the solution and for me it finally all worked again.
I do have a sporadic issue with System.Web.Mvc.xml being locked, perhaps a side effect of the output path change that MS did not foresee or something... Perhaps nothing to worry about.
Hope this helps some poor googling soul some day.
Project/Views/Web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
</configuration>
Project/App.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Please somebody help me fix this issue.
Umbraco application as parent on IIS6 has the following version of System.Web.WebPages.Razor.
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
<system.web.webPages.razor>
<host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor" />
<pages pageBaseType="System.Web.WebPages.WebPage">
<namespaces>
<add namespace="Microsoft.Web.Helpers" />
<add namespace="umbraco" />
<add namespace="Examine" />
</namespaces>
</pages>
Blog Engine application as virtual directory under the Umbraco application on IIS6 has the following version of System.Web.WebPages.Razor.
<configSections>
<remove name="system.web.webPages.razor" />
</configSections>
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Even after i added the dependentAssembly still nothing works for me, Am wasting more than a week on this issue, Please help.
Have you checked the actual version of System.Web.WebPages.Razor that is currently deployed to your bin folder? I had a similar issue recently in a multi-project solution and one of the projects was using an older version of the assembly via Nuget which happened to be the one that ended up in the bin folder causing a similar error. In fact I'm pretty sure that it's the Umbraco Nuget package copying in the older assembly.
Finally, I have fixed this issue. Blog Engine's(Child application) Razor Script version is 2.0.0.0 and Umbraco(Parent application) 4.1.6 application's Razor script version is 1.0.0.0, i have added the below in child's web.config
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
Once the above added, i get rid of this error and i faced the same dependency errors for the below and i added the respective dependent assembly and the version.
Microsoft.Web.Helpers.dll
Examine.dll
Umbraco.dll
WebGrease.dll
For the above three dependency will not present in child application's bin folder, you need to copy the dll files from parent bin folder and add it in child bin folder, which will sort all the dependency issues.
For any deploying issues on BlogEngine as virtual directory and Umbraco as parent application, leave your message will help you solve the issue of any different versions.
#ProNotion is right, I have seen more and more packages on Umbraco relying on specific versions of assemblies causing assemblies to conflict especially if two packages need different versions of the same assembly.
So some other tips:
This tool from MS helps diagnose assembly binding problems (http://msdn.microsoft.com/en-us/library/e74a18c4%28v=vs.71%29.aspx).
Adding a runtime / assemblyBinding section to your web.config can work round problems with clashing assemblies (http://msdn.microsoft.com/en-us/library/0ash1ksb(v=vs.110).aspx)
Sometime the assembly doesn't get copied (eg you use msbuild and the assembly isn't included in the project) - so you should also check to see if the assembly made it to the live server.
Please try the following steps.
Check the Version of System.Web.Webpages in your References. Say Your Version is=X.X.X.X
2.In Webconfig
a.Add the assembly first
<assemblies>
<add assembly="System.Web.WebPages, Version=X.X.X.X, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
b.Bind the assembly for runtime
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-X.X.X.X" newVersion="X.X.X.X"/>
</dependentAssembly>
</assemblyBinding>
3.Make sure you have added correct key
<appSettings>
<add key="webpages:Version" value="X.X.X.X"/>
</appSettings>
This worked for me. Hope It'll help you too.
Sometime, you will have mistake between
System.Web.WebPages.Razor
and
System.Web.Razor
Try look and check
Create a new Area, right click project, Add, Area
Copy the web.config from the views folder in this area to /views/web.config
remove the area
I was able to create a custom build of ASP.NET MVC and use it in a web application, however, I can't seem to figure out how to get the Razor intellisense to work correctly.
If you follow the steps below, the Razor intellisense will only show WebPages info and nothing else (HTML helpers etc.).
I'm using VS 2012.
Here's what I've done so far:
I cloned the latest ASP.NET Web Stack
Opened the Runtime.sln and built the solution
Created a new ASP.NET MVC 4 (.NET 4.0) web application
Deleted existing references for System.Web.Mvc, System.Web.Razor, System.Web.WebPages, System.Web.WebPages.Razor, System.Web.WebPages.Deployment and added references to the built assemblies in step #2.
In ~/Views/Web.config, replaced System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 with just System.Web.WebPages.Razor
Also, replaced System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 with just System.Web.Mvc
Removed the following from the web.config
<runtime>
<assemblyBinding xmlns="urn:schemasmicrosoftcom:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
If you're looking for intellisense support in VS 2012 for views, as well as the right-click context menus for the controllers folder and views folder (shortcuts to add controller and add view) then you need to open up the .csproj file of your web project and manually edit it to include the MVC project type GUID. This is what VS actually uses to decide what flavor of intellisense you get (among other things).
Specifically, the xml tag of the .csproj file you're looking for is:
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
You should be missing the GUID value
{E3E379DF-F4C6-4180-9B81-6769533ABE47}
Good luck!
I am trying to 'build' my MVC3 web app in VS2010 however keep getting the following error:
Error 2 The type 'System.Web.Mvc.ModelClientValidationRule' exists in both 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll' and 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll' C:\Users\brownp\Documents\Visual Studio 2010\Projects\Cab\Cab\Models\AccountModels.cs 223 28 Cab
Also, every time I open the solution, it prompts me with the following:
I install via Web Platform Installer and it installs successfully however the message reappears every time I open the solution.
Can anyone offer any guidance?
Thanks Paul
After installing MVC4 beta today, a few of my MVC 3 projects would not compile. (ModelClientValidationRule conflict) The fix was:
Edit:
ProjectName.csproj
Change
<Reference Include="System.Web.WebPages"/>
To
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
Ok try this solution...
In the root Web.config file, add a new entry with the key webPages:Version and the value 1.0.0.0.
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
2.In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
3.Locate the following assembly references:
<Reference Include="System.Web.WebPages"/>
<Reference Include="System.Web.Helpers" />
Replace them with the following:
<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
4.Save the changes, close the project (.csproj) file you were editing, and then right-click the project and select Reload.
REFERENCE: http://forums.asp.net/t/1723108.aspx/1
also try: http://www.asp.net/learn/whitepapers/mvc4-release-notes#_Toc303253815
Delete System.Web.WebPages from solution references. It is all.
The best way to avoid this conflict is-
Go to solution explorer
Reference
Right click on System.Web.WebPages
Remove
Now run your application and Enjoy !
This issue, which is the same as you described in VS2010, occurred in my case in VS2015 with a newer version of MVC (V5).
Here's how I was able to fix it:
Update the NUGET packages to the latest version.
In your project, remove the references for Microsoft.AspNet.WebPages. Then, re-add reference by using the latest package (use "Browse..."):
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40
Ensure that all projects are referencing the same assembly, if not, fix them as described above. Then, re-build the solution. In my case, it fixed the error.
Check the Web.config file, and fix settings such as:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="true" />
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
I am having a problem getting a MVC 3 project running in IIS7 on a computer running Windows 7 Home-64 bit. Here is what I did.
Installed IIS 7.
Accessed the server and got the IIS welcome page.
Created a directory named d:\MySite and copied the MVC application to it. (The MVC app is just the standard app that is created when you create a new MVC3 project in visual studio. It just displays a home page and an account logon page. It runs fine inside the Visual Studio development server and I also copied it out to my hosting site and it works fine there)
Started IIS management console.
Stopped the default site.
Added a new site named "MySite" with a physical directory of "d:\Mysite"
Changed the application pool named MySite to use .Net Framework 4.0, Integrated pipeline
When I access the site in the browser I get a list of the files in the d:\MySite directory. It is as if IIS is not recognizing the contents of d:\MySite as an MVC application.
What do I need to do to resolve this?
As requested, here is the web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I posted this question on "ServerFault" as well and got a resolution to the issue here.
The answer is:
Since IIS was installed after .NET 4, you likely need to run the aspnet_regiis.exe tool to register all the .NET 4 stuff with IIS.
I like to add some details:
After registering ASP.NET 4 using aspnet_regiis -i I also had to update the web application using aspnet_regiis -s W3SVC/1/ROOT/SampleApp1 in order to fix the problem.
The /1/ in W3SVC/1/ROOT/SampleApp1 is the instance of your web application. You can find it by looking into your IIS Manager in the column ID.
The ROOT/SampleApp1 in W3SVC/1/ROOT/SampleApp1 is your application path. If you want to update all sites, just do aspnet_regiis -s W3SVC/.
Afterwards it worked fine for me.
I had 403.14 errors when running an MVC 3 website on the server. Server was 32 bit. 2008. IIS7. The problem was that the HTTP Redirection feature was not installed. Server Manager -> Roles -> Web Server -> Roles Services -> HTTP Redirection. This is the only thing that fixed it for me. The web.config needed no change.
I think the majority of IIS7 website setup problems is due to folder security. If you try to create a website by copying the application folders directly from your dev environment to a folder not under wwwroot, the security on your folders will be wrong and you will fight it for hours getting ambiguous errors. The EASY way to get it correct, is to inspect and inetpub/wwwroot folder, examine it and add permissions to your folder, starting with computername\IIS_IUSRS and computername\Users. For mvc, make sure you have a web.config AND global.asax at the root. You do not need a default document for mvc and you should not allow directory browsing. If using aspnet_regiis, you may want to use the -ir if there are other sites being hosted on the machine.
Have you checked the websites default document in IIS is at the top of the list.
I think it defaults to default.asp with default.aspx either not there or at the bottom of the list
I didn't solve this problem until I install .net v4.0.30319 ,before that .net version on my machine is v4.0.30128 . It takes me a long time to figure out the problem,hope this can help someone.