Login failed for user in MVC application - sql

Hello I am trying to make a user authentication page, I added to my web.config something like this:
<authentication mode="Forms">
<forms loginUrl="~/User/Login" timeout="2880">
</forms>
</authentication>
<membership defaultProvider="SimpleMembershipProvider">
<providers>
<clear />
<add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership>
<roleManager enabled="true" />
I connect to database with sqlauthentication mode like you can see in Server Explorer but when I try to start the application I get an error.
Here is my connection string to:
<add name="DefaultConnection" connectionString="Data Source=db-mssql;Initial Catalog=inzS9776;Persist Security Info=True;" providerName="System.Data.SqlClient" />

Related

AllowAnonymous for elmah

when I go to https://site/elmah it will redirect me to the login page, i do not want this, Anonymous user also may go here. (but only on this server and not remote! )
details
Its a MVC 4 website with formsauthentication. I added a filter so i do not have to put [Authorize] on my controllers
filters.Add(new AuthorizeAttribute());
web.config
<appSettings>
<add key="elmah.mvc.disableHandler" value="false"/>
<add key="elmah.mvc.disableHandleErrorFilter" value="false"/>
<add key="elmah.mvc.requiresAuthentication" value="false"/>
<add key="elmah.mvc.IgnoreDefaultRoute" value="false"/>
<add key="elmah.mvc.allowedRoles" value="?"/>
<add key="elmah.mvc.allowedUsers" value="?"/>
<add key="elmah.mvc.route" value="elmah"/>
<add key="elmah.mvc.UserAuthCaseSensitive" value="true"/>
</appSettings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="5"/>
</authentication>
....
</system.web>

Integrate open source mvc forum 1.5 with asp.net identity table?

Mvc forum 1.5 use membership table but my application create mvc 5+Entity framework 6 + asp.net identity table.how to integrated mvc forum with my application.
Hi Mahaveer,
You will have to do following changes in connection string and system.web:
The UserManagement_Connection is basically a connection string
<add name="UserManagement_Connection" connectionString="Data Source=.\SQLExpress;Initial Catalog=ASPNETDB;Integrated Security=false;User Id=userId;Password=pwd" providerName="System.Data.SqlClient" />
<system.web>
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="UserManagement_Connection" applicationName="myapplication" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="RoleProvider">
<providers>
<add connectionStringName="UserManagement_Connection" applicationName="myapplication" name="RoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
Then directly you can use the Membership functions in your application
Let me know if you face any issue.
:)

Cannot add authentication on app with connection string error

I am trying to add authentication to my application using the built in provider however I am getting an error doing so. My web.config file is as follows (with the db etc taken out of connection string but does all work):
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="LaundryDBContext"
connectionString=".amazonaws.com,1433;
Initial Catalog=Main;
Persist Security Info=True;
User ID=****;
Password=****;
MultipleActiveResultSets=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
When trying to add authentication I am getting the following error:
The connection name 'ApplicationServices' was not found in the applications configuration or the connection string is empty.
I would love the authentication and application settings to be stored in the existing DB. how do I fix this?
The connectionStringName property of the provider entries are set to "ApplicationServices" which is not a named connection string in your web.config. Your connection string is named "LaundryDBContext".
Change the connnectionStringName property to "LaundryDBContext" and the provider will use that connection string to talk to your database.
You should read one of the many walkthroughs on configuring membership to understand how that works in more detail.
In brief...
open the visual studio command prompt and type aspnet_regsql
Follow the wizard in the dialog that opens to add the aspnet membership schema to your database.

How to connect my webrole app (vb.net) to my sql azure database?

I am creating a new application (webrole) in webforms called SGS. This application is being build using vb.net.
I am developing the app in windows 7 and have already deployed it to Windows azure.
Every time I need to change something in the application, I change it locally and then publish it again to my production enviroment (i know about staging enviroment in azure, but I prefered the production).
The app is in the start point, now I need to connect it to my database that is in SQL Azure.
I built a new database named SGS that is on SQL Azure and I want to connect my application to it.
I would like that even when I am in the local environment, my application only connects to my sql zure database. This way I don't need any database on my local Pc.
I don't know how to accomplish this.....
The connection string (ado.net) that is on the azure is :
Server=tcp:mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr#mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;
My webconfig file as this information:
<xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<connectionStrings>
Server=tcp:mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr#mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<!-- <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial
Catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />-->
<add name="DefaultConnection" connectionString=" <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="aspnet_1db0ca8ec36d4ba1852e5e4ec9947660Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=aspnet_1db0ca8ec36d4ba1852e5e4ec9947660;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
<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>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<roleManager enabled="false" defaultProvider="DefaultRoleProvider">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</sessionState>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
What do I need to change to accomplish this?
Thank you very much.
This set up should do exactly what you want. It's only slightly more complex if you wanted to connect to SQL Server when running locally BUT SQL Azure when deployed.
To connect to SQL Azure from your local machine though, you'll need to have a firewall rule that allows traffic to reach SQL Azure. Ironically, the post right below yours in Stack Overflow has a response that should help you do this (if you haven't already).
If you set up the firewall rule and are still having issues, post back with more specifics about what's not working, error messages, etc.
Change the Service and Default connection strings to the connection string you received from the Azure SQL portal.
So you will get this:
<add name="ApplicationServices" connectionString="mwjw08qhju.database.windows.net,1433;Database=SGS;User ID=pr#mwjw08qhju;Password=myPassword;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient" />
Hope that helps

Problem Deploying new application

Im new to this, so please forgive me. What im doing is deploying my application onto the server, it works fine on my local machine but im getting errors when I try to hit the server. Here is the error below and my web.config file. I dont know what im doing wrong.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 18: <add assembly="System.Design, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=B03F5F7F11D50A3A"/>
Line 19: <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
Line 20: <authentication mode="Forms">
Line 21: <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
Line 22: </authentication>
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data
source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User
Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<customErrors mode="Off"></customErrors>
<compilation debug="true" strict="false" explicit="true"
targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Extensions.Design,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="ApplicationServices" applicationName="/"/>
<add name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I seem to recall this happening when you have deployed your application into a sub-folder of an existing site, and it it's web.config includes a setting that either applies to the entire site/application, and can't be modified on a per-folder basis
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level
I'd play with your
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
setting. Try moving it to the site's root web.config and see where that gets you, or remove it entirely.
Also, see (just from a quick Google)
Error: allowDefinition='MachineToApplication' beyond application level
http://geekswithblogs.net/ranganh/archive/2005/04/25/37609.aspx
ASP.NET IIS Web.config [Internal Server Error]
http://forums.asp.net/t/1031775.aspx/1