I use ASP.NET Identity 2.0 in an ASP.NET MVC5 project that is composed of three layers; Web application (presentation layer), Unit Test (test project) and Class library (data layer). Normally IdentityConfig.cs is located in the App_Start folder of Web application but as I implement a Group-Based Permissions Management as indicated on this page I want to keep all the domain models and IdentityConfig.cs file to the Identity folder in data layer project instead of the web project (presentation layer). Because IdentityConfig.cs needs to access DbContext class that is placed in my data layer project. Is there any problem doing this? On the other hand, could you please explain a little bit what is the App_Start folder?
Here is the ASP.NET Identity folder structure in my project below:
DataLayer (class library)
Concrete EFDbContext
Entities (my entity classes except from ASP.NET Identity entities)
Identity
ApplicationGroupManager
ApplicationGroupStore
GroupStoreBase
IdentityConfig
IdentityModels
PresentationLayer (Web app)
App_Start
Controllers
AccountController
GroupsAdminController
ManageController
RolesAdminController
UsersAdminController
As long as you have asp.net identity, you will have to add reference to it in the presentation layer (web project) and the configuration will be kicked off from there.
If you moved it to the data access layer, then you put a security concern in the data access which is not right.
Normally, I just leave it in the web project and create my own user class and link it to the ApplicationUser class through its Id, but if you must seprate it, then you can put the IdentityConfig in a separate library that handles the cross cutting concerns like security, logging and exception handling as this layer will be working across all layers.
In the data access, you can have a custom user and role stores and put the configuration in the cross cutting library and link all of that in the presentation layer as this is the kickoff point for your web app.
The App_Start is justa normal folder that has the code that will be executed when the application starts, and you can put this code any where else, it is all called by the Global.asax file
Related
I'm facing this problem with EntityFramework 5 (VS 2012). I have the following projects in my solution:
I'm using database first and the designer
Data. Where my entities model and entities are.
Security. Where the business logic for security is.
Web. The web UI
Security has a reference to Data so it can use the model and entities to retrieve data from the database. In Security I have a method the returns a list of MenuOptions (this is an entity in the project Data) to the UI (Web project). In the Web project I then want to iterate the list of MenuOptions to build a menu. The problem is that I don't want to add a reference to Data in my Web project just to be able to have access to the entities. Then, how can I make the entities in Data visible to Web without adding a reference to the full project? (I only want the entities to be accessible to the UI).
Separate the entities in a dll (or project) put your DbContext inherited class and entities mapping configuration in another.
This way you can distribute your entities dll in different projects without sharing DB access items.
I'm working with Silverlight. In it, I've created a web project.
I always have created desktop application where I divide my projects in three modules:
Domain
Application
Presentation
But now, I'm working to the server side and I really have no much idea about how to build my architecture. In it, I plan to have a entity model for my database.
So, can you give some ideas about the modules how to structure?
I structure my Silverlight server-side libraries as follows:
MyApp.Host: The main hosting project for the silverlight application. Brings in fact nothing more than the aspx file housing the XAP and the ClientBin folder containing the XAP files. Additionally you can use a global.asax file to run a bootstrapper or any other components needed to startup your server-side application.
MyApp.Server.Services: This project contains all my domain services. The client side libraries have a RIA-Services link set to this project
MyApp.Server.Data: This project contains my Entities, and my data-access-layer, such as database contexts or repositories encapsulating the database access.
Note: This structure is for RIA-Services applications. When using other service types you might want to have a portable library called MyApp.Interfaces for accessing services and entities.
I have a MVC3 app that is calling a WCF Service Application. The WCF Service App has its own web.config file (comes when you create the project automatically). In this .config I added an appSetting section with key to retrieve.
When I run the MVC app and it calls the WCF svc and the svc cannot see this appsettings value. If I move the appSettings section over to the MVC web.config the service application sees the value.
I would expect this from a calling application if it were a Winform or client based application calling a DLL but not where I have 2 separate apps where I actually want separate configuration files.
For example, I want to configure unity in my web services to perform dependency injection. I don't want the calling web application to know or have to define these values. The service should have them.
The issue I had was with the Unity configuration in the MVC app. Originally I had been pointing at a class library for my services layer, I swapped this over to use WCF. When I did this I left in the old type registrations which unity resolved and caused it to look at the new WCF project (same namespaces/class names) as a class library instead of using the endpoints that I registered.
Ripped out those specific class registrations leaving just the interfaces and endpoints and it worked like a charm.
I made one application in silverlight4 and used EDM and WCF-RIA for database access.
Now I want to integrate this application to asp.net project and when I integrate it into the ASP.net project it is giving this exception-
Microsoft JScript runtime error: Unhandled Error in Silverlight Application Load operation failed for query 'GetQuestions'. The remote server returned an error: NotFound. at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
at System.ServiceModel.DomainServices.Client.DomainContext.<>c_DisplayClass1b.b_17(Object )
so please help me anybody.
Your RIA Services DomainService has 2 parts. You have copied the client part by virtue of copying the XAP file, but you are missing the RIA WCF server-side part of the service.
You need to move the Domain service files from your original Silverlight website to your new ASP.Net project (along with any web.config settings required to wire it up properly). This is not in the ASPX files. Without seeing the specifics of your existing projects I can't tell you exactly what filenames you need to migrate.
My suggestion is to always create RIA Service libraries instead of adding directly to a Silverlight application. Then you can link the Client-side library to any number of Silverlight applications, then link the .Web part of the RIA library to your website to provide the WCF service. Again the key is to migrate the config settings.
It will probably make a lot more sense if you create a new RIA services library project, add your EDM etc, then link the halves to a separate Silverlight app and your new ASP.net website.
Step-by-step:
Create RIA Services Library project by selecting Add New Project. Select Silverlight on the left. Select WCF RIA Services Class Library on the right. I will assume it is called the default name RIAServicesLibrary1 for this example. It will create a Silverlight client library called RIAServicesLibrary1 and a standard .Net library called RIAServicesLibrary1.Web for use by the Web server.
Add your EDMX to the RiaServices.web project. Select Add new item. Select Data on the left. Select ADO.Net Entity Data Model on the right. I will assume it is called the default Model1.edmx for this example. Connect it to your database tables etc.
Build your project so that the next step will find your data model.
Create a Domain Service referencing your EDMX models in your RiaServices.web project. Select Add new item. Select Web on the left. Select Domain Service Class on the right. I will assume it is called DomainService1.cs for this example. Choose your data items from the Add New Domain Service Class popup window by ticking the checkboxes. A set of RIA services objects and methods will be created for each item you select.
Add a reference to the client Ria services library project (RIAServicesLibrary1) to your Silverlight application.
Add a reference to the web RIA services library project (RIAServicesLibrary1.Web) to your hosting web application (e.g. you ASP.Net website).
Copy/merge the various sections in the RIAServicesLibrary1.Web/app.config file into your <webapplication>/web.config file. This will include any connection strings and the module sections.
Build the project again so that the Data Source window will see your new Domain Context data sources.
Use the RIAServicesLibrary1 client object (called DomainService1 in this example) directly from your Silverlight code like this:
DomainService1 client = new DomainService1();
or use the Data Sources window to drag/drop a new grid etc onto a page.
If the Data Sources window is not visible select the "Data" menu then the "Show Data Sources" option.
For more information try this Microsoft link: Using WCF RIA Services
I have a solution containing
asp.net project
class library
WCF service class library
WCF service application
I've added a project refference from the asp.net project to the class library project and to the service class library project.
I've published the asp.net application, loaded it to the webserver root. all ok.
Now for the service, I've created a new folder on the root called WCF, and placed the aplication in there.
Is this The way I should deploy the sollution? Are this the steps when you have more than a simple asp.net application?
PS: How do I change that WCF folder to make it an application trough a control panel because I get this:http://surveillancecamera.somee.com/WCF. The reason why I get this is described here:
I would treat the WCF service as a separate entity altogether. Deploy the WCF service and verify it works, then deploy the ASP.Net application.
WCF services have a different set of configuration rules that don't always pair nicely in the same "application root" as your ASP.Net web application. In addition, you may want to use the same WCF service in different applications, and it may not be accessible if it is tightly coupled to this ASP.Net application.