WebResource.axd and ScriptResource.axd weird behaviour - ajax.net

I am building a website, to be used primarily in my internal network. I am facing a very frustrating problem with AJAX .NET. To explain the problem, first let me detail out my environment.
I am developing in Visual Studio .NET 2010, targeting .NET framework 4.0.
My staging server is a win7 utlimate machine having the complete configuration of IIS 7 installed.
I am using MySql Server 5.1 as my database server
The staging server has the required MySQL connectors installed
I am using the Membership class to authenticate and authorize my users. With mysql, I am following this article to accomplish this : http://www.codeproject.com/KB/database/mysqlmembershipprovider.aspx
The staging server is using AVG antivirus along with windows firewall.
I am using the toolKitScriptManager on all my pages.
The application works perfectly fine in visual studio. Also, when deployed on the staging server, it works fine on any browser on the staging server as well. The website also works fine on other machines inside my network, when I access it by tying the ip adderess:port of the server. Now the problem is that after some time of usage the website just hangs. As in it says page loading for a long time before eventually timing out. This issue goes away if I clear the cache and restart the browser but reappears after some time. This issue is witnessed only on the networked machines. We have never encountered it on the web browsers of the staging server.
I have succeeded in a controlled reproroduction of the issue. Whenever the page loads and I hit refresh on the page, the problem appears. If I go back and try to access the same page by clicking the page link, it works. But if I hit refresh, the page just keeps on saying loading and eventually times out.
I have examined the network by using the google chrome developer toolbar and firebug and I found that whenever the problem occurs, some webresource.axd and scriptresource.axd files show up as "pending".
After spending more then 15 days, researching google to combat this issue, I have unsuccessfully tried the following remedies :
Thinking it might have something to do with concurrent connection limit of IIS7 on win 7, I tested it with minimal load, that is just one user accessing the site. I also monitored the IIS worker processes to see if the requests are queeued up there, but I see no pending requests, The problem is still there.
Thinking it might have something to do with firewall blockage, I disabled the firewall on my staging server. The problem is still there.
Thinking it has something to do with my web.config settings, I checked my web.config a thousand times for mistakes, but all sections are intact. Please see the web.config file at the end of this listings for any signs of problem
Your kind suggestions please.
My web.config follows :
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<connectionStrings>
<add name="ConnString" connectionString="Database=scsbackend;Data Source=localhost;User Id=xxxxx;Password=xxxx"/>
</connectionStrings>
<system.web>
<sessionState mode="InProc" timeout="90000"></sessionState>
<authorization>
<allow roles="Admin"/>
<allow roles="Tellecaller"/>
<deny users="?"/>
</authorization>
<authentication mode="Forms"/>
<roleManager defaultProvider="MySqlRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="90000" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
<providers>
<clear/>
<add name="MySqlRoleProvider" type="Andri.Web.MySqlRoleProvider" connectionStringName="ConnString" applicationName="mysqlmembership" writeExceptionsToEventLog="true"/>
</providers>
</roleManager>
<membership defaultProvider="MySqlMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear/>
<add name="MySqlMembershipProvider" type="Andri.Web.MySqlMembershipProvider" connectionStringName="ConnString" applicationName="mysqlmembership" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" writeExceptionsToEventLog="true"/>
</providers>
</membership>
<pages validateRequest="false">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
<tagMapping>
<add tagType="System.Web.UI.WebControls.CompareValidator" mappedTagType="Sample.Web.UI.Compatibility.CompareValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.CustomValidator" mappedTagType="Sample.Web.UI.Compatibility.CustomValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RangeValidator" mappedTagType="Sample.Web.UI.Compatibility.RangeValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RegularExpressionValidator" mappedTagType="Sample.Web.UI.Compatibility.RegularExpressionValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RequiredFieldValidator" mappedTagType="Sample.Web.UI.Compatibility.RequiredFieldValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.ValidationSummary" mappedTagType="Sample.Web.UI.Compatibility.ValidationSummary, Validators, Version=1.0.0.0"/>
</tagMapping>
</pages>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="false" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="MySql.Data, Version=5.2.3.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="Accessibility, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Accessibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Services.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies>
</compilation>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>
<location path="Default.aspx">
<system.web>
<authorization>
<allow roles="Admin"/>
<allow roles="Tellecaller"/>
</authorization>
</system.web>
</location>
<location path="SCS_Webcontrol.aspx">
<system.web>
<authorization>
<allow roles="Admin"/>
<allow roles="Tellecaller"/>
</authorization>
</system.web>
</location>
<location path="M/scs.aspx">
<system.web>
<authorization>
<allow roles="Admin"/>
<deny roles="Tellecaller"/>
</authorization>
</system.web>
</location>
<location path="SCS_Reports.aspx">
<system.web>
<authorization>
<allow roles="Admin"/>
<deny roles="Tellecaller"/>
</authorization>
</system.web>
</location>
<location path="Webcontrol_WebService.asmx">
<system.web>
<authorization>
<allow users="?"></allow>
</authorization>
</system.web>
</location>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
</configuration>

Related

VS 2010 misses "Microsoft.ReportViewer.Common Version=8.0.0.0" when running with SSRS 2012

Our project is built with VS 2010 and reports are built with SSRS 2005 and it works just fine, in this environment.
We are trying to migrate to SSRS 2012. In run time we get this error
'Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I copied the file "MicrosoftReportViewerCommon.dll" to the bin folder, but its version is 10.0.x.x. I don't know how to find version 8.0.0.0.
I don't know exactly what we should do. Is it supposed to add this file to the project? Or the references in the project should be changed to refer to another file version?? And how this should be done??
In the web form we have this line of code:
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
and in web.config:
<system.web>
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
validate="false" />
</httpHandlers>
......
</system.web>
<system.webServer>
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
Any help is appreciated.
After 2 days of searching the web, I figured out how to overcome this error.
I had to install ReportViewer 2005, and this installer will register “Microsoft.ReportViewer.Common Version=8.0.0.0” in GAC automatically.
I've been told that is not a good practice and it is just a workaround, because the project is not running using the most updated controls and it is still using the old ones.
For now the project is working fine, but I hope some body provide me with a real solution.
I had a similar problem and found I needed three files:
Microsoft.ReportViewer.Common.dll
Microsoft.ReportViewer.ProcessingObjectModel.dll
Microsoft.ReportViewer.WebForms.dll
And the config file looked like this:
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>

Unable to access WCF service hosted on server from c#.net application

I have created a WCF service to contact sql database.
I hosted the service on remote server IIS.
Service is run and can be able browse from IIS. IIS Browse returns the service URL like below. .
When I try to access the service from outside the server ie from my local system, It is throwing error.
Instead of domain name, I have tried with the system IP and I can able to access the service via IE ()
When I tried to add the service on my .net application it is throwing error.
Error Message From Add Service Reference:
<!--The document was understood, but it could not be processed.
- The WSDL document contains links that could not be resolved.
- There was an error downloading '<!--http://sysname:4567/Service1.svc?xsd=xsd0'.
- The remote name could not be resolved: 'sysname'
Metadata contains a reference that cannot be resolved: 'http://ipaddress:4567/Service1.svc?wsdl'.
Metadata contains a reference that cannot be resolved: 'http://ipaddress:4567/Service1.svc?wsdl'.
If the service is defined in the current solution, try building the solution and adding the service reference again.-->
Error Message From svcutil.exe:
<!--Error: Cannot obtain Metadata from http://http//ipaddress:4567/Service1.svc
?wsdl
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess. For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: http://http//ipaddress:4567/Service1.svc?wsdl
Metadata contains a reference that cannot be resolved: 'http://http//ipaddres:4567/Service1.svc?wsdl'.
There was no endpoint listening at http://http//ipaddress:4567/Service1
.svc?wsdl that could accept the message. This is often caused by an incorrect ad
dress or SOAP action. See InnerException, if present, for more details.
The remote name could not be resolved: 'http'
HTTP GET Error
URI: http://http//ipaddress:4567/Service1.svc?wsdl
There was an error downloading 'http://http//ipaddress:4567/Service1.sv
c?wsdl'.
The remote name could not be resolved: 'http'
If you would like more help, type "svcutil /?"-->
here is my WebConfig file:
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<authentication mode="Windows"/>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<system.web.extensions>
<scripting>
<webServices></webServices>
</scripting>
</system.web.extensions>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<system.serviceModel>
<services>
<service name="portalConnectorService.Service1" behaviorConfiguration="portalConnectorService.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress="http://184.73.184.213:4567/Service1.svc"></add>
</baseAddresses>
</host>
<!- - Service Endpoints - ->
<endpoint address="" binding="wsHttpBinding" contract="portalConnectorService.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="portalConnectorService.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Could any one help me to resolve this error.
Try commenting out the host section which specifies a base address.
Actually that's ignored by IIS, but try it anyway.
What is the actual error message you're getting?

ASP.NET Performance Profiling 404/500 errors

Using the Visual Studio Performance Explorer, with Cassini, I'm trying to launch profiling on my (Orchard CMS 1.4.0) ASP.NET MVC3 application, but I get this error:
The web site could not be configured correctly; getting ASP.NET process information failed. Requesting http://localhost:30320/OrchardLocal/VSEnterpriseHelper.axd returned an error: The remote server returned an error: (404) Not Found.
So I searched for a solution and found this article which didn't apply, because I'm using Visual Studio's development server (Cassini) not IIS - no less IIS 6. Then I read this article and this article; of all those suggestions, the only one that made a difference was adding the location section to my web.config, to grant access to VSEnterpriseHelper.axd. But as one of those articles predicted, my 404 error simply became a 500:
The web site could not be configured correctly; getting ASP.NET process information failed. Requesting http://localhost:30320/OrchardLocal/VSEnterpriseHelper.axd returned an error: The remote server returned an error: (500) Internal Server Error.
The trailing commentaries in these various articles aren't working for me. Any suggestions? I figure I will post my (Orchard 1.4.0) web.config here, in case somebody can spot a culprit:
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor" requirePermission="false" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="log4net.Config" value="Config\log4net.config" />
</appSettings>
<!-- Added this, which eliminated the profiling
VSEnterpriseHelper.axd 404 error - and led to a 500
error instead. -->
<location path="VSEnterpriseHelper.axd">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<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>
<!--
Set default transaction timeout to 30 minutes so that interactive debugging
is easier (default timeout is less than one minute)
-->
<system.transactions>
<defaultSettings timeout="00:30:00"/>
</system.transactions>
<system.web>
<!--<trust level="Medium" originUrl="" />-->
<httpRuntime requestValidationMode="2.0" />
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" targetFramework="4.0" batch="true" numRecompilesBeforeAppRestart="250" optimizeCompilations="true">
<buildProviders>
<add extension=".csproj" type="Orchard.Environment.Extensions.Compilers.CSharpExtensionBuildProviderShim"/>
</buildProviders>
<assemblies>
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<remove assembly="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<remove assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<remove assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<remove assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<remove assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<remove assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<remove assembly="System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<remove assembly="System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<remove assembly="System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<remove assembly="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<remove assembly="System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<remove assembly="System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<remove assembly="System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<remove assembly="System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<remove assembly="System.WorkflowServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<remove assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<remove assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<remove assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Forms">
<forms loginUrl="~/Users/Account/AccessDenied" timeout="2880"/>
</authentication>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
-->
<customErrors mode="RemoteOnly" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<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.Linq"/>
<add namespace="System.Collections.Generic"/>
<add namespace="Orchard.Mvc.Html"/>
</namespaces>
</pages>
<httpHandlers>
<!-- see below -->
<clear />
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<httpModules>
<add name="WarmupHttpModule" type="Orchard.WarmupStarter.WarmupHttpModule, Orchard.WarmupStarter, Version=1.0.20, Culture=neutral"/>
</httpModules>
</system.web>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WarmupHttpModule" />
<add name="WarmupHttpModule" type="Orchard.WarmupStarter.WarmupHttpModule, Orchard.WarmupStarter, Version=1.0.20, Culture=neutral"/>
</modules>
<handlers accessPolicy="Script">
<!-- clear all handlers, prevents executing code file extensions, prevents returning any file contents -->
<clear/>
<!-- Return 404 for all requests via managed handler. The url routing handler will substitute the mvc request handler when routes match. -->
<add name="NotFound" path="*" verb="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode" requireAccess="Script"/>
</handlers>
<!-- Prevent IIS 7.0 from returning a custom 404/500 error page of its own -->
<httpErrors existingResponse="PassThrough" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="App_Data/Dependencies"/>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="3.0.0.0"/>
<bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
In my case, I had
<validation validateIntegratedModeConfiguration="true" />
set in my web.config. When I changed it to
<validation validateIntegratedModeConfiguration="false" />
things magically started working. Three hours down the drain....
I faced similiar problem, and I found one solution. I found out that I get 404 error because VSEnterpriseHelper.axd is routed through MVC, and it's happening whatever I set in Web.config. So I figured out that I should route it properly. So I added route to handle this file, and I wrote handler:
Handler:
public class DefaultRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new DefaultHttpHandler();
}
}
internal class DefaultHttpHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
string contentPath = context.Request.PhysicalPath;
#if DEBUG
if (contentPath == context.Server.MapPath("VSEnterpriseHelper.axd"))
{
var assembly = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name == "Microsoft.VisualStudio.Enterprise.AspNetHelper");
if (assembly == null)
{
if (File.Exists(#"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Enterprise.AspNetHelper.dll"))
{
assembly = Assembly.LoadFrom(#"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Enterprise.AspNetHelper.dll");
}
if (File.Exists(#"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Enterprise.AspNetHelper.dll"))
{
assembly = Assembly.LoadFrom(#"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Enterprise.AspNetHelper.dll");
}
}
var type = assembly.GetType("Microsoft.VisualStudio.Enterprise.Common.AspNetHelperHandler");
var handler = (IHttpHandler)Activator.CreateInstance(type);
handler.ProcessRequest(context);
return;
}
#endif
[...]
}
}
Route definition:
DefaultRouteHandler defaultHandler = new DefaultRouteHandler();
routes.Add(new Route("{*resource}", new RouteValueDictionary(), new RouteValueDictionary(), defaultHandler));
I fixed the same 500 error, here is what you need to do (partially borrowed from here with my own comment):
Make sure you have write permissions on your web.config file
If your website has locked down security on the root folder (using either
forms or windows authentication etc), make sure you add a [location] tag to allow full access to the vsenterprisehelper.axd file, like this:
<location path="VSEnterpriseHelper.axd">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
Ensure AXD extensions are configured in IIS for your site
There are problems if your AppSettings are stored in a separate configuration file, and your web.config refers to them with a configSource attribute
I finally (4 hours later) fixed this by moving my default .axd route handler from RouteConfig.cs into the main Global.asax.cs:
AreaRegistration.RegisterAllAreas();
// Register .axd route ahead of WebApiConfig
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
Because I was using WebAPI, the WebApiConfig routes were picking up the calls to the AXD as they were being registered before RouteConfig.RegisterRoutes where the .axd exception is by default.

Manually upgraded from MVC3 to MVC4 Beta and getting "not valid #" sign errors

I'm using Razor in both
Any page that using the # sign. Its almost like either the System.Web.WebPages or System.Web.Helpers are not able to determine the Views
Here is the actual error:
"#" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.
Here is my web.config that is in the /Views folder
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.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=4.0.0.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.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
Refer to MVC 4 ReleaseNote
There is a section describing Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4
It turns out switching to MVC4 beta was not handling ### escapes properly
I have a twitter client where it will render a person's screen name in a view like this:
###TwitterUsername
This will render a # with the escaped ## and then render the twitter name with #TwitterUsername
This does not work with MVC4. So I had to change to this and it worked fine:
#Html.Raw("#")#TwitterUsername
Not near as pretty, but it works.
Is there something not right with Razor parsing on MVC4 or am I not doing something right implementing it?
The output of this is:
#jordanshane
Perhaps these links will help:
http://forums.asp.net/t/1751597.aspx/1
http://haacked.com/archive/2011/05/09/compiling-mvc-views-in-a-build-environment.aspx
MVC4 Razor confused about braces
I had a similar problem when upgrading from MVC3 to MVC4 when outputting a 'page' that is an Excel dump in Excel XML format. For example, I had the following line in my XML page layout file:
Doesn't work:
<NumberFormat ss:Format="m/d/yyyy;##"/>
The parser gave me the following error:
Parser Error Message: ""/>" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.
The Html.Raw("#") answer worked for me, and I wasn't readily able to find any reason for this behavior in the links that several other answers provided. In case anyone is looking for a more terse looking solution, here's another possibility:
Does work:
<NumberFormat ss:Format="m/d/yyyy;#('#')"/>

The name 'model' does not exist in current context in MVC3

I added a cshtml page in an project. When I tried to add the following declaration to it, I get an error: "The name 'model' does not exist in current context".
#model xyz.abc.SomeClass
I checked the references, all of them are in place. I added a web.config in view folder, but that didn't fix it.
Is there anything i am missing?
Update: If you are using a newer version of MVC, the same process applies, just be sure to use the correct version number in the web.config's <host> line.
Well, I found myself experiencing the same thing you did, and after a bit further research, I found out what the problem is!
You need to include the default MVC3 web.config for the Views folder. MVC3 has two: one in the root for your application, and one for the views folder. This has a section for included namespaces. Be sure that yours looks something like this:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.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.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
I suggest that you create a new MVC3 project, then just copy the web.config created for you into your views folder.
Important Once you've done that, you need to close the file and reopen it. Voila! Intellisense!
I ran into this same issue when I created a new area to organize my pages. My structure looked like:
WebProject
- [] Areas
- [] NewArea
- [] Controllers
- [] Views
- [] Controllers
- [] Views
- Web.config
- Web.config
The views created in the Views folder under the WebProject worked fine, but the views created under the NewArea threw the following error:
The name 'model' does not exist in the current context.
To fix this I copied the web.config in the Views folder under the WebProject to the Views folder in the NewArea. See below.
WebProject
- [] Areas
- [] NewArea
- [] Controllers
- [] Views
- **Web.config**
- [] Controllers
- [] Views
- Web.config
- Web.config
I ran into this because I manually created this new area using Add -> New Folder to add the folders. I should have right-clicked the project and selected Add -> Area. Then Visual Studio would have taken care of setting the area up correctly.
If your views are in a class library assembly, which is useful for reuse of shared views among projects, then just doing what Adam suggests might not be enough. I still had issues even with that.
Try this in your web.config in the root of your project:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.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=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<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.webPages.razor>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<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=2.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=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<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" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
And this in the web.config in your views folder:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.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=4.0.0.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.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
This worked for me. I now have intellisense and no compile errors on my views in a non-MVC project that I can then reference from multiple MVC websites.
I ran into this problem when I inadvertently had a copy of the view file (About.cshtml) for the route /about in the root directory. (Not the views folder) Once I moved the file out of the root, the problem went away.
Had similar problems using VS2012 and VS2013.
Adding the following line to <appSettings> in the main web.config worked:
<add key="webpages:Version" value="3.0.0.0" />
If the line was already there but said 2.0.0.0, changing it to 3.0.0.0 worked.
Update: 5/5/2015
For your MVC 5 project you need to set the Version to 5.0.0.0 in your /views/web.config
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</system.web.webPages.razor>
While you declare the model at the top of the view using code like this:
#model MyModel
you need to capitalise your references to it below, for example:
#Html.Encode(Model.MyDisplayValue)
I believe a missing web.config in the Views folder would be the major cause of this, but if that is fixed and the problem still persists, check that you are using Model, not model to refer to it in the source.
I ran into this problem as well. My circumstances were a little different.
One of my view folders was accidentally moved to my project's root directory. This lead to the route
project_root/SignUp/ViewName matching before project_root/Views/SignUp/ViewName. This caused the #model error.
After moving the views back into the appropriate location, the directory was somehow recreated in the project root. This time, empty. /SignUp/ViewName worked, but /SignUp/ threw a 403 - Forbidden: Access is denied. error. The entire folder must be removed from the project root.
I hope this helps someone. I spent hours believing the problem was caused by our recent upgrade from MVC 3 to MVC 4. Just a note: Upgrade problems should only occur between MVC 2 and MVC 3. If you see this problem on later versions, it's probably not due to the upgrade.
It took me ages to solve this issue, but finally I hope I have solved it on MVC, that is similar:
I have reinstall ASP.NET 4.5 (http://www.asp.net/downloads)
I have followed the upgrading tutorial on http://www.asp.net/whitepapers/mvc4-release-notes
BUT this mentioned paragraph is wrong for me
System.Web.Mvc, Version=4.0.0.0
System.Web.WebPages, Version=2.0.0.0
System.Web.Helpers, Version=2.0.0.0
System.Web.WebPages.Razor, Version=2.0.0.0
Because I have Razor in System.Web.Razor, so I changed the razor namespace to System.Web.Razor.
Add this to your web.config
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
</appSettings>
I have add the assembly reference to all these assemblies above
Locate the ProjectTypeGuids element and replace {E53F8FEA-EAE0-44A6-8774-FFD645390401} with {E3E379DF-F4C6-4180-9B81-6769533ABE47}.
That is all.
It is a horrible mistake but:
Be sure you have Web.config files in your View at Remote. Maybe you skipped to upload it by your Ftp programme's filters.
I was missing web.config under Areas/MyArea/Views/web.config. Once added it worked fine. This was with MVC 5 and .NET4.5
There is also another reason. In my case, I had copy an index.cshtml file to web root folder (outside the Views folder) as a backup from remote server.
So, I kept changing my /views/web.config, kept changing my /views/home/index.cshtml and error kept happening... until found out the /index.cshtml outside the views folder, deleted it and sure, it all went back to normal!
I ran into this same problem, but in my case, the only thing that had changed is that I had uninstalled Visual Studio 2012 and installed Visual Studio 2013. I opened up our solution, but I kept getting the same The name 'model' does not exist in current context error in every Razor view.
My coworker suggested checking for updates for VS2013. After I installed the VS2013 Update 1, I stopped getting this error.
Check your config file on views directory. in the
add the key for MVC 4/5
Reinstalling the nuget solved it for me
PM> Install-Package Microsoft.AspNet.Razor -Version 3.2.3
For me this was the issue. This whole block was missing from the section.
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=2.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=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
I've got the same issue after updating packages. I did the whole stuff You've written above in this topic, but the red underlying of the model keyword has not disappeared. Later, found solution: just deleted 'package' folder from my project's dir and rebuilded, in the meantime allowed NuGet to restore missing packages. Refreshed, and it's done!
Check your web.config file should be exist in published files
I was facing the same issue and then I find a solution. The solution is:
Close Visual Studio
Delete the SUO file
Restart Visual Studio
The .suo file is a hidden file in the same folder where the .svn solution file exists. Hope, it'll work!
Closing Visual Studio and re-opening worked for me. Must be a weird bug.

Resources