ASP PasswordRecovery Email Failure, DateTime precision - asp.net

I have an asp.net 4.0 website and I'm using the PasswordRecovery control for a forgot password form. When I run the site locally it works fine, emails are sent. However, when I run the site from my vps, I get an error message when trying to send the email. There's nothing in the server's event log.
My PasswordRecovery aspx code is as follows:
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server"
CssClass="mediumText">
<MailDefinition From="noreply#x.com" BodyFileName="~/EmailTemplates/PasswordRecovery.txt" />
My web.config mail settings are as follows:
<system.net>
<mailSettings>
<smtp from="noreply#x.com">
<network host="smtp.123-reg.co.uk" password="x" userName="x" />
</smtp>
</mailSettings>
</system.net>
I've now run SQL Profiler against the SQL Server Express Instance, and it turns out that an exception is being thrown from the SQL Server on the call to dbo.aspnet_Membership_GetUserByName. There's a type conversion issue because PasswordRecovery is passing a DateTime parameter with 7 decimal places for the seconds. If I manually execute the stored procedure with 3 decimal place,s then it works. Does anyone know why the precision of the DateTime parameter is different on my server than on my laptop?

As you will see from reading this issue and the subsequent responses, the DateTime precision issue you are seeing is just a result of SQL Profiler displaying the date with the wrong format. That issue is unrelated to what is preventing your email from being sent.
What is the error message you receive when you try to send the email? The issue is more than likely related to something preventing your email from making it to the SMTP server. Are you sending to the same SMTP using the same credentials from your machine?

I think it is some connectivity issue from your VPS to SMTP server.
You can test this outside of your code by trying to connect to SMTP server using telnet.
Follow the steps mentioned in the link below to
http://support.microsoft.com/kb/323350

The datetime conversion error is a red herring. That is only occuring when you copy it from the profiler and execute it in management studio. This is a known issue.
You might want to read this:
http://forums.asp.net/t/1398826.aspx/1
Sounds like it might simply be that the membership provider settings are different with regards to the passwords.
There are two possibilities that I see.
You don't have a machineKey defined in your web.config AND your local and VPS instance are both pointing to the same database. If this is true, put a machineKey in your config and regen your passwords.
Your membership provider config on the VPS used to be configured for hashed passwords and somewhere along the way was changed to encrypted passwords. (or vice versa). This would also cause issues.

Related

asp.net pages work, but classic asp gives access denied error

I am setting up an existing application on a new server. It is a mix of Asp.Net and Classic Asp pages. The asp.net pages work perfectly, but the classic asp pages give the following error:
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or
access denied.
My Settings:
Windows Server 2008 x64
IIS7
SQL 2008 Express with Advanced Services
32bit application
Here are some things I've tried:
Set IIS7 AppPool to enable 32-bit applications
Enabled "Active Server Pages" extension in IIS "ISAPI and CGI Restrictions"
Installed Frontpage 2002 Extensions for IIS7 (from RTR)
Enabled Named Pipes protocol in SQL Config Mgr
My Connection String:
connectionString="Data Source=(local);Initial Catalog=System;Persist Security Info=True;User ID=System;Password=mypassword" providerName="System.Data.SqlClient"
My CLICONFG Alias:
Server Alias = System
Network Library = Named Pipes
Connection Parameters = (local)
I've successfully installed the program in this environment before without any issues. Both *.asp and asp.net are using the same connection string, so I can't see how that is a problem. The User "System" specified in the Connection String is setup as a user in SQL with all permissions granted.
Please help!! I've spent over 3 days on this.
Thanks!
I'm not so sure that classic asp understands all the parameters in your connection string. It likely ignores something it doesn't understand but the on that I think it's having the greatest trouble with is this one:
Data Source=(local)
and possibly
providerName="System.Data.SqlClient"
I would try either:
Creating a second connection string and use one for classic ASP and the other for aspx. Use this 'simple' format for classic asp:
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
Change the Data Source parameter to use the actual server or instance name.
System.Data.SqlClient is a data provider for asp.net, it wouldn't work with classic asp.
Here's an example of a Classic ASP connection string for SQL Server
Provider=sqloledb;Data Source=yourServerAddress;Initial Catalog=yourDataBase;User Id=yourUserid;Password=yourPwd;
For more examples see here - look at oledb providers.
http://www.connectionstrings.com/sql-server/
Also, where are you putting your connection string? If it's in web.config then .net will be able to read it but Classic ASP won't. It needs to go in the page which wants to connect itself, in an include or in global.asa
Edit - one extra point. If you're using SQL Server Express then you need to specify this - eg:
Data Source=localhost\SQLEXPRESS
Shawnda, John and Evan make good suggestions and points.
I'll share my active live server configurations with you so you have something to test on your server. That's if you're running MSSQL on IIS 7.x and Windows 2008 Server with any flavor of SQL Server 2008.
I run 2 servers mixed .Net and ASP one Web 2008 and 2008 R2 with IIS .Net sites with ASP using a common db all sites mixed work just fine.
First tip, make your connection string a Call Function or Sub.
From what you said you have to find all the locations you have your connection string.
How we migrate will help you.
Create your function and place it into your SQL Included pages or your master scripts page that is included in all pages that need your connection string.
Function ConnOpen(SqlConn)
Dim strConnSql
Set SqlConn = Server.CreateObject("ADODB.Connection")
strConnSql = "Provider=SQLNCLI10;Server=SERVERNAME\SQLEXPRESS;Database=DBNAME;UID=USER;PWD=PASSWORD;"
SqlConn.Open strConnSql
End Function
Function ConnClose(SqlConn)
SqlConn.Close
Set SqlConn = Nothing
End Function
Follow what has been suggested and change the string.
This is how I migrate sites from databases.
I will add a new connection string as a function and test it on one of my pages.
If the new connection works I'll do a search and replace of the string.
Once you figure out which connection string works you're going to stop spending time like 3 days.
The string above is active on my .Net sites in my inc_sqlpage.asp which is included in all pages that require database connection.
You should find all your connection strings and remove and replace them with a easier to manage function.
Call ConnOpen(MyConn)
... 'your SQL
Call ConnClose(MyConn)
If after this method you still can't connect then I'll say it's your server naming or firewall if this is a new server.
Example: I do not use IP address connections only internal DNS machine names. If i changed the servername to IP I would see the same type of error.
I'm sure you have tried different settings but try the one above switching IP with Machine Name, .\ and localhost but not (local).
I found the solution!!!
Thanks everyone for your assistance. I finally found the solution!
Turns out the connection string for my classic asp pages were expecting SQL to be installed with the default instance....but I had done a named instance. The connection string had "Data Source = System" (System was an alias setup on the computer that only specified (local) as the connection....it did not specify the instance name.).
I changed the connection string to "Data Source = .\SQLEXPRESS" and it worked fine.
The connection string that was in there would have worked fine if I had selected "Default Instance" during the installation....as had been done on other servers I had installed.
Thanks again!

Unable to connect using sql authentication through an asp.net web app

I cannot get my web app to connect to the database when running the app. I can connect in the SQL Server object explorer and I took the connection string from the connections properties
Here is my connection string :
<add name="Quotes.DAL.QuotesConnection"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=TestDB;Integrated Security=False;User ID=sa;Password=***;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
providerName="System.Data.SqlClient" />
I can connect as SA and I can create the database that it points to in Management Studio. When my app tries to connect via Entity Framework I get the following error :
System.Data.SqlClient.SqlException (0x80131904): Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,
I'm running Windows 7 as a home dev machine so there is no Active Directory.
Can anybody explain why this might happen?
I have found that this is probably because I have Entity Framework in another assembly. I created a new web application and its connection string works. When it try the same connection string in my DAL it fails with this same error!
Thanks
It may be because of setting Integrated Security=False, I have never set it to false. I normally use just the bare minimum Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword; when setting up my connection strings with sql authentication, only adding things as I need them.
The other issue I see is using SA to connect to the database. This breaks almost every best practice in the book and I would recommend creating an app specific password for when you roll out the program. The reason being is the GOD ACCESS account for the server will have its password in plain text in the app.config file. Just something to keep in mind.
EDIT: After some comment discussion the connection string was in the wrong config file.

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable.

I get this error when trying to send an email using Asp.net application using SMTP on IIS 7.5
The error is "System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such user here at System.Net.Mail.SmtpTransport.SendMail(... "
What i have in web.config is
<system.net>
<mailSettings>
<smtp from="support#mysite.com" deliveryMethod="Network">
<network host="hostname" port="25" password="password" userName="you#yoursite.com" />
</smtp>
</mailSettings>
</system.net>
I really don't understand what should be the username and password here. I get the same error when i put defaultcredentials = "true" instead of username and password. Is there something to do with toaddress. The toaddress is myid#mydomain.com, which works for all other emails, etc.
Please advice me where i am doing wrong!! Thank you in advance!
The userName and password settings refer to the credentials for connecting to the SMTP server. Make sure you don't confuse this with the username and password for the from or to address, which is not relevant to the SMTP server.
You may want to try a tool like SMTPDiag to help you figure out any SMTP connectivity issues you have. However, your error seems to indicate that connectivity is fine but that mail cannot be delivered.
Ram if you are using a web host and you have SMTP support in your package... Then check their control panel.
Also as Jacob I want to remind you that FREE SMTP user accounts that web hosts offer are different from credentials to connect to the SMTP server itself. Usually the former is that's free with web hosts and the latter is not included as long as you don't have a dedicated server I think.
If you don't find it in their control panel then call support... They will be able to give you those details if applicable.

SQL connection string ignoring specified username & password?

I’m having a problem with my SQL Connection strings not using the authentication provided in the connection string. I have written an ASP.NET application using self-tracking entities and I need to access data from two different servers. The first server, SQLSERVER1 is using windows authentication and is on the domain and im able to pull my data just fine. The second server connection however, is on another box off the domain and I need to use a specific login and password to access the data. I confirmed that the credentials im using in the connection string can connect to the server just fine.
On my web-server setup I have my app pool in IIS7 running under its own credential “Domain\AppPoolUser”.
For some reason, whenever I try to call data from SQLSERVER2 after publishing to the webserver im getting the following error, even though I have specified the credentials in my connection string and they are valid. The connection works fine however, if im debugging the application locally : Login failed for user 'DOMAIN\AppPoolUser'.
It seems like it’s not using the credentials I have specified in the connection string, and instead trying to connect as the application pools credentials. How can I setup the connection string to use the credentials I have provided?
Here is my connection strings:
<add name="ADATrackingContext" providerName="System.Data.SqlClient" connectionString="Server=SQLSERVER1;Database=ADATracking;Integrated Security=True;" />
<add name="PatientContext" providerName="System.Data.SqlClient" connectionString="Server=SQLSERVER2;Database=Patients;uid=PatientUser;password=123456;Integrated Security=False;" />
Not sure if it matters, but the user should be User Id= and not uid=
The ADATrackingContext connection string will attempt to login using the Domain\AppPoolUser domain account since you have set the Integrated Security = true. Since you don't have Domain\AppPoolUser as a login for your db, you will get the error you describe.
Double check to make sure you are passing the correct connection string to your DbContext.
It looks like the error was being caused beacuse I was trying to pull the data before my client page was authenticated to the ADATracking connection string. I moved the data call over to the HomeConstroller.cs instead of the Global.asax file and all is working now. My mistake.

SMTPClient Half Working \ Half Not

I am using Microsoft's membership framework on a website. I am able to send password retrieval e-mails, but am unable to send e-mails myself using SMTPClient.
When you configure the SMTP settings in the Web Site Administration Tool, what are the settings that this application give it's SMTPclient?
If I know this, I can duplicate it and hopefully send e-mails.
A few items I've ruled out.
- I'm using port 25, (which is the only one allowed under medium trust).
- This code works on my local system.
I was attempting to pass the values for SMTPClient in with the constructor. What I failed to realize is that SMTPClient apparently automatically pulls the values from web.config and uses those.
By trying to pass my own values (even though they where identical); I inadvertently violated trust levels causing a security exception.
Don't pass in smtp info in the constructor, use web.config to set it up, and there should be no problem in medium trust.
It could be lots of things, from credential problems, DNS issues, or...who knows. Is it unable to send as in you get an error or as in they appear to go but never arrive?
Are you sure the WSA tool is going through SMTPClient, or are you just assuming it (I don't know myself)?
-- MarkusQ
I am getting a Security Exception on
my mail
That sounds like a credentials problem then, or a trust issue. Are you sure you're running at medium (or higher) trust? What's the rest of the error?
-- MarkusQ
Try checking your web.config file: is the WSA tool updating these settings?
This element is under the configuration element
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="you#email.com">
<network
host="your.gateway.com"
userName="your#email.com"
password="your_password"
port="25" />
</smtp>
</mailSettings>
</system.net>

Resources