I have 2 seperate areas for my ASP.NET MVC 3 website - Admin (Intranet website) and Client (Internet website).
The Model (business and data access layer) will be used by both websites. The websites will be hosted on seperate servers. So, the folder will not be shared.
So, I am planning to create the DLL of the Model and put the DLL in the Bin Folder of both website and use it.
I hope this will keep my UI neat and less code as well.
Now, my doubts are:
Do I need to create a Class Library project to create the DLL of the Model or do I need to use and MVC web application project to create the DLL?
Where should I put the web config? Hope I need in both Model and also in UI?
Do I need to create a Class Library project to create the DLL of the Model
Yes, a separate class library shared between the 2 web applications is the best approach.
Do I need to use and MVC web application project to create the DLL (looking for the best approach)?
No, the ASP.NET MVC could contain only the views. Do not reference and reuse a web application for common logic in other applications.
Where should I put the web config?
Each ASP.NET MVC web application should have its own web.config.
Yes, your abstracted business logic should be in a separate class library project. You can then reference this project from web apps in the same solution or compile it and reference it as a DLL. Your web.config file(s) will still live in your web project(s).
To add settings for your class library in your web project, use configuration sections:
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="My.Class.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<My.Class.Library.Properties.Settings>
<setting name="SettingName" serializeAs="String">
<value>SettingValue</value>
</setting>
</My.Class.Library.Properties.Settings>
</applicationSettings>
Related
Is it possible to run classic asp page in integrated mode of IIS7?
I need it for integrating our legacy asp application with new asp.net mvc application.
I have seen seen several examples with web.config:
<add name="classic-asp"
path="*.asp"
verb="*"
type="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
resourceType="File"
preCondition="integratedMode" />
But it doesn't work for me.
Thanks,
You can not run Classic ASP(VBScript) and ASP.NET/MVC using same application pool.
You will have to create separate folders for each part or at least one as virtual folder for classic asp and assign to it application pool as non-managed code.
Main reason for this because as you clearly stated in your question - both using different ISAPI filters: c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_filter.dll for MVC or NET part and it will not handle Classic asp as you expect it to.
For that you need C:\Windows\System32\inetsrv\asp.dll
I have WCF application and MVC application in 1 solution. When I deploy projects with WCF, I always deployed them like 2 sites. Firstly, I deployed WCF application to IIS, then MVC application and use WCF's endpoint address.
My question is that, is it possible to deploy MVC and WCF applications together, not like 2 separate site? WCF runs inside ASP application. And in IIS we have 1 site.
Yes it is possible. Merge WCF application & MVC application together into a single project. If your WCF project contains too many classes you can move them into a class library.
But you must move following items into web application project:
Move .svc file into MVC project, this file does all the magic to
host your WCF service into IIS.
Move System.Service Model section of WCF application into MVC
project.
I done this.. Works well in local...
But When you host it in an IIS or web deploying
add this code in webconfig
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I was exploring the source of the default MVC 5 projects and found that there are two Web.Config files created. One is in the root of the project and the other in the root of Views. Why are there two?
The web.config file exists in the Views folders to prevent access to
your views by any means other than your controller. In the MVC design
pattern, controllers are supposed to route requests and return a
rendered view to the calling client. In other words, your view at
www.mydomain.com/MySuperController/AwesomeAction1/SweetPage.aspx
should not be directly accessible.
What does the Web.Config file do in the views folder of a MVC project
All configuration files in IIS are hierarchical. You can have one in every directory, if you want to, and each lower-level configuration overrides the higher level ones.
In the machine-level configuration there are definitions for what each of the sections mean and which web.config files those sections can appear in, which builds up a pretty complex system of settings that can be changed at each level. See, for example, this article on Working with Configuration Files in IIS 7, in particular the section Configuration Levels
In the case of an MVC application, the top-level configuration file defines the web server and web application settings that apply to your entire project. The web.config file that's in your Views folder overrides those settings, where needed, and adds additional settings that only apply to the actual Razor views in your project, and not (say) the App_Data folder or your Global.asax. For example, the web.config for your views adds an additional assembly reference that adds an XML tag for the MVC namespace, which only makes sense in the context of an HTML page:
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
I have to use Sync Framework 2.0 in our WPF app that will contain SQL Compact 3.5 and will synchronize with SQL Server 2008.
I followed this video : http://download.microsoft.com/download/6/7/3/6730f0e7-a649-4656-96ab-150c7501a583/IntroToSyncServicesADODetNet_HighQuality.wmv.
But instead DataSet I've used EntityFramework 4.0 and C#.
I'm very interested in code auto generation by adding Local Database Cache file with extension sync. It is great, and I can modify code in my partial class to change base functionality.
Everything works grate when I have code for client and server place in WPF application.
Everything works grate when I use WCF Class Library that contains server synchronization logic.
But... In the following example they show us how to run solution and host WCF in local "WCF Host" only on my computer.
The first question is:
"How can I create instance of class from WCF Class Library that contains all server synchronization logic and then host it and expose in ASP.NET MVC 2.0 application."
The most important thing is to keep this *.sync files and don't write all the code manually it gives me the option to automatically update this code when database schema would change.
The second question is:
"How can I configure endpoints and behaviors for this instance of WCF Class Library in my web.config when it has its on app.config in class library?..."
Unfortunately wizard for *.sync files only sees local WPF application, or WCF Class Library, I can't choose directly ASP.NET MVC 2.0 (it would be great) to generate class for synchronization in web app.
I would be very pleased to see working example.
Regards,
Daniel Skowroński
Solution to create WCF Class Library instance with synchronization logic hosted in ASP.NET MVC 2.0:
follow http://download.microsoft.com/download/6/7/3/6730f0e7-a649-4656-96ab-150c7501a583/IntroToSyncServicesADODetNet_HighQuality.wmv to create WCF Class Library
create ASP.NET MVC 2.0 App and add WCF Service
delete C# file *.cs behind *.svc
add Project Referece from ASP.NET projet to WCF Class Library
edit your *.svc file in ASP.NET
here you will see something like:
<%# ServiceHost Language="C#" Debug="true" Service="namespace-assembly.class" CodeBehind="filename.svc.cs" %>
where Service is Factory method that will create instance of "namespace-assembly.class" so, you have to change this to "wcf_librrary_namespace-assembly.****DataCacheSyncService" and CodeBehind to "wcf_librrary_namespace-assembly.filename.cs"
next modify wcf instance in WCF Class Library that will enable hosting it with the same credentials as asp.net app, simply add : [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] attribute
next configure web.config:
<service name="asp.net-namespace.wcf_service_name" behaviorConfiguration="service_nameBehavior">
<host>
<baseAddresses>
<add baseAddress="http://ipaddres/asp.net-app-name/service-name.svc" />
</baseAddresses>
</host>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="" binding="basicHttpBinding" contract="wcf_librrary_namespace assembly.I****DataCacheSyncContract" />
</service>
<behavior name="service_nameBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
add also
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
below
<system.serviceModel>
now simply publish it to your server and create ASP.NET app
now add Service Reference to your Client Application
here we have problem that when you will execute:
**DataCacheSyncAgent syncAgent = new **DataCacheSyncAgent(new **DataCacheSyncContractClient());
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
You will probably get Exception: “Cannot convert type ** to Microsoft.Synchronization.Data.SyncGroupMetadata, One solution to resolve this issue for now that I’ve found is to expand your service reference and b CTR+H rename all “asp-net-assembly-SyncGroupMetadata” and other similar files to “Microsoft.Synchronization.Data.SyncGroupMetadata” etc.
Now synchronization should start
HTH
Regards,
Daniel Skowroński
I have a ASP.NET MVC app that is using SQLite database through Entity Framework.
Everything works on VS 2008's local development webserver.
However, deploying the web app to my service provider causes this error:
[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1308959
System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +35
Service provider has commented that they do not support SQLite. I had though that SQLite is independent of service provider's settings since it's App_Data deployable.
Has anyone experiences of a succesfull Entity Framework + SQLite deployment?
Cheers,
-pom-
You're unlikely to be reading this anymore, but you're missing the following in your app.config (or, for you, web.config):
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>
Specifically, if you're using sqlite in a library which is linked into your website, you must add this to the config file of the website - not the library! This is because of how you're loading the provider: essentially, you're determining at runtime which dll to load, using the string "System.Data.SQLite", and locating the appropriate provider is done using the settings of the entry assembly.
Edit: By the way, when you're writing the library that has an sqlite dependancy, you can avoid this complexity. You do not need to use DbProviderFactories to look for sqlite at runtime; you can take a compile-time dependancy just as well, which can be easier to manage. Then you can ignore the above app.config section, and instead replace all instances of:
DbProviderFactories.GetFactory("System.Data.SQLite").CreateConnection()
with
System.Data.SQLite.SQLiteFactory.Instance.CreateConnection()
If you do so, you're using a plain library call to create the connection and there's no runtime selection of db provider. That can be less flexible since you can no longer exchange data providers via the config file, but for many libraries that's sufficient. Unfortunately, if you don't control the library code, this isn't an option.
Have you tried adding the required DLL(s) to your application's bin directory? You might want to look at Phil Haack's article on Bin Deploying ASP.NET MVC for ideas on how to do this automatically.
SQLite needs full trust permission for ASP.NET application deployment. Many shared hosting providers don't allow that. You might wan't to check this.