MVC4 Membership Tables not created on production environment - asp.net-membership

I'm attempting to use the ASP.NET universal providers in my MVC4 application. Among other places, this article describes how, the first time you attempt to register a user, the tables should auto-create in my DB.
I had this working on my internal app/db, but I used the asp.net web configuration tool to create my first user. When I deployed this to production, I attempted to register a user and was hit with an error indicating dbo.Applications didn't exist, which is one of the tables that should have been created.
Any thoughts on why these tables weren't created? I've made sure the System.Web.Providers dll was copied to the bin folder. I'm also sure my app can manage CRUD tasks on my database.

argh duh. Turns out I didn't have create perms set up for the app pool identity that was making the call. Hangs head in shame

Related

Auto logout after Docker deployment in ASP.NET Core MVC Identity

I'm using ASP.NET Identity for Authentication and Authorization. Since I use docker on the recommended way (separate container for building and running), I got always logged out after each deployment. Seems like ASP.NET Core doesn't store the sessions in the database. Also cause I can't see any table where they are.
How can I fix this so that my users don't get logged out after each deployment?
I think I need to store the sessions in the database. But I couldn't find information how to do this. I found information about using Redis as session store. This comes near - I'm not sure, if this also affect the ASP.NET Identity session, or only the session stores like TempData. And the other problem is, that I would like to store the session in my MySQL database using Pomelo.EntityFrameworkCore.MySql provider.
Found out that using memory storage causes issues with the encryption keys, too. In Short, ASP.NET Core use those keys to protect sensitive data like sessions. So they're not stored in plain text. Seems like that ASP.NET generate those keys automatically on the first application run.
Cause it runs in a Docker container, this will result in two big problems:
The encription key get lost by rebuilding the container image. ASP.NET Core generated a new one automatically, but can't decrypt the existing sessions cause they were encrypted using an different key
A container is isolated, so the default memory storage provider for sessions would lost its data after every new deployment
This could be solved by using a storage which is running on a different server than the webserver, as I suggested. I couldn't find any MySQL implementation for this. Only SQL server, which seems to be MSSQL. I fixed it by installing a Redis server. Its used for session storage and the encryption keys.
To let ASP.NET Core storage encryption keys in Redis, install the Microsoft.AspNetCore.DataProtection.Redis provider and append the following lines to ConfigureServices before AddOptions
var redis = ConnectionMultiplexer.Connect($"{redisIpAddress}:{redisPort}");
services.AddDataProtection().PersistKeysToRedis(redis, "DataProtection-Keys");
Note, that this is only part of ASP.NET Core since the 1.1.0 release. Cause it has dependencies on other packages of the 1.1.0 branch, I'd assume that its not working on the LTS 1.0 release. In this case, you may need to write a custom implementation which is 1.0 compatible. But I haven't tested this, since I'm using 1.1.0 in my project. More infos in this article: http://www.tugberkugurlu.com/archive/asp-net-core-authentication-in-a-load-balanced-environment-with-haproxy-and-redis
In summary, I don't think its a bad idea to use Redis for this instead of a SQL database, cause Redis is optimized for serving key-value pairs very fast. And the base is there to use Redis for caching other parts of the application like (complex) database queries. This can speed up your application and reduce load of the database server.

Spring MVC objects storage in application

I have a Spring MVC application.
For example I have a simple JSP page that displays list of Contact objects.
User can add, remove objects. The question is about the way of Contact objects storage. I cannot (by some reasons) use database. How can I anyway store list of objects globally for application?
According to this
it must be stored across whole application lifec-cycle. After I
restart server it the list should not be lost
you can use H2 or HSQLDB database and keep it content into single file, located in configurable path. Anyway, to keep some persisted data, you should use local file or remote storage, so, i think, it would simplify solution if you use such kind of database.

Application unable to connect to database on AppHarbor

I have this application which I am developing for learning purpose. I have hosted the application on AppHarbor.
It is ASP.NET MVC and EF Code First.
I added the SQL server free add on for db purpose but come what may the db connectivity is failing.
Code is hosted on Github here :- https://github.com/BilalHasanKhan/BusinessFlow
Please advise or point where I am wrong.
By switching custom error off I found the error:
Model compatibility cannot be checked because the database does not
contain model metadata. Ensure that IncludeMetadataConvention has been
added to the DbModelBuilder conventions.
You might want to check the blog post we recently did on migrations with EF Code First. There's also example code to along with the post.

C# MVC3 - New Membership Providers (System.Web.Providers) and old Membership classes (System.Web.Security)

I got my app running very well when I was testing locally, with Membership providers and Database. My nightmare began when I tried to run it in Windows Azure plataform.
Since then, I read a lot of articles about running aspnet_regsql in Sql Azure, and the new universal Membership providers. But I can't realize how to use the new Providers, and I'm getting really confused about System.Web.Providers and System.Web.Security classes and methods. When I tried to create a new user with the new Providers, the creation failed with a Null Exception, even if I had all the parameters placed and the build was ok.
My project is totally ready, I just need to upload it to the host.
How could I make it run in Windows Azure easily? Or should I learn how to use the new universal Providers and adjust all my project to that?
It appears that System.Web.Providers is required to run your application on Azure, at least without any heavy code lifting. Scott Hanselman outlines the basics of installing and using System.Web.Providers in his recent blog post: Introducing System.Web.Providers - ASP.NET Universal Providers for Session, Membership, Roles and User Profile on SQL Compact and SQL Azure.
Another resource that may be helpful is Wade Wegner's post Deploying the Windows Azure ASP.NET MVC 3 Web Role.
In short, after installing System.Web.Providers in your project using NuGet, it will reconfigure your web.config to include two connections strings, one for ApplicationServices, and another for the DefaultConnection. You will need to updated these with your Azure connection string, but make sure you append "MultipleActiveResultSets=True;" to both connection strings.

Is it possbile to change the webpages_Membership, roles etc table names from a simple template created with web matrix?

I've created a Web Matrix web site from the starter template which creates a database with the a few tables for the login details. Most of these are names webpages_Membership, webpages_Roles etc. The hosting company I use only gives me one database and I want to have more than one site on the server. I want to prefix the table name with something to make it unique, but it looks like the web matrix framework will only work with the set table name. Does anyone know if this is possible?
If you use SQL Server Compact Edition, you can have as many databases as you like in your App_Data folder. Certainly something to consider if your sites aren't likely to be hugely busy. Otherwise you can develop your own Provider inheriting from ExtendedMembershipProvider and make it "site-aware". Dig around in the WebMatrix.Data source code for more details (available as part of the MVC source download).

Resources