I have a database that I've created. I also have created a new ASP.NET MVC application using Individual User Account boilerplate code to get started. I notice that my web.config is pointing to a default location. I want to keep the boilerplate code and bring in my data model using Entity Framework so that. However user authentication tables and the tables I have created are in 2 different databases. What is the best way to resolve this?
Ultimately I just want to use the ASP.NET MVC authentication and bring in my data using Entity Framework and have both my data and the user account tables in the same database. If there is a better approach to doing this all together I am all ears.
You could create an attribute on each Individual User that has their own connection string so that every time you create a new db context, you do it passing their connection string attribute, then the context would be pointing to the correct database each time.
Related
I have been reading through multitenancy in hibernate and couple of post from stackoverflow but it seems they are not addressing the requirement that i have, so here it is. I am working on a SAAS based application model where i have one application been served by multiple customers, and for every customer there will be a independent instance of the tenant database(postgresSql). Apart from this i also have a master database that will be used to authenticate the user and to identify which tenant database it belongs, consider this master database will have information like the connection URL to the tenant database.
When the user logs in i will authenticate it with the master database get the tenant database information like connection URL and connect to that database and serve all the users request through that.
Considering the fact that i can define multiple sessionfactories in the hibernate config file, which will make it static during application development, instead i would want to create the sessionfactories dynamically for the respective tenant database for which the user belongs by reading the information of the connection URL from the master database.
Also, there also will be a scenario where in i will have to maintain the sessionfactory of the master database and the tenant database as there will be a requirement where i will have to add users to both master database and tenant database during user creation.
Can any one help be address this requirement?
I would define two sessionfactory, one for the master db and one for the others dbs starting with fake values. this can help you on how to change the datasource at run time.
Finally threadlocal can help you to store data between calls.
Hope it helps.
I have an ASP.NET MVC 4 app. My database is hosted on Windows Azure. My solution has a new SQL Server Database project. I want to start off by adding adding the ASP.NET Membership functionality to this Database [project]. My question is, how do I do that?
I thought it would be a straight forward drag and drop operation. However, I cannot figure out how to do this basic task. All of the online videos I find demonstrate how to to implement the login via the ASP.NET MVC side. However, I don't see anything that shows setting up the Membership tables/sprocs/views and getting them in a SQL Server Database project.
Thank you for any insights.
You can get the script(s) necessary for adding membership to a database using aspnet_regsql in your framework folder (usually %windows%\Microsoft.NET\Framework\v4.0.30319\). An example usage for producing the .sql file would be:
...\v4.0.30319>aspnet_regsql -sqlexportonly MembershipScript.sql
From there, run that script against your database. You may also need to play with the -d <database> flag, but all options can be shown using aspnet_regsql -?. (This includes exporting the necessary tables for session state and other options).
I hope that's what you were asking but if I've misunderstood the question please clarify and I'll do my best to revise the answer
The template for creating an MVC 4 Internet application with forms-based authentication uses both the traditional ASP.NET Membership database with an additional layer on top called SimpleMembership, which has its own database. The SimpleMembership database uses Entity Framework code-first model which creates the database automatically the first time you start the application. Since SimpleMembership uses code-first the database schema can be modified by changing the UserProfile class in AcccountModels.cs. What is your objective for putting these databases that are handled by the application into a separate database project? Unless you are going to bypass SimpleMembership any solution will have to handle two databases.
We currently have a SQL Server 2008 instance set up for our ASP.Net MVC application, and the SQL Server instance uses built-in auditing (I believe CDC?)
We also have our ASP.Net application set up to use one connection string specified in web.config for the entire application, no matter who is logged in (of about ~50 users)
The problem: We want to be able to include among the audit information the username of the user who made the particular change in question.
It looks like we can only do that in one of two ways:
Change our application setup so that every single user gets their own database login. This would require us to use dynamic connection strings (perhaps not too terrible), but moreover it would be a pain in the ass to add a new user to the system and the admins could no longer do it automagically via the application's interface (I think).
Use another solution from within the ASP.Net app itself. This would allow us to trivially add any bit of information in the application we wish, but would involve scrapping the entire builtin solution and essentially starting from scratch with a significant effort.
Someone must have run into this problem before with auditing - is #1 feasible? Or is #2 the only way we can go here?
Thanks
Option #1 is pain for the admins, a little complicated code for "dynamic" connection strings, and calling sp_addlogin to create users. But the worst is that separate DB login for every user also allows them to query DB directly (if they know instance & database names, which could leak to them in any way and "see" DB server through the network). Direct access to the DB is something that may crash every application. Don't do it, unless you're very sure that DB server is not directly reachable to the users.
About #2. How about adding column "LastModifiedLogin" to every table, where you put login of logged in user during every insert/update? This shouldn't crash CDC and you got what you want. However auditing delete is little problematic, because you issue statement and have no longer row where you could place the login. You may organize seperate "DeleteAudit" table where you put name of table, row identifier and user login on every delete, but that's only rough idea.
If you use NHibernate for data access, I would advise you to consider switching CDC to NHibernate Envers, which is very neat solution.
Does anyone have a view on whether to use a new separate database for forms authentication users, or is it ok to mix it with your application database?
I could see separation being useful if multiple applications/databases were sharing user authentication, but in my case I have one website/database, and intended to just add the tables/views/sps created by aspnet_regsql.exe to my current application database.
Any views/opinions welcomed. Thank you.
You can mix that db with your database BUT you should not make any changes to the default database tables if you want to use asp.net built in classes that use that database , It means you can only add your tables to that database !
That is OK to have a single Database from which the Forms are to be authenticated. Since the SQL server is a very secure one there will be no problem in having a single database.
But If you want to setup Your custom database for Authentication then Refer the following Links
Using Forms Authentication with a customer database
forms authentication with sql server 2008 database questions
So I'm working on an ASP.NET project for university. We have to upload our code to a server running IIS and SQL Server 2008. I've written my project using MVC Code-First EF. I understand that the Entity Framework system needs permission to create the database to work properly (you can't just give it an empty database and let it fill it with data). This has created a problem for me since I do not have database creation privileges on the shared SQL Server. Is there any way around this?
As you don't have permissions, it sounds like you'd need to get a DBA to create your database on the server you are trying to deploy to - this could be done from either a database creation script or from a database backup of the db on your dev machine. You can then instruct EF code first not to try to create / update the database automatically by adding this line to your global.asax (or indeed anywhere before you first access the database)
Database.SetInitializer<YourContextType>(null);
You can use an existing database, rather than let EF create one for you. I have done this myself, but admittedly only when using EF Migrations. Otherwise, you run into trouble with missing table exceptions and what not.
When using migrations, just point your connection string to your empty database, create an initial migration to populate the database with your schema and then update the database itself.
See this answer: How do I create a migration for an existing database in EntityFramework 4.3?
.. which include this nice link to getting started with EF Migrations: http://thedatafarm.com/blog/data-access/using-ef-migrations-with-an-existing-database/
All this is available through Nuget, and if you have access to Pluralsight content, I can highly recommend Julie Lerman's video on the topic.
If you don't want to use Migrations, you can still use Code First if you just create the database objects manually using SMMS, but obviously you have the manual work of keeping your model and the database in sync.