Showing posts with label user. Show all posts
Showing posts with label user. Show all posts

Saturday, March 31, 2012

System.InvalidCastException: Specified cast is not valid.

Hi
I get the this error when i run my code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
this.DataGrid1.DataSource= this.DataSource();
this.DataGrid1.DataBind();
}
private ICollection DataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
for (int i=0;i<10;i++)
{
DataRow dr = dt.NewRow();
if (i%2==0)
{
dr[0]=1;
}
else
{
dr[0]=0;
}
dt.Rows.Add(dr);
}
DataView dv;
dv = new DataView(dt);
return dv;
}
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int i = e.Item.ItemIndex;
if(i==0)
{
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
}
}
page:
one two
one two
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 56px" runat="server"
Height="216px" Width="448px" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="dll" Runat="server">
<asp:ListItem Value="0">one</asp:ListItem>
<asp:ListItem Value="1">two</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
ch JIt would help if you told us the line #. Is it at:
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
First of all, it looks like you are doing that when ItemIndex == 0
wouldn't that be ur HeaderTemplate in which case cell[0].Controls[0]. really
might not be what you expect. Secondly, you might prefer
e.Item.FindControl("dll") or e.Item.Cells[0].FindContorl("dll") (not sure
which will work, favor the first one if it'll work) over using indexes. It
makes your code more flexible and less likely to break. Sometimes literals
(like spaces and newlines) are converted to controls, so while you might
think it's Controls[0], it might really be Controls[1] 'cuz there was a
newline before it.
It should be pretty easy to step through your code and debug though...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Jimmy" <beffer@.gmail.com> wrote in message
news:eX0b2r$yFHA.2556@.TK2MSFTNGP10.phx.gbl...
> Hi
> I get the this error when i run my code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> this.DataGrid1.DataSource= this.DataSource();
> this.DataGrid1.DataBind();
> }
> private ICollection DataSource()
> {
> DataTable dt = new DataTable();
>
> dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
>
> for (int i=0;i<10;i++)
> {
> DataRow dr = dt.NewRow();
> if (i%2==0)
> {
> dr[0]=1;
>
> }
> else
> {
> dr[0]=0;
>
> }
> dt.Rows.Add(dr);
> }
> DataView dv;
> dv = new DataView(dt);
> return dv;
> }
> private void DataGrid1_ItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> int i = e.Item.ItemIndex;
> if(i==0)
> {
> ((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
> }
>
> }
>
> page:
>
> one two
> one two
> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
> absolute; TOP: 56px" runat="server"
> Height="216px" Width="448px" AutoGenerateColumns="False">
> <Columns>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:DropDownList ID="dll" Runat="server">
> <asp:ListItem Value="0">one</asp:ListItem>
> <asp:ListItem Value="1">two</asp:ListItem>
> </asp:DropDownList>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> ch J
>
>
>

System.InvalidCastException: Specified cast is not valid.

Hi

I get the this error when i run my code:

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

this.DataGrid1.DataSource= this.DataSource();

this.DataGrid1.DataBind();

}

private ICollection DataSource()

{

DataTable dt = new DataTable();

dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));

for (int i=0;i<10;i++)

{

DataRow dr = dt.NewRow();

if (i%2==0)

{

dr[0]=1;

}

else

{

dr[0]=0;

}

dt.Rows.Add(dr);

}

DataView dv;

dv = new DataView(dt);

return dv;

}

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{

int i = e.Item.ItemIndex;

if(i==0)

{

((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";

}

}

page:

one two
one two
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 56px" runat="server"
Height="216px" Width="448px" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="dll" Runat="server">
<asp:ListItem Value="0">one</asp:ListItem>
<asp:ListItem Value="1">two</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid
ch JIt would help if you told us the line #. Is it at:
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";

First of all, it looks like you are doing that when ItemIndex == 0
wouldn't that be ur HeaderTemplate in which case cell[0].Controls[0]. really
might not be what you expect. Secondly, you might prefer
e.Item.FindControl("dll") or e.Item.Cells[0].FindContorl("dll") (not sure
which will work, favor the first one if it'll work) over using indexes. It
makes your code more flexible and less likely to break. Sometimes literals
(like spaces and newlines) are converted to controls, so while you might
think it's Controls[0], it might really be Controls[1] 'cuz there was a
newline before it.

It should be pretty easy to step through your code and debug though...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy" <beffer@.gmail.com> wrote in message
news:eX0b2r$yFHA.2556@.TK2MSFTNGP10.phx.gbl...
> Hi
> I get the this error when i run my code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> this.DataGrid1.DataSource= this.DataSource();
> this.DataGrid1.DataBind();
> }
> private ICollection DataSource()
> {
> DataTable dt = new DataTable();
>
> dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
>
> for (int i=0;i<10;i++)
> {
> DataRow dr = dt.NewRow();
> if (i%2==0)
> {
> dr[0]=1;
>
> }
> else
> {
> dr[0]=0;
>
> }
> dt.Rows.Add(dr);
> }
> DataView dv;
> dv = new DataView(dt);
> return dv;
> }
> private void DataGrid1_ItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> int i = e.Item.ItemIndex;
> if(i==0)
> {
> ((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
> }
>
> }
>
> page:
>
> one two
> one two
> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
> absolute; TOP: 56px" runat="server"
> Height="216px" Width="448px" AutoGenerateColumns="False">
> <Columns>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:DropDownList ID="dll" Runat="server">
> <asp:ListItem Value="0">one</asp:ListItem>
> <asp:ListItem Value="1">two</asp:ListItem>
> </asp:DropDownList>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> ch J
>
>

Monday, March 26, 2012

system.net.mail - email sending no longer working

Hi,

Previously on my web app I had a contact page that would send an email to me with all the filled in values from the user. The email would be sent with the FROM address the user put in, so when I received it I could reply back to them. I had this working for years, and now all of a sudden it errors out.

I get the following error. Please note I was using System.Net.Mail, but changed to a component to try and debug.

I'm wondering what would cause this error to happen suddenly? Perhaps a configuration change in IIS ? What would be a good work around to this ? Is it possible to maybe email from my own domain, but specify a different ReplyTo address?


Thanks,
mike123

Additional Help:452 4.2.2 Mailbox full
] Verify you can send email on behalf of'userFilledInName@dotnet.itags.org.hotmail.com' through the mail server 'domainName.com to'admin@dotnet.itags.org.domainName.com'. 'domainName.com' may not allow relaying for that specific address or domain, resulting with a 500 or larger error.Your server may also require a username and password for authentication, check with your mail server administrator. For additional information, enable logging by setting EmailMessage.Logging = true and if you have file write permission set a path for EmailMessage.LogPath, then check the log. If you are sending from an ASP.NET application and do not have file write access, wrap the EmailMessage.Send() in a Try..Catch() block and call Response.Write( EmailMessage.GetLog() ) from inside or after the Catch(). To ignore this error; set IgnoreRecipientErrors = true
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: aspNetEmail.SmtpProtocolException: [Additional Help:452 4.2.2 Mailbox full
] Verify you can send email on behalf of'userFilledInName@dotnet.itags.org.hotmail.com' through the mail server 'domainName.com to'admin@dotnet.itags.org.domainName.com'. 'domainName.com' may not allow relaying for that specific address or domain, resulting with a 500 or larger error.Your server may also require a username and password for authentication, check with your mail server administrator. For additional information, enable logging by setting EmailMessage.Logging = true and if you have file write permission set a path for EmailMessage.LogPath, then check the log. If you are sending from an ASP.NET application and do not have file write access, wrap the EmailMessage.Send() in a Try..Catch() block and call Response.Write( EmailMessage.GetLog() ) from inside or after the Catch(). To ignore this error; set IgnoreRecipientErrors = true

Source Error:


Line 200:
Line 201:
Line 202: msg.Send()
Line 203: msg = Nothing
Line 204:

Destination Full means exactly that. You're sending to an address where the mailbox will accept no more messages. You can't fix this, the problem is the recipient needs to read their mail and empty their mailbox.

Jeff


Hi Jeff,

Thanks for the lightning quick reply, but sorry I forgot to include this part. I have emptied the mail box, it is definately not full. Also to make sure it wasnt a server side mail problem I also tried sending to other email addresses that also were verified to not be full.

I was thinking it might have something to do with the relaying ? I can paste mail logs if that might help ?

Thanks again,
Mike123


anybody have any other thoughts on this ?

much appreciated

mike123

Saturday, March 24, 2012

System.Net.Mail.SmtpClient.Send() Error: An invalid character was found in the mail header

hi all!

please help!

I wanted to make an automatic email when I create user by CreateUserWizard. So I configured SMTP, then in properties of the wizard indicated textfile for message and wrote simple subject "registration"

but I have an exception (like in subj).

I even tried to set the subject in event handler for "emailsending" event. Same exception.

What is wrong? How could I fix it?

Here us some info from stack:

[FormatException:An invalid character was found in the mail header.] System.Net.BufferBuilder.Append(String value, Int32 offset, Int32 count) +915954 System.Net.Mail.EHelloCommand.PrepareCommand(SmtpConnection conn, String domain) +106 System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +835 System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +316 System.Net.Mail.SmtpClient.GetConnection() +42 System.Net.Mail.SmtpClient.Send(MailMessage message) +1485

[SmtpException: Email send failure.] System.Net.Mail.SmtpClient.Send(MailMessage message) +2074 System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341 System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +571 System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +105 System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +453 System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +149 System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +171 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

Hi there, can i just ask why you choose me? as for your problem, it looks like there is an invalid character in the mail header, so either there is nothing in it or something there shouldnt be, try taking a few steps back, if your attaching a text file just simply put a few words coded in, and if your header is dynamic try making it hard coded


You were online. Sorry.

It is more simple. There is simpliest string, like "123". Same error


hey no worries, well try a string like abc, also make sure no fields are not left blank. What usually helps me is take a 10 min break, clear you head have a coffee and come back look through your code as if you have never seen it before. something may catch. Im not the worlds best .neter but i usually find if there is a problem its often by taking things back to basic it helps


If your still not having any success you could try the code below and see if it makes any difference.

Regards

Martijn

Sub mailout()Dim mailAsNew Net.Mail.MailMessage()

'set the addresses

mail.To.Add("recipient@.whereever.com")

mail.From =New Net.Mail.MailAddress("sender@.wherever.com"))

'set the content

mail.Subject ="Email Subject line"

mail.Body ="The main body of the email message"

'send the message

Dim smtpAsNew Net.Mail.SmtpClient("smtp.whereever.com")

'to authenticate we set the username and password properites on the SmtpClient

smtp.Credentials =New Net.NetworkCredential("smtp-accountname e.g. sender@.wherever.com","smtp-account-password")

Try

smtp.Send(mail)

response.write("Email sent successfully")

Catch ExAs Exception

response.write("Email send failed error code is... " & Ex.Message)

EndTry

EndSub


no success, same error


I cant come up with any conclusions from your stack trace.

The code I gave you I copied out of an application I wrote there was something I had missed and should have cleaned up in the following line

mail.From =New Net.Mail.MailAddress(Session(sender@.wherever.com))

It should be this (no reference to any session variable)

mail.From =New Net.Mail.MailAddress(sender@.wherever.com)

The only other question is does your recipient or sender email address have any unusual charactors or attempt to have a space in it? Any thing like that could cause a problem. Try the same code with different email addresses and different content.

Sorry no other suggestions

Martijn


May be this piece of code will help:

<system.net>
<mailSettings>
<smtp from="evdokp@.pochta.ru">
<network host="mail.pochta.ru" password="[мой пароль]" userName="evdokp@.pochta.ru" />
</smtp>
</mailSettings>
</system.net>

this is how ASP.NET build-it configuration tool edits web.config

Well, my additional question is: where does the tool sets port value?


ok, my sugesstion is to take remove the brackets from the password and to use a password with standard English character set without and spaces.

Be sure to update the password on the mail server too.

Good luck

<system.net>
<mailSettings>
<smtp from="evdokp@.pochta.ru">
<network host="mail.pochta.ru" password="myPassword" userName="evdokp@.pochta.ru" />
</smtp>
</mailSettings>
</system.net>


it is not that easy.

these brackets are there just because I hide my password. It was like you say "myPassword"

Do you know where port is defined in web.config?

System.Net.Mail.SmtpException

My webserver does not have smtp on it but I'm still able to relay email to my email server with user name and password, my first question is that the dotnet is using an API that's built into server to relay?

Also email stopped working a day ago with error messageSyntax error, command unrecognized. The server response was: 5.1.0 Dropping connection due to an error on this server . Could this error be caused by the internal process dotnet uses to relay not working?

The 5.1.0 error is usually on the remote SMTP server and the error is propogated back to you. Does the server you relay to allow relays?

You're not relaying. System.Net.Mail simply sends the message to the defined SMTP server. Your error is a SMTP error, check the logs on the SMTP server to see what is happening, if you can. A 5.1.0 is a Sender Denied error, which most likely means you now need to use authentication. Checkwww.systemnetmail.com for help and samples.

Jeff


Still not getting this working getting, any help would be appreciated.

System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it

Line 88: try
Line 89: {
Line 90: client.Send(message);
Line 91: Response.Redirect("RequestAccepted.aspx");
Line 92: }
Source File:d:\Inetpub\KPClient\ContactUS.aspx.cs Line:90

Stack Trace:

[SocketException (0x274d): No connection could be made because the target machine actively refused it] System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +1001874 System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +33 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +431[WebException: Unable to connect to the remote server] System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +1447464 System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +190 System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21 System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +318 System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +227 System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +316 System.Net.Mail.SmtpClient.GetConnection() +42 System.Net.Mail.SmtpClient.Send(MailMessage message) +1485


This turned out to be a bad router change that was not documented.