Uploaded website does not sent emails - asp.net

I have uploaded my website to a known hosting server and i have a contact form, the weird thing is that when i run the website from visual studio (asp.net language) is sending the emails fine on my inbox.From the time that i uploaded it on the hosting server it gives the error: failure sending the email.I am using smtp.gmail.com, port:587,username and pass and ssl enabled.
protected void sendClientMail(string emailto)
{
try
{
var mail = new MailMessage
{
BodyEncoding = Encoding.UTF8,
From = new MailAddress(ConfigurationManager.AppSettings["MAILFROM"])
};
mail.To.Add(emailto);
mail.Bcc.Add(ConfigurationManager.AppSettings["MAILBCC"]); //sends to my email also
mail.Subject=ConfigurationManager.AppSettings["CLIENT-MAILSUBJECT"];
mail.IsBodyHtml = true;
#region //Load Email Control and get HTML string
string mailBody = "";
{
PrintPlaceHolder.Visible = true;
var sb = new StringBuilder();
var writer = new HtmlTextWriter(new StringWriter(sb));
var emailctl = LoadControl("~/Controls/ClientEmail.ascx") as ClientEmail;
if (emailctl != null)
{
emailctl.Name = txtName.Text;
emailctl.IntroName = txtName.Text + " " + txtSurname.Text;
emailctl.Surname = txtSurname.Text;
emailctl.Mobile = txtMobile.Text;
emailctl.Phone = txtPhone.Text;
emailctl.City = txtCity.Text;
emailctl.Street = txtStreet.Text;
emailctl.Message = txtmessage.Text;
emailctl.Email = txtEmail.Text;
emailctl.Country = ddlCountry.SelectedValue;
PrintPlaceHolder.Controls.Add(emailctl);
emailctl.RenderControl(writer);
}
mailBody = sb.ToString();
if (emailctl != null)
{
emailctl.Dispose();
}
writer.Dispose();
sb.Clear();
PrintPlaceHolder.Visible = false;
}
#endregion
mail.Body = mailBody;
//mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential (ConfigurationManager.AppSettings["MAILFROM"], ConfigurationManager.AppSettings["PASS"]);
client.Host = ConfigurationManager.AppSettings["SMTPSERVER"];
client.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPORT"]);
//client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl= false;
//client.UseDefaultCredentials = true;
client.Send(mail);
clearFields();
Response.Write("<script>alert('"+ConfigurationManager.AppSettings["MAILSUCCESS"]+"');</script>");
}
catch (Exception e)
{
Response.Write("<script>alert('"+ ConfigurationManager.AppSettings["MAILFAIL"] +" Error: "+e+"')</script>");
}
}//end method
Web.config file code:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
<add key="CLIENT-MAILSUBJECT" value="Mario Website - Confirmation Email"/>
<add key="MY-MAILSUBJECT" value="Mario Website - Email Sent"/>
<add key="MAILFROM" value="mariotec#mario26tech.com"/>
<add key="MAILBCC" value="nikolaou_marios#hotmail.com"/>
<add key="SMTPSERVER" value="sns41.win.hostgator.com"/>
<add key="SMTPPORT" value="26"/>
<add key="PASS" value="pass"/>
<add key="MAILSUCCESS" value="Email was sent successfully, thank you for your interest!!!"/>
<add key="MAILFAIL" value="There was an error while sending the email."/>
</appSettings>
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear/>
<add value="Index.aspx"/>
</files>
</defaultDocument>
</system.webServer>
</configuration>
I have contacted the hosting provider without any help.
Thanks in advance.

Related

angularjs - webservice returns an html page instead of data

I'm using $http.get to connect to an asmx webservice passing 2 parameters: username and password. However it returns the html page of the web service instead of data.
am I missing something?
here's my code for controller.js:
$scope.enterlogin = function(usern,pass)
{
loginService.getUser(usern,pass).then(function(response){
console.log('response is = ' + response.data);
};
}
Here's my code for services.js:
.factory('loginService', ['$http', function($http){
var base_url = "http://<ipaddress of webservie>/UserService3/WebService1.asmx?op=getUserbyUsername";
return {
getUser: function(usern,pass){
console.log('code side usern is = ' + usern + "" + pass);
return $http.get(base_url, { params: { passw: pass, uname: usern}
});
}
}
}])
I also added these to the webservice's web.config file:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<httpHandlers>
<add verb="GET,HEAD,POST,OPTIONS" path="*.asmx" type="System.Web.UI.PageHandlerFactory" />
</httpHandlers>
And this:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
and this is the webmethod in the webservice:
[WebMethod]
public string getUserbyUsername(string uname, string passw)
{
string cs = "Data Source =.; Initial Catalog = UsersDB; Integrated Security = True";
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("spGetUserByUsername", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter parameter = new SqlParameter(#"Username", uname);
SqlParameter parameter2 = new SqlParameter(#"Password", passw);
cmd.Parameters.Add(parameter);
cmd.Parameters.Add(parameter2);
User user = new User();
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
// user.Username = reader["Username"].ToString();
// user.Password = reader["Password"].ToString();
user.IsExisting = reader["IsExisting"].ToString();
user.UserID = reader["UserID"].ToString();
}
con.Close();
return new JavaScriptSerializer().Serialize(user);
}
}
You might need to change System.Web.UI.PageHandlerFactory (which is typically used for aspx endpoints) to System.Web.Services.Protocols.WebServiceHandlerFactory (which is more typically used for asmx endpoints).
EDIT: try changing the return to void and then doing this:
Context.Response.Write(new JavaScriptSerializer().Serialize(user));
See if that works.

ReportViewer Showing empty in vs2010

I'm calling a report from report server, the project runs successfully but the page will be empty. through development tool I can find the amount of space it is acquired.
Below is the code i'm using.
Web Config.
under system.web
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
</httpHandlers>
system.web under compilation
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>
and there are some assemblies which are automatically added when the reportviewer was added to the page.
under system.webservices
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
cs page
int dcid = 1;
ReportViewer1.Visible = true;
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServer"].ToString());
Microsoft.Reporting.WebForms.ReportParameterInfoCollection paramInfo;
System.Collections.Generic.List<Microsoft.Reporting.WebForms.ReportParameter> paramList = new System.Collections.Generic.List<Microsoft.Reporting.WebForms.ReportParameter>();
paramList.Add(new Microsoft.Reporting.WebForms.ReportParameter("DCId", dcid.ToString(), false));
ReportViewer1.ServerReport.ReportPath = ConfigurationManager.AppSettings["ReportsFolder"].ToString() + "rpt_DCForm";
ReportViewer1.ServerReport.ReportServerCredentials = new Credentials(ConfigurationManager
.AppSettings["ReportUserName"].ToString(), ConfigurationManager
.AppSettings["ReportUserPwd"].ToString(), ConfigurationManager
.AppSettings["ReportserverDomain"].ToString());
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
ReportViewer1.ServerReport.SetParameters(paramList);
paramInfo = ReportViewer1.ServerReport.GetParameters();
ReportViewer1.ServerReport.Refresh();
Credentials class
string _userName, _password, _domain;
public Credentials(string userName, string Password, string domain)
{
_userName = userName;
_password = Password;
_domain = domain;
}
#region IReportServerCredentials Members
public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string userName, out string password, out string authority)
{
//userName = _userName;
//password = _password;
//authority = _domain;
//authCookie = new System.Net.Cookie(".ASPXAUTH", ".ASPXAUTH", "/", "Domain");
//return true;
authCookie = null;
userName = password = authority = null;
return false;
}
public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get { return null; }
}
public System.Net.ICredentials NetworkCredentials
{
get { return new System.Net.NetworkCredential(_userName, _password, _domain); }
}
#endregion
The same code works fine in our other project. For a new solution Its not working.
Please help what I'm missing out.
Thanks in advance.

Asp.net Routing not works when hosted on root

I have used Asp.net 4.0 Routing techniques to achieve friendly urls. I have used following code in global.asax..
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection sqlCon = new SqlConnection(connectionstring);
SqlCommand sqlCmd = new SqlCommand("Sch_Sp_GetRegisterRoutes", sqlCon);
sqlCmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
try
{
sda.Fill(dt);
}
catch (Exception ex)
{
}
finally
{
sqlCon.Close();
}
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
try
{
routes.MapPageRoute(dr["Menuname"].ToString().Replace(" ",string.Empty),
dr["URL"].ToString(),
"~/" + dr["Pagename"].ToString());
}
catch (Exception exx)
{
}
}
}
}
my url in database is like About-Us and Pagename is like MyFolder/Aboutus.aspx. In my local machine it worked but when I deploy it on my server(iis 7 version and windows server 2008) it shows error '
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable'
I have call it as resolveUrl("~/About-Us").
Please help me....
Just adding few lines of code in web.config , it wil worked for me..
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition=""/>
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*"
path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>

how to access connection string Class.cs file?

I am totally new to Windows programming so i don't know how to access connection string in Class.cs file as we can in web application as follow:
public DataTable Client_Login_Check(string Email, string Password)
{
DataTable dt = new DataTable();
try
{
object[] objParam = new object[2];
objParam[0] = Email;
objParam[1] = Password;
return dt = SqlHelper.ExecuteDataset(ConfigurationManager.AppSettings["GL"], "GreenLight_Users_LoginCheck", objParam).Tables[0];
}
catch (Exception ex)
{
OutputMessage = ex.Message;
}
return dt;
}
I have added "System.Configuration" namespace...But still i am not getting ConfigurationManager in help. Please help me..
Apart from adding a reference to System.Configuration.dll in the project, you will also need to add a using declaration for the namespace in the file:
using System.Configuration;
Note:
You should be using ConfigurationManager.ConnectionStrings["GL"].ConnectionString and have the connection string in the connectionStrings configuration section, not in the appSettings section.
Add a reference to System.Configuration.dll, and you should be able to use the System.Configuration.ConfigurationManager
if you want to use App.config
add these lines in tag
<configuration>
<connectionStrings>
<add name="mystring" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dbName;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="Server" value=".\SQLEXPRESS"/>
<add key="Database" value="dbAIAS"/>
<add key="ClientSettingsProvider.ServiceUri" value=""/>
</appSettings>
<configuration>
in Name.cs file you can access by
string strconn = #"Data Source= " + ConfigurationSettings.AppSettings["Server"].ToString() + "; Initial Catalog= " + ConfigurationSettings.AppSettings["Database"].ToString() + ";Integrated Security=True";

ConnectionStringSettings NullReference Error

I have the following settings in my web.config, as a child of the configuration element:
<connectionStrings>
<clear />
<add name="GingerlimeDB"
connectionString="Data Source=localhost;
Integrated Security=False;
Initial Catalog=dbname;
User Id=accountname;
Password=password;"
providerName="System.Data.SqlClient" />
</connectionStrings>
In the code behind where I wish to retrieve the connection string, I placed:
using System.Configuration
...
var connStringObject = ConfigurationManager.ConnectionStrings["GingerlimeDB"];
string connectionString = connStringObject.ConnectionString;
Console.WriteLine(connectionString);
I don't get to the console output, instead it shows:
Object reference not set to an instance of an object.
How do I get the Connection String out of the web config?
Assuming your web.config file looks like this:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<clear />
<add name="GingerlimeDB"
connectionString="Data Source=localhost;
Integrated Security=False;
Initial Catalog=dbname;
User Id=accountname;
Password=password;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
You should be able to access the connection string exactly like you showed in your code. I use something nearly identical:
using System.Configuration;
....
internal bool OpenDatabaseConnection()
{
try
{
string connectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;
dbConnection = new SqlCeConnection(connectionString);
dbConnection.Open();
return true;
}
catch (SqlCeException ex)
{
this.errorLogging = new ErrorLogging(ex.Message, ex.Source, ex.HelpLink, ex.GetType().ToString());
}
catch (InvalidOperationException ex)
{
this.errorLogging = new ErrorLogging(ex.Message, ex.Source, ex.HelpLink, ex.GetType().ToString());
}
catch (ArgumentException ex)
{
this.errorLogging = new ErrorLogging(ex.Message, ex.Source, ex.HelpLink, ex.GetType().ToString());
}
catch (ConfigurationErrorsException ex)
{
this.errorLogging = new ErrorLogging(ex.Message, ex.Source, ex.HelpLink, ex.GetType().ToString());
}
return false;
}
Which line is actually causing the NullReference exception? (object not set to an instance of an object)?

Resources