Login failed for user Test_web'. code first - code-first

heelo this is my connection string
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True" providerName="System.Data.SqlClient;Password=;User ID=;"/>
</connectionStrings>
<appSettings>
and this is my error please help me
Cannot open database "DataLayer.Context.test" requested by the login. The login failed.
Login failed for user 'test\test_web'.

You have specified the "DefaultConnection" as name of the connection string here. so your context class should have the same name. (it's the default convention in ef code-first)

Related

ASP.NET Core 3.1 - "site can’t provide a secure connection" when setting application url using .UseUrls()

I'm running the app using "dotnet run". If I don't set the url programmatically using .UseUrls() then it picks it up from launchSettings.json and all good. However if I set THE SAME url using .UseUrls() I get the message below on the brower.
There are no errors from the code i.e. both cases report " Now listening on: http://localhost:6001". Any ideas?
Remove Strict-Transport-Security from your Web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security"
value="max-age=16070400; includeSubDomains" />
</customHeaders>
</httpProtocol>
</system.webServer>
My mistake - launchSettings.json was using https://localhost:6001 and the code was using http://localhost:6001. Doh!

How do I hook into IDP initiated single logout to run custom code?

I'm using sustainsys.saml2.httpmodule. I would like to run some code to log the logout from an IDP initiated single log out. The user also does not seem to be logged out (IsAuthenticated is still true) after an IDP initiated single log out even though https://stubidp.sustainsys.com/Logout gives me a success result.
I can't seem to find anyone else needing the same functionality or having the same issues. My Sustainsys config is below.
<sustainsys.saml2 entityId="http://localhost:53758/Saml2"
returnUrl="http://localhost:53758/Common/Pages/Saml2Login.aspx"
authenticateRequestSigningBehavior="IfIdpWantAuthnRequestsSigned"
validateCertificates="false"
publicOrigin ="http://localhost:53758/">
<nameIdPolicy allowCreate="false" format="Unspecified"/>
<metadata cacheDuration="PT1440M" wantAssertionsSigned="true">
<organization name="ab" displayName="ab" url="https://www.example.com/" language="en" />
<contactPerson type="Technical" email="a#b.com" />
<requestedAttributes>
<add friendlyName ="Some Name" name="urn:someName" nameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" isRequired="true" />
</requestedAttributes>
</metadata>
<identityProviders>
<add entityId="https://stubidp.sustainsys.com/Metadata"
signOnUrl="https://stubidp.sustainsys.com"
logoutUrl="https://stubidp.sustainsys.com/Logout"
allowUnsolicitedAuthnResponse="true"
binding="HttpRedirect"
wantAuthnRequestsSigned="true">
<signingCertificate storeName="CertificateAuthority" storeLocation="CurrentUser"
findValue="cdf7090a433561a843b51198b0ba6456" x509FindType="FindBySerialNumber" />
</add>
</identityProviders>
<serviceCertificates>
<add storeName="CertificateAuthority" storeLocation="CurrentUser" findValue="2cfe21cb930c19a341e9e30a07a3c123" x509FindType="FindBySerialNumber" />
</serviceCertificates>
</sustainsys.saml2>
You can use the LogoutCommandResultCreated notification. It will get called both when the redirect to the Idp is about to happen as well as after the response has been received from the Idp.

Connect to remote sql server via alias

My connection string is working when I am connecting via IP adresss
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=ALIAS_SERVERNAME;Initial Catalog=DATABASE_NAME;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="DefaultContainer" connectionString="metadata=res://*/Models.Db.ModelName.csdl|res://*/Models.Db.ModelName.ssdl|res://*/Models.Db.ModelDb.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.0.61;initial catalog=DATABASE_NAME;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I have created Alias on remote server, like I did it localy (same ports and names) ,but it doesnt working. And when I put IP addres in connection string, like the one I have posted it is working.
Can someone pleas give me some instructions on how to troubleshot problem.
Error I am getting when I try to connect via Alias, and via IP it is working. Btw can connect localy via Alias.
(EntityException): The underlying provider failed on Open.
So, your DB server is aware of its alias name, but your application server is not. You have to create alias on application server.
You can do that with
cliconfg.exe
(Start > Run > cliconfg > Click "OK")
And than set your protocol, and port same as on DB server
You might need to add SQL Server name i.e. SQLEXPRESS, etc. at the end of your alias as shown below:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=ALIAS_SERVERNAME\SQLEXPRESS;
Initial Catalog=DATABASE_NAME;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
If you do not use default name for MSSQL Server then you need to change with what you used as name of it. You can check it on the Server Name field of the Connect dialog of SQL Server Management Studio as shown below.
Update: Here is the DataLink properties dialog shown below:
If it does not solved the problem, have a look at The underlying provider failed on open. Hope this helps...

NWebsec's "A potentially dangerous redirect was detected" with Facebook logon

I have read through NWebSec's documentation to try and resolve the problem.
Set the web.config to
<nwebsec>
<httpHeaderSecurityModule
xsi:noNamespaceSchemaLocation="NWebsecConfig/HttpHeaderSecurityModuleConfig.xsd"
xmlns="http://nwebsec.com/HttpHeaderSecurityModuleConfig.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<redirectValidation enabled="false">
<allowSameHostRedirectsToHttps enabled="false"/>
<add allowedDestination="https://www.facebook.com/"/>
<add allowedDestination="http://www.nwebsec.com/"/>
<add allowedDestination="https://www.google.com/accounts/"/>
</redirectValidation>
<securityHttpHeaders>
<strict-Transport-Security max-age="365" includeSubdomains="true" httpsOnly="false" preload="true" />
</securityHttpHeaders>
</httpHeaderSecurityModule>
but I am still getting
A potentially dangerous redirect was detected. Add the destination to the whitelist in configuration if the redirect was intended. Offending redirect: https://www.facebook.com/dialog/oauth?response_type=code&
This came up in google before the answer, which is here: https://docs.nwebsec.com/en/latest/nwebsec/Redirect-validation.html
In summary you have to whitelist the URL which your login service refers to, like this:
app.UseRedirectValidation(opts =>
{
opts.AllowedDestinations( "https://www.facebook.com/dialog/oauth");
opts.AllowedDestinations("https://login.microsoftonline.com"); // Tested
});

Unable to connect to ADAM with Windows domain\username

I'm having some difficulty connecting to an ADAM instance from my Commerce Server 2007 ASP .NET solution, and I believe it relates to my config file somehow. The short version is that I can connect to ADAM through ADAM-ADSIEdit with my current username/password, but when I put this in my web.config i get "Parser Error Message: Logon failure: unknown user name or bad password."
<connectionStrings>
<add name="LDAPConnection" connectionString="LDAP://<domain/>:389/<Partition DN>" />
</connectionStrings>
<membership defaultProvider="MembershipADAMProvider">
<providers>
<add name="MembershipADAMProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="LDAPConnection"
connectionProtection="None"
connectionUsername="<domain>\<username>"
connectionPassword="<password>"/>
</providers>
</membership>
I've tried a bunch of things to fix this and haven't come up with any kind of reasonable solution. I started with just the connection String and no username or password. I got an error saying that I could not make a secure connection. that's when I added the connectionProtection="None" line. Then it said I could not use default credentials without a secure connection, so I added the Username and Password fields. When I created the ADAM instance, I used the current Windows login credentials. I've tried to use my windows login credentials here in web.config, and I've tried with various domain names, pretty much anything I could think of. I'm totally lost why I cant bind with ldp and I can connect in ASIEdit with these domain\username and password but can't from my CommerceServer ASP .NET application...Is there some other step I'm missing?
Thanks,
John
You should follow the information here, there is a lot of good stuff about secure connections and how to disable them within your ADAM instance for development purposes.