I created an asp.net site using VS 2008. I was using a db in app_data for membership. I am moving this to a new server and the db will be attached to a sql server 2008 R2 instance. I wanted to change the db name so it would fit in better with the rest of the server. Since I changed the name from ASPNETDB.mdf to Reporting.MDF I cannot login and ASP.NET says I have no users. I used the rename function in VS and updated my connectionstring.
<connectionStrings>
<add name="MembershipConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Reporting.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<!--added to create new membership to connect to-->
<roleManager enabled="true">
<providers>
<clear/>
<add connectionStringName="MembershipConnectionString" applicationName="WebSite2" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken="/>
</providers>
</roleManager>
<membership defaultProvider="SqlMembershipProvider">
<providers>
<clear/>
<add connectionStringName="MembershipConnectionString" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="WebSite2"
requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10" passwordStrengthRegularExpression=""
name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" />
</providers>
</membership>
Users: 0
Provider: Test to check db works fine.
edit: I removed the publicKey in case it is tied to me in some way.
edit: I changed the name back to aspnetdb and it still does not work.
If i delete the membership code it works again. This is after changing the name back to aspnetdb. I am back where I started.
If you have this problem again it's likely caused by forgetting to properly set the applicationName attribute in web.config. Here's a great, detailed explanation of the common problem. If you compare the web.config file from your question to your web.config in your answer, you'll see that the applicationName attributes in the two files have different values; WebSite2 versus /.
I fixed this by opening machine.config and copying all of the membership details. Then used
clear
in every section.
<connectionStrings>
<add name="LocalSqlServer2" connectionString="Data Source=Johnny;Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<!--added to create new membership to connect to-->
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=" connectionStringName="LocalSqlServer2" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer2" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken="/>
</providers>
</profile>
<roleManager>
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer2" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken="/>
<add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken="/>
</providers>
</roleManager>
Try attaching the aspnetdb database first. Then rename it using Sql Management Studio.
Related
I'm trying to implement membership with oracle. I have created the database perfectly, but I can not access from my App. The database is on a dadicated server, and the error that its shows me is "OracleConnection.ConnectionString is invalid" but I know that is correct.
I have used this connection with ADO.NET and I works perfectly.
Can I use a remote server to implement membership? because this is the only explinantion that I could find...
This is my connectionstring.
Thanks in advance!
I found the solution in this post:
Setting up the default AspNetSqlProvider to point to remote database
So my web.config looks like:
<connectionStrings>
<add name="ApplicationServices" connectionString="DATA SOURCE=(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=EUBEWD92Z1.jnj.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE))); user id=user; password=pass;" providerName="Oracle.DataAccess.Client"/>
</connectionStrings>
<membership>
<providers>
<remove name="OracleMembershipProvider"/>
<add name="OracleMembershipProvider"
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""/>
</providers>
</membership>
Hmmmm... I really can't get my head around this.
In web.config I have:
<connectionStrings>
<clear /> <!--- need this to prevent using LocalSqlServer from machine.config or somewhere becouse it is not present when when publish to hosting -->
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-Goaly-20120615111028;Integrated Security=SSPI" />
</connectionStrings>
and
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<!-- I think this line is telling asp.net that I want the membership working agains defaultconnection, and not LocalSqlServer connection????? -->
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
But then it is complaining:
The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
When I use the publish from VS2012 RC in the settings tab I get a ModelContext and a DefaultConnection, so how is this supposed to work?
What I want is simply to get the membership tables in the same database as the tables created by modelcontext.
This should be so oob, but I must have overcomplicated it some how.
Thanks for any help.
Regards
Larsi
The default settings for all web sites on a windows machines inherit the settings of 2 configuration files: machine.config and web.config, which can be found in the directory Windows/Microsoft.NET/Framework(or Framework64 for 64 bit)/version/config.
Here is a snippet from the default version of machine.config:
<system.web>
<processModel autoConfig="true"/>
<httpHandlers/>
<membership>
<providers>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
</providers>
</membership>
<profile>
<providers>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</profile>
<roleManager>
<providers>
<add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</roleManager>
</system.web>
So the answer to your question is: it is machine.config that establishes the dependency to the LocalSqlServer connection. When you add the <clear/> tag as the other answers to this question suggest, you are removing the reference to the membership provider named AspNetSqlMembershipProvier, and with it the reference to LocalSqlServer.
It is mentioned in the follwing post forumsasp
that adding </clear> tag before your connection string in the membership element and rolemangaer element ( if present in your web.config) will solves the issue.
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<clear/> <!-- solves the issue -->
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
also you can use SqlMetal.exe to add membership tables to your existing database.
There is allready a membershipprovider registered (in one of the root configuration files) before your configuration file is loaded. That membershippprovider points to LocalSqlServer.
You'll need to remove the first membershipprovider, and this can be done by clearing all providers before you add one, just as you are doing with your connectionstrings.
In the <system.web> configuration section, inside the membership/providers section, add a <clear> element before the <add> element(s).
I'm trying to allow users to login with either forms authentication or their AD account but having some problems. I'm logged into an AD accountno,w but Page.User.Identity.Name is blank. I have this in my web.config:
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://full.domain.address:389/DC=mydomain,DC=blah,DC=uk"/>
<add name="myapp" connectionString="Data Source=myserver;Initial Catalog=myapp;User ID=myapp;Password=myapp" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="129600" name="CookieMonster" protection="All" slidingExpiration="true" cookieless="UseCookies"/>
</authentication>
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"
connectionStringName="myapp" enablePasswordRetrieval="false" enablePasswordReset="true"
requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10" applicationName="/"/>
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="myapp" applicationName="/"/>
</providers>
</profile>
Do I need to do something else to get this to work? I've tried logging in with my domain account and domain\myaccount to no avail.
When I try var u = Membership.GetUser("mydomain\\myuser"); I get an error: Usernames must not contain '\' when mapped to 'userPrincipalName'.
AD userPrincipalName might be something like user#full.domain.address. Try using the sAMAccountName value for the attributeMapUsername:
<add name="ADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
attributeMapUsername="sAMAccountName"/>
If you are unable to connect, you may need to add connectionUsername and connectionUserPassword attributes (check the MSDN documentation).
"sAMAccountName" does not include the domain. To resolve your problem, simply remove the domain qualifying form your username:
Instead of var u = Membership.GetUser("mydomain\\myuser");
use var u = Membership.GetUser("myuser");
This is because you specified the domain in the connection string, implicitly by connecting to a particular active directory.
I have an ASP.NET MVC 1 web application using the ASP.NET Membership provider. On my local box, when I submit data to a form, the redirect takes it to the proper location (with Controller.RedirectToRoute). On the server where it is supposed to live, form submitting takes me back to the login page. The data posts properly, but I'm just redirected incorrectly.
I recall dealing with this a few years ago (in a non-MVC application) and it was due to a problem with the Web.Config relative to the Membership provider.
I can't imagine I'm the only one that's had this problem. What should I be looking for in my web.config that could be related to this?
Thanks ahead of time.
EDIT
Here is my authentication and membership portion of the web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="IPS" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="IPS" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="ApplicationServices" applicationName="IPS" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add applicationName="IPS" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
MVC 1 uses Forms auth by default. You may want to check your forms auth settings to make sure that you aren't being redirected as part of security.
If you using the MySQL like a user data storage, such problem can happened because of different MySQL Connector version on our local pc and server
In my test enviroment I created a Login and used the ASP.NET Configuration in Visual Studio. It worked perfectly.
But now after testing I imported an existing database to my sql-server and this database includes existing asp.net login tables(same structure). In my web-application I want to use these imported tables instead of those in my testing database. I already checked the web.config as well as the aspnetreg tool (don't know the exact name :p)
My question: How can I change the database used by my ASP.NET login?
you have to overwrite the default application services connection string to have it use your existing deployed DB
in the web.config connection string section change the default connection string
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
to be whatever your connection string is
or if you want to use a different connection string you can change the name of the connection string used in the membership provider settings also in web.config
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/"/>
</providers>
</membership>
Change the name of the connectionStringName to something else
EDIT Role provider code
<roleManager enabled="true">
<providers>
<clear/>
<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</roleManager>
Again you will want to change connectionStringName to your connection string.