I have an MVC website and I need to pull out a couple of pieces of data from an Umbraco database. I don't need any of the Umbraco views or any of that stuff. I'm new to the Umbraco Core libraries.
What I did was create a reference to the Umbraco.core dll from my web project and added the connection string to the Umbraco database in my web config. I then added a method to attempt to retrieve some data
public IContentType GetBenefits() {
var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
var benefits = contentTypeService.GetContentType("Benefits");
return benefits;
}
ApplicationContext.Current is always null
I'm running on my local dev PC under IIS Express
Do I need to do anything else to instantiate the Umbraco connection?
ApplicationContext.Current will always be null in this case because ApplicationContext.Current refers to the current running instance of an Umbraco Application. In order to have a running instance you need a full Umbraco installation configured, bootstrapped and running.
I don't think you will be able to do this with Umbraco.Core alone and adding all those extra libraries for the sake of connecting to a database is overkill anyway.
If you need to access Umbraco specific database content then the best option is to Add an Umbraco Api Controller to the actual Umbraco instance and expose the data that you need with Web API.
At a push you could connect to the database directly but the database is well abstracted and normalized so, unless you need only very specific data from the database, this isn't going to be worth the effort.
Related
I built a MVC site with Identity that will be replacing an old site that uses Asp.Net 2.0 security. I used a local database to create all of my pages. I'm finally at a point that I want to use my hosting provider's SQL Server. I published my code and changed the connection string to point to the hosted SQL Server. Migrations are turned on and I even ran "Update-Database". However, I don't see tables like "AspNetRoles" or "AspNetUsers". I went ahead and changed the connection string on my local machine to point to the hosted SQL server to make it easier to test out. I tried logging in with one of the accounts I created previously and it said it couldn't be found. That's actually a good thing since it tells me that it's pointing to a new database. I went ahead and created a new user hoping it would auto create the database tables. The new user worked and I can log in with the account but I still can't see the tables when I look at it through SQL Studio Mgr. Yes, I did refresh the tables under SQL Server and still don't see them. Any suggestions on why I'm not seeing the Identity tables?
I have implemented Umbraco using UmbracoIdentity for membership and everything was going fine until I deployed my solution to an Azure Web App. On azure I am getting permission errors because UmbracoIdentity is using a SQL Server CE database stored in the App_Data folder.
For reference the error I am getting is:
Exception type: SqlCeException
There is a file sharing violation. A different process might be using the file. [ ...\wwwroot\App_Data\UmbracoIdentity.sdf ]
My Umbraco data is being stored in an SQL database and I would like to store my UmbracoIdentity membership data here as well. I would appreciate any help in how to setup SQL Server as the user store for membership data.
You need to implement the IExternalLoginStore.cs interface and then configure the application to use it. It should be fairly simple to implement as you can use the SQL Server CE implementation as an example. I've done one for Azure Table Storage - you can check the Readme at https://github.com/alindgren/UmbracoIdentity.AzureLoginStore to get an idea of how to configure the app to use a custom external login store (which for me was the least obvious part).
I am new to the MVC world, i am developing an mvc5 code first from database project which i want to to create securely connection between my local server with more than one sql servers, and each server can contains one or more databases.
so can someone clarify me these:
1. Creating SQL Server Connections[if possible in one entity framework]
2. Securing the Connections.
3. if possible how to access the database other then the initial catalog database
Note:
i found to use entity framework to data access , after creating connection then encrypt the connection string by command-line utility, Aspnet_regiis.exe
any other techniques rather than this.
Thanks
As far as securing connections go, all you've got is SSL. Make each SQL Server instance only available via SSL and your connection is as secure as it will ever be. Encrypting the connection string, using a limited access user, etc. are important, but aren't really aspects of securing the connection, merely security in general.
For multiple database access via Entity Framework, you just need multiple contexts. Each context belongs to one and only database, but you can have as many contexts as your want. The only thing to be somewhat mindful of is having multiple contexts that you run migrations against. While I believe EF has supported this since version 6, it's still not recommended. Generally, you should only have one context that you run migrations against (the entities that inherently belong to your application), while your other contexts will merely work with existing database created and managed outside of your application. Really, if you think you have a need for multiple migrate-able context in a single project, that's really an argument for splitting up your project into multiple projects.
So, for connecting to an existing database, you just need a regular old DbContext subclass, with a couple of tweaks: 1) you need to specify the connection to use manually and 2) you need to disable database initialization. Here's a skeleton of what that looks like:
public ExistingDatabaseContext : DbContext
{
public ExistingDatabaseContext()
: base("ConnectionStringName")
{
Database.SetInitializer<ExistingDatabaseContext>(null);
}
// DbSets here
}
I am planning to build an iOS app with using DB(Ms-Sql).
However, people recommends not to access DB from Xcode.
They recommend me to use php or asp for accessing db through a webpage.
I want to know the reason.
Also I am going to use DB only for (view) select line (not insert, update nor delete).
so is it possible to access directly to db for viewing purpose only?
thank you
It's generally bad for an application (mobile, web, any client) to directly have access to any database for security issues. Clients really should not be accessing the database, which is often holding very private/secure data. It opens up vulnerabilities (i.e., sql injection attack).
A set of web services written in php or java or some back-end technology is a more secure, scalable system. These web services can connect to the database and retrieve data. Your iOS application can call the web services and receive the data..for example in the form of XML or JSON.
so I'm developing a SAAS application using asp.net mvc SQL server 2008 and Linq2SQL I've a master db where I'll store information about clients like name subdomain/hostname information and other stuff and I'll use one database per client for the actual client data,
what is the best way to generate and use the connection string for each individual db the connection string will be based on each customer domain so I could hard code it into master db at customer creation and create the DataContext based on that? any flaws in this strategy?
I am also using forms authentication and it will be built into each clients own db so do I've add anything dynamically to the configuration? as currently the authentication/membership is driven by connection string inside the web.config file
You should probably have a table in a centralized master db that includes the database connection information for each client. Then in your SAAS application, any time you are instantiating the data context, instead of using the default parameterless constructor, use the constructor overload that takes the connection string you stored in the centralized database for that client. The context shouldn't be kept alive between requests, so you shouldn't have a problem with cross page requests across multiple clients.