I've searched over the topics on Stackoverflow but this question hasn't been answered so far.
I have two projects in my solution: a) MVC Application b) Class Library.
The class library acts as a plugin, so it contains views. The main problem is that I have no intellisense in the view's markup for my classes contained within the class library (the same assembly as the views).
In the beginning I couldn't even write <%= Html.RenderAction... %>. I've solved that by adding a Web.config file to the class library with the following section:
<configuration>
<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"/>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
Now it recognizes Html.RenderAction, etc in the view's markup. However I've no idea how to get access (with intellisense) to my classes contained within the same assembly as the views :(
Kind regards,
Jakub
There is a separate list of namespaces in the config where you need to include your custom namespaces. The example below demonstrates in the simplified web.config you add your namespaces. If this still does not work make sure that your project and webconfig has correct references to the other assembly.
<configuration>
<pages>
<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="Blog.Models"/> <!-- These are my custom namepaces -->
<add namespace="Blog.Views"/>
</namespaces>
</pages>
</configuration>
The Spark viewengine as the same issue, see their documentation. Basically they say 'make a web app project' and treat it like a class library in every other way. Worked for me in Spark, maybe it'll work in your situation as well?
Out of the box, MVC does not support multiple projects. Check my previous questions for more detail.
Related
I've encountered an odd problem: I'm trying to migrate an ASP.NET 4.0 website to an ASP.NET web application. Visual Studio's "Convert to Web Application" function actually worked quite nicely, but the only thing that's not working are the references to charts. I'm getting the error:
The type or namespace name 'Chart' does not exist in the namespace
'System.Web.UI.WebControls'
From the .designer file. The designer is automatically creating this type of code:
protected global::System.Web.UI.WebControls.Chart ClientHoursPie;
Based on research I have done, the proper 4.0 namespace to use for charts is System.Web.UI.DataVisualization.Charting. I have added the following components in the web.config (copied from the original website, which was working fine):
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
I can correct the namespaces in the designer files but each time the aspx file is saved, the designer reverts back to the old namespace.
I would love to avoid having to rebuild all of the individual pages from scratch. Is there a setting somewhere that I've missed?
Thanks in advance.
I was able to solve the problem by adding a few entries to web.config that I had missed. Anyone experiencing this problem needs to make sure you include:
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
And this (in system.webServer section):
<handlers>
<remove name="ChartImageHandler"/>
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
I can compile and test my .NET 4.0 web application just fine within Visual Studio 2010. If, however I point my local IIS to the folder containing the application, I get the following error:
Compiler Error Message: CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
Source Error:
Line 388: <add namespace="System.ComponentModel.DataAnnotations" />
Line 389: <add namespace="System.Configuration" />
Line 390: <add namespace="System.Linq" />
Line 391: <add namespace="System.Text" />
Line 392: <add namespace="System.Text.RegularExpressions" />
Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config Line: 390
How is it that the web.config from the framework won't compile for me?
I have found similar problems on the web and most just say 'add this reference...', but it can't be the right thing to edit the default web.config -- can it?
This worked for me. Have this assemblies in the web.config file
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
I think you need to add the assemblies below in your web.config -
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
You will get System.Linq in core assembly
If you have a website, asp.net needs proper references to be able to compile it. A web application would not need that.
There are some assemblies referenced in the machine.config, some might be missing depending on your code, you can add them to machine.config or the root web.config.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What is the purpose of the Assemblies node in Web.Config?
I removed all the 'add' elements in the compilation/assemblies element.
So initially in my application's root web.config file:
<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.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
Now it looks like:
<compilation debug="true" targetFramework="4.0">
<assemblies>
</assemblies>
</compilation>
And my application still works. The project file still has all the references I removed, but this section appears to be unused during compilation (inside visual studio).
What is going on?
The references in this section of the application are used for the automatic ASP.NET compilation that is done on the fly. If you are deploying a compiled site, (no .cs or .vb files) then you are fine to remove it.
I tried to install MSCharts on my Win2008 server.
It installed without problem.
Then I wrote
in config.
But when I'm trying to open page with charts it returned following error.
No http handler was found for request type 'GET'
Do you have any thougths about the problem?
This is what you need for ASP.NET 4.0 / IIS 7.5 on Windows 7:
Your web.config must contain the following:
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;" />
</appSettings>
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<system.webServer>
<handlers>
<add name="ChartImg" verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
You also need this at the top of your aspx page:
<%# Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
Hope this helps
Like Danil said, IIS7 requires that you put the handlers in
<system.webserver>
<handlers>
Add the two lines below after the last add-in handles
<add name="ChartImg" verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="ReportViewer" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler,Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Solution was in web config. IIS7 required to write handlers inside system.webserver but not in the system.web. So I just move handler and add name attribute as it became required.
Don't know anything about MSCharts, but I'd say try changing the AppPool for the app to 'Classic .NET AppPool'.
Alternatively, you may need to modify your web.config to add the handler in there. See Rick Strahl's post here.
After deployment of my website to IIS, I'm getting the following error message when trying to access a session:
Session state can only be used when
enableSessionState is set to true,
either in a configuration file or in
the Page directive. Please also make
sure that
System.Web.SessionStateModule or a
custom session state module is
included in the
\\
section in the application
configuration.
I access it in Page_Load or PreRender events (I tried both versions). With Visual Studio Dev Server it works without a problem. I tried both InProc an SessionState storage, 1 and multiple worker processes. I added a enableSessionState = "true" to my webpage explicitly.
Here is part of web.config:
<system.web>
<globalization culture="ru-RU" uiCulture="ru-RU" />
<compilation debug="true" defaultLanguage="c#">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.DataSetExtensions, 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.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<pages enableEventValidation="false" enableSessionState="true">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" 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" />
<add name="SearchUrlRewriter" type="Synonymizer.SearchUrlRewriter, Synonymizer, Version=1.0.0.0, Culture=neutral" />
<add name="Session" type="System.Web.SessionStateModule" />
</httpModules>
<sessionState cookieless="UseCookies" cookieName="My_SessionId" mode="InProc" stateNetworkTimeout="5" />
<customErrors mode="Off" />
</system.web>
What else do I need to do to make it work?
I tried to monitor if IIS accesses the aspnet_client folder with Process Monitor and didn't get any access.
The solution happened to be very curious. Though IIS7 jn WIndows 2008R2 in error description says to add SessionStateModule to system.web section, it should be added to system.webServer section.
<system.webServer>
<modules>
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</modules>
</system.webServer>
Sessions should work on a plain, empty application. That is, all the default values should work.
If it's not working with basic test applications, then IIS may have got confused with your application.
Try deleting your IIS application. Then create a new virtual directory, restart IIS, and then add your application again.
Also, double check your application's ASP.Net settings. Make sure it's set to the correct version of ASP.Net.
While searching, I also ran into...
http://ramonaeid.spaces.live.com/blog/cns!A77704F1DB999BB0!181.entry
Hope that helps.
Make sure that the service names "ASP.NET State Service" is running and then add this to your web.config.
<sessionState mode="InProc" server="127.0.0.1" port="42424" ... >
Reference:
http://msdn.microsoft.com/en-us/library/ms972429.aspx
http://msdn.microsoft.com/en-us/library/h6bb9cz9(VS.71).aspx
Comment:
Maybe is better to manual change the port to something else. This can be done with regedit.
HKLM\Syste\CurrentControlSet\Services\aspnet_state\Parametres\Port -> 42424
Some more infos:
http://msdn.microsoft.com/en-us/library/ff648667.aspx
Has this particular server been used for anything else? Is it a Windows 2008 server and IIS7?
I'm willing to bet that you're missing some server roles for IIS, have you checked those by right clicking "Computer", choosing "Manage", going to the roles management (it's on the primary tree in computer manager) and checking the installed bits for IIS?
If this is IIS6 then you may have other concerns. But I figure we'll start with something simple, see if we can't help you figure this one out.
What is your folder structure. Do you have web configs at a higher folder that may have explicitly disabled this?
If possible, reregister asp.net
Open Control Panel
Programs\Turn Windows Features on or off
Internet Information Services
World Wide Web Services
Application development Features
ASP.Net <-- check mark here
ref: How to register ASP.NET 2.0 to web server(IIS7)?
Try adding in pages section in web.config the following section:
<namespaces>
<add namespace="System.Web.SessionState" />
<namespaces/>