Azure Membership account access issue - c#

I deployed my MVC application on the WindowsAzure staging environment. I used universal provider for membership. But i am little bit confused.
My confusion is that i created some accounts on my local machine now after deployment when i am trying to access those accounts in cloud, i got error message incorrect username or password but if i am accessing those accounts from my local machine, then there was no error message. I did`nt change the connection string. Can anybody please explain me the concept or give me some reference link ?

As you asked for concept on how it works, i can explain it. When you are using ASP.NET Universal Providers in your MVC app, there must a database where it can be configured. In most cases SQLExpress is the local database used by Universal Providers to store the membership details.
Now when you deploy your application to Windows Azure as Cloud Service there is no local database configured so your default configuration to Universal Providers will not work. The best way to solve this problem is to configure your MVC application universal providers to use SQL Database even when you are testing locally. Once local tests are completed and your deploy your application to Windows Azure, because your application is still pointing to SQL Database, it will work without any problem (considering you have configured SQL Database properly).
This particular article shows different connection strings used in MVC application to connect with SQLExpress or SQL Database so you can use it to modify your SQL DB.

You'll want to set an explicit <machineKey> in your web.config. That key is used for a number of things relating to sessions and membership (like cookies and passwords). If you don't specify the key explicitly, Windows Azure chooses one for you on each deployment, which will invalidate existing auth cookies and stored passwords.

Related

Azure Web App Not Showing Connectionstring in Kudu Env

We are trying to get connectionstring from Azure Web App to work with our ASP.net Website.
We have configured the connection string correctly in Azure Web App:
However, when we visit our Kudu environment page its showing a completely incorrect connection string, cannot figure out why its not showing our custom connection string.
Also - we are using a custom connection string because we have a special connector (Devart Mysql) that we need the provider name to remain correctly.
When we try to load our site we receive this:
I'm wondering if azure web app is overriding our provider and resetting it to a Sql Server provider instead of the Devart.MySql provider we need to use. Appreciate any help/guidance
UPDATE
Checking the web.config using kudu it appears that azure is automatically changing the provider name to System.Data.Entityclient - how can we prevent this from happening? I believe this is the root of the issue
Also - we are using a barebones project to test this with the bare minimum so we know that there aren't other factors in the project manipulating these values, pretty certain azure web app is making this change, just not sure how to fix it
For .NET apps like ASP.NET, these connection strings are injected into your .NET configuration connectionStrings settings at runtime, overriding existing entries where the key equals the linked database name.
These settings will also be available as environment variables at runtime, prefixed with the connection type. The environment variable prefixes are as follows:
SQL Server: SQLCONNSTR_
MySQL: MYSQLCONNSTR_
SQL Database: SQLAZURECONNSTR_
Custom: CUSTOMCONNSTR_
You retrieve the settings in your application using ConfigurationManager.ConnectionStrings["keyname"];.
So in web.config set the connectionString blank and will automatically use the connectionString of the application settings. For more details, you could refer to this tutorial.

Azure SQL authentication through AD service principal

I am having a windows client application connecting directly to a SQL server.
I am using SQL server authentication now, but I want to replace that for improved security. (I don't want to deploy the credentials together with the application)
I want to use Azure AD to provide access to the app (and forwarding the access token to the DB)
My desired setup would look like:
I have a Azure AD app registration (service principal).
- I assign permission to use the application individually --> Enterprise App --> User assignment required --> Yes
- I give permission to the app (service principal) on the SQL database.
- What I can do now is to access the DB as the logged in user (API permission Azure SQL Server --> user_impersonation), but that means, that I have to give access to all individual users directly on the DB.
I would like to access the DB as the application.
Is this possible, and if yes, how?
Now, I am able to use ADAL to connect as the service principal to the DB, but then I have to create a client secret for the service principal and deploy that together with the application --> not secure. Or I can use MSAL with user_delegation and access the DB as the logged-in user but that means that I have to give him direct access to the DB and he can access it in another way as just with the application (i.e. in MSSMS).
Looks like what you want to use is a managed identity.
There's a tutorial here: https://learn.microsoft.com/en-gb/azure/app-service/app-service-web-tutorial-connect-msi
I should warn you this managed identity feature is new-ish and you need to be careful what version of .Net framework your application is using. Some Azure App Service and other ressources are not yet updated to a .Net framework that supports managed identities (Last I know).

How can I deploy an app using Identity Model to Production on Azure?

I'm pretty new to MVC. I'd like to deploy the default sample web app to Azure with a basic Identity Model installed so that I can confirm basic user authentication is working in production. I can't seem to get it working.
I am using Visual Studio 2015 RC. I launch a new MVC web application project. IdentityModels.cs is installed by default. If I connect to LocalDB, it runs great. If I connect to an Azure SQL DB instead, it runs great. I am able to register and then log in with the credentials I've created. The database updates as expected either locally or on my Azure SQL instance.
The problem is when I deploy to production. I make no changes to the code whatsoever, and Publish via Web Deploy. When running the same code from an Azure website, I try to submit user info on the Registration page and I get a 500 error: Failed to load resource.
It seems that my Azure website cannot connect to the Azure SQL DB, even though I verified that it could connect just before I used Web Deploy. Can anyone help me figure out why?
You need to allow Windows Azure Services for your Azure DB through managing the allowed IP addresses, because your DB is initially inaccessible, except from an IP range that you specify.

How to handle session management on cloud hosting in asp.net webform based website

Let us say i have a website developed in asp.net webforms on .net 4.0 frame work and this needs to be migrated to cloud hosting like rackhosting.
This website currently uses asp.net default membership for user management and also uses several session variables for storing temporary variables.
This website is hosted on a dedicated server hosted inhouse.
so my question is
How to make it work on cloud hosting
One way of doing could be using MS Sql Server based session management
What else i need to take into consideration to make it work on cloud hosting
I have no experience with cloud hosting as one gets confused with the cloud hosting architecture provided by service providers. Microsoft Azure, Amazon etc..
any pointer to a good article and code examples would be great to start with
You will need to use a Session State Provider that will span the servers.
e.g. one that uses App Fabric (or other caching provider) or Sql Server
For sharing sessions you have 2 options:
1. Sticky sessions, easiest to implement because there are no changes to do in code, but you will not be able to autoscale (add or reduce the number of machines based on load). This will be just a setting on your load balancer, so you need to check if the load balancer of your cloud provider has this.
2. Out of proc session and here I suggest to use the ASP.NET Redis session provider (supported by Microsoft). Both AWS and Azure provide Redis as a servce, so it is easy to start with, you don't need to think of its administration. Most important out of proc will mean some code changes, at least marking your classes that go in session as Serilizable, but you will be able to autoscale.

How to create an azure web service and use existing sql database

I'm working on an exercise and i want a help. So far I have to created an MVC4 Internet Application using C# and uploaded it to azure as a web site (custom create with sql server). Now I want to create a web service to use the same database that my web application is using. How I can do it?
I found an option when you create a new project (C#->Cloud Project-> Windows Azure Cloud Service)
Note that then i want to use the web service with workflow based service
Thank you
Connections to SQL Azure are just Connection Strings. This isn't any different than creating applications on premises or hosting them elsewhere. Get the connection string of your existing Azure SQL Database and then use that when setting up your database calls in your web service project. You can get the connection string from the Windows Azure Management portal. Dig down to the database and there will be a Show Connection Strings option on the dashboard page for the database. See this documentation if you aren't familiar with working with connection strings Azure SQL: http://msdn.microsoft.com/en-us/library/windowsazure/ee336282.aspx
Note that Azure SQL Databases do not support integrated windows authentication, so the connection string will contain the username and password. You may want to look into securing that information in your configuration.

Categories