When sending an attachment with this page the application hangs. The is
placed on the server but it's never sent and deleted.
All the permissions seem to ok but I cant seem to find out why this app hangs.

Thanks


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.IO" %>


<script language = "javascript">
function Tocheck(frmemail) {
if(frmemail.txtFile.value == "") {
alert("Please attach a file");
frmemail.txtFile.focus();
return(false);
}
}
</script>

<script runat="server">

void btnSubmit_Click(Object sender, EventArgs e) {

MailMessage mail = new MailMessage();
mail.From = txtFrom.Text;
mail.To = txtTo.Text;
mail.Subject = txtSubject.Text;
mail.Body = txtMsg.Text;
mail.BodyFormat = MailFormat.Html;

string strdir = "f:\\inetpub\\webtools\\emailtest\\files\\";
//string strdir = "c:\\temp\\";

string strfilename = Path.GetFileName(txtFile.PostedFile.FileName);

txtFile.PostedFile.SaveAs(strdir+strfilename);

mail.Attachments.Add(new MailAttachment(strdir+strfilename));

try
{
SmtpMail.SmtpServer = "mail.fmr.com";
SmtpMail.Send(mail);
}
catch(Exception ex)
{
Response.Write("<b>Exception Occured:</b> " +ex);
}
finally
{
Response.Write("Your E-mail has been sent sucessfully");
}

// Uploaded file deleted after sending e-mail

File.Delete(strdir+strfilename);
}

</script>




<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Using ASP.NET To Send Email - Part 2</title>
</head>

<body>

<div align="center">
<form method = "post" name = "frmemail" runat = "server"
enctype="multipart/form-data" onSubmit = "return Tocheck(this)">
<table border="1" width="637" height="196">
<tr>
<td height="196" width="637" valign="top">

From : <asp:TextBox ID = "txtFrom" Runat =server></asp:TextBox>
<p>To: <asp:TextBox ID = "txtTo" Runat = server></asp:TextBox>
<p>Subject:<asp:TextBox ID = "txtSubject" Runat = server></asp:TextBox>

<p>Message:<asp:TextBox runat="server" Height="57px" TextMode="MultiLine"
Width="212px" ID="txtMsg"></asp:TextBox>


<p>Attach:<input type = "file" id = "txtFile" runat = "server">


<p align="center"><asp:Button Runat = server ID = "btnSubmit" Text =
"SEND" OnClick = "btnSubmit_Click"></asp:Button></td>
</tr>
</table>
</form>
</div>

</body>

</html>

Re: Sending Email/Attachment .NET app hangs by Egbert

Egbert
Fri Nov 24 15:27:07 CST 2006


"Vinnie L" <VinnieL@discussions.microsoft.com> wrote in message
news:592106FF-4459-4C84-97CD-0432483A122F@microsoft.com...
> When sending an attachment with this page the application hangs. The is
> placed on the server but it's never sent and deleted.
> All the permissions seem to ok but I cant seem to find out why this app
> hangs.
>
> Thanks
>
>
> <%@ Page Language="C#" %>
> <%@ Import Namespace="System.Web.Mail" %>
> <%@ Import Namespace="System.IO" %>
>
>
> <script language = "javascript">
> function Tocheck(frmemail) {
> if(frmemail.txtFile.value == "") {
> alert("Please attach a file");
> frmemail.txtFile.focus();
> return(false);
> }
> }
> </script>
>
> <script runat="server">
>
> void btnSubmit_Click(Object sender, EventArgs e) {
>
> MailMessage mail = new MailMessage();
> mail.From = txtFrom.Text;
> mail.To = txtTo.Text;
> mail.Subject = txtSubject.Text;
> mail.Body = txtMsg.Text;
> mail.BodyFormat = MailFormat.Html;
>
> string strdir = "f:\\inetpub\\webtools\\emailtest\\files\\";
> //string strdir = "c:\\temp\\";
>
> string strfilename = Path.GetFileName(txtFile.PostedFile.FileName);
>
> txtFile.PostedFile.SaveAs(strdir+strfilename);
>
> mail.Attachments.Add(new MailAttachment(strdir+strfilename));
>
> try
> {
> SmtpMail.SmtpServer = "mail.fmr.com";
> SmtpMail.Send(mail);
> }
> catch(Exception ex)
> {
> Response.Write("<b>Exception Occured:</b> " +ex);
> }
> finally
> {
> Response.Write("Your E-mail has been sent sucessfully");
> }
>
> // Uploaded file deleted after sending e-mail

Hi,

Because of .NET garbage collection, you must be sure that
All resources are released before you delete.
I suspect a deadlock.

Can you comment the File.Delete statement and retry?
If this fixes, we can find an other way to solve the temp file deletion.

--
compatible web farm Session replacement for Asp and Asp.Net
http://www.nieropwebconsult.nl/asp_session_manager.htm

> File.Delete(strdir+strfilename);
> }
>
> </script>
>
>
>
>
> <html>
>
> <head>
> <meta http-equiv="Content-Language" content="en-us">
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title>Using ASP.NET To Send Email - Part 2</title>
> </head>
>
> <body>
>
> <div align="center">
> <form method = "post" name = "frmemail" runat = "server"
> enctype="multipart/form-data" onSubmit = "return Tocheck(this)">
> <table border="1" width="637" height="196">
> <tr>
> <td height="196" width="637" valign="top">
>
> From : <asp:TextBox ID = "txtFrom" Runat =server></asp:TextBox>
> <p>To: <asp:TextBox ID = "txtTo" Runat = server></asp:TextBox>
> <p>Subject:<asp:TextBox ID = "txtSubject" Runat = server></asp:TextBox>
>
> <p>Message:<asp:TextBox runat="server" Height="57px" TextMode="MultiLine"
> Width="212px" ID="txtMsg"></asp:TextBox>
>
>
> <p>Attach:<input type = "file" id = "txtFile" runat = "server">
>
>
> <p align="center"><asp:Button Runat = server ID = "btnSubmit" Text =
> "SEND" OnClick = "btnSubmit_Click"></asp:Button></td>
> </tr>
> </table>
> </form>
> </div>
>
> </body>
>
> </html>


Re: Sending Email/Attachment .NET app hangs by VinnieL

VinnieL
Sat Nov 25 14:02:02 CST 2006

Hi Ergbert, Thanks for the assistance.
That didn't do it. This is bewildering to me. I gave FULL control to the
Anon user, Network Services, Authenticated Users accounts and also Excluded
the dir from Application Center Sync to made sure that App Ctr wasn't the
cause.
What tools can I use to troublesshoot, I tried DebugDiag but the app really
isn't crashing or hanging. It will timeout eventuall but there are no dumps
on DebugDiag.
Vinnie

"Egbert Nierop (MVP for IIS)" wrote:

>
> "Vinnie L" <VinnieL@discussions.microsoft.com> wrote in message
> news:592106FF-4459-4C84-97CD-0432483A122F@microsoft.com...
> > When sending an attachment with this page the application hangs. The is
> > placed on the server but it's never sent and deleted.
> > All the permissions seem to ok but I cant seem to find out why this app
> > hangs.
> >
> > Thanks
> >
> >
> > <%@ Page Language="C#" %>
> > <%@ Import Namespace="System.Web.Mail" %>
> > <%@ Import Namespace="System.IO" %>
> >
> >
> > <script language = "javascript">
> > function Tocheck(frmemail) {
> > if(frmemail.txtFile.value == "") {
> > alert("Please attach a file");
> > frmemail.txtFile.focus();
> > return(false);
> > }
> > }
> > </script>
> >
> > <script runat="server">
> >
> > void btnSubmit_Click(Object sender, EventArgs e) {
> >
> > MailMessage mail = new MailMessage();
> > mail.From = txtFrom.Text;
> > mail.To = txtTo.Text;
> > mail.Subject = txtSubject.Text;
> > mail.Body = txtMsg.Text;
> > mail.BodyFormat = MailFormat.Html;
> >
> > string strdir = "f:\\inetpub\\webtools\\emailtest\\files\\";
> > //string strdir = "c:\\temp\\";
> >
> > string strfilename = Path.GetFileName(txtFile.PostedFile.FileName);
> >
> > txtFile.PostedFile.SaveAs(strdir+strfilename);
> >
> > mail.Attachments.Add(new MailAttachment(strdir+strfilename));
> >
> > try
> > {
> > SmtpMail.SmtpServer = "mail.fmr.com";
> > SmtpMail.Send(mail);
> > }
> > catch(Exception ex)
> > {
> > Response.Write("<b>Exception Occured:</b> " +ex);
> > }
> > finally
> > {
> > Response.Write("Your E-mail has been sent sucessfully");
> > }
> >
> > // Uploaded file deleted after sending e-mail
>
> Hi,
>
> Because of .NET garbage collection, you must be sure that
> All resources are released before you delete.
> I suspect a deadlock.
>
> Can you comment the File.Delete statement and retry?
> If this fixes, we can find an other way to solve the temp file deletion.
>
> --
> compatible web farm Session replacement for Asp and Asp.Net
> http://www.nieropwebconsult.nl/asp_session_manager.htm
>
> > File.Delete(strdir+strfilename);
> > }
> >
> > </script>
> >
> >
> >
> >
> > <html>
> >
> > <head>
> > <meta http-equiv="Content-Language" content="en-us">
> > <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> > <title>Using ASP.NET To Send Email - Part 2</title>
> > </head>
> >
> > <body>
> >
> > <div align="center">
> > <form method = "post" name = "frmemail" runat = "server"
> > enctype="multipart/form-data" onSubmit = "return Tocheck(this)">
> > <table border="1" width="637" height="196">
> > <tr>
> > <td height="196" width="637" valign="top">
> >
> > From : <asp:TextBox ID = "txtFrom" Runat =server></asp:TextBox>
> > <p>To: <asp:TextBox ID = "txtTo" Runat = server></asp:TextBox>
> > <p>Subject:<asp:TextBox ID = "txtSubject" Runat = server></asp:TextBox>
> >
> > <p>Message:<asp:TextBox runat="server" Height="57px" TextMode="MultiLine"
> > Width="212px" ID="txtMsg"></asp:TextBox>
> >
> >
> > <p>Attach:<input type = "file" id = "txtFile" runat = "server">
> >
> >
> > <p align="center"><asp:Button Runat = server ID = "btnSubmit" Text =
> > "SEND" OnClick = "btnSubmit_Click"></asp:Button></td>
> > </tr>
> > </table>
> > </form>
> > </div>
> >
> > </body>
> >
> > </html>
>
>

Re: Sending Email/Attachment .NET app hangs by David

David
Sun Nov 26 03:46:34 CST 2006

Download Visual Web Developer from Microsoft.com and debug your ASP.Net
application within a Visual Studio environment. You should be able to
see the exact line of code that is hanging/failing.

DebugDiag is not the appropriate tool. Treat it like a customized
Visual Studio-like debugger with some automation scripts designed to:
1. trigger on "universally bad" events like crashes (or for memory
leak/hangs, other tell-tale signs)
2. recognize common failure patterns (normally, debuggers just tell you
the raw details - you're supposed to make sense of it)
3. and do some automated triage.

It is designed to help system administrators to figure out what code is
responsible for the observed problem of "crashes, hangs, and memory
leaks" on a server and get the appropriate developer to fix the issue.
On the other hand, you happen to be the developer that's supposed to
fix the issue, so DebugDiag really isn't the tool for you.



//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//


Vinnie L wrote:
> Hi Ergbert, Thanks for the assistance.
> That didn't do it. This is bewildering to me. I gave FULL control to the
> Anon user, Network Services, Authenticated Users accounts and also Excluded
> the dir from Application Center Sync to made sure that App Ctr wasn't the
> cause.
> What tools can I use to troublesshoot, I tried DebugDiag but the app really
> isn't crashing or hanging. It will timeout eventuall but there are no dumps
> on DebugDiag.
> Vinnie
>
> "Egbert Nierop (MVP for IIS)" wrote:
>
> >
> > "Vinnie L" <VinnieL@discussions.microsoft.com> wrote in message
> > news:592106FF-4459-4C84-97CD-0432483A122F@microsoft.com...
> > > When sending an attachment with this page the application hangs. The is
> > > placed on the server but it's never sent and deleted.
> > > All the permissions seem to ok but I cant seem to find out why this app
> > > hangs.
> > >
> > > Thanks
> > >
> > >
> > > <%@ Page Language="C#" %>
> > > <%@ Import Namespace="System.Web.Mail" %>
> > > <%@ Import Namespace="System.IO" %>
> > >
> > >
> > > <script language = "javascript">
> > > function Tocheck(frmemail) {
> > > if(frmemail.txtFile.value == "") {
> > > alert("Please attach a file");
> > > frmemail.txtFile.focus();
> > > return(false);
> > > }
> > > }
> > > </script>
> > >
> > > <script runat="server">
> > >
> > > void btnSubmit_Click(Object sender, EventArgs e) {
> > >
> > > MailMessage mail = new MailMessage();
> > > mail.From = txtFrom.Text;
> > > mail.To = txtTo.Text;
> > > mail.Subject = txtSubject.Text;
> > > mail.Body = txtMsg.Text;
> > > mail.BodyFormat = MailFormat.Html;
> > >
> > > string strdir = "f:\\inetpub\\webtools\\emailtest\\files\\";
> > > //string strdir = "c:\\temp\\";
> > >
> > > string strfilename = Path.GetFileName(txtFile.PostedFile.FileName);
> > >
> > > txtFile.PostedFile.SaveAs(strdir+strfilename);
> > >
> > > mail.Attachments.Add(new MailAttachment(strdir+strfilename));
> > >
> > > try
> > > {
> > > SmtpMail.SmtpServer = "mail.fmr.com";
> > > SmtpMail.Send(mail);
> > > }
> > > catch(Exception ex)
> > > {
> > > Response.Write("<b>Exception Occured:</b> " +ex);
> > > }
> > > finally
> > > {
> > > Response.Write("Your E-mail has been sent sucessfully");
> > > }
> > >
> > > // Uploaded file deleted after sending e-mail
> >
> > Hi,
> >
> > Because of .NET garbage collection, you must be sure that
> > All resources are released before you delete.
> > I suspect a deadlock.
> >
> > Can you comment the File.Delete statement and retry?
> > If this fixes, we can find an other way to solve the temp file deletion.
> >
> > --
> > compatible web farm Session replacement for Asp and Asp.Net
> > http://www.nieropwebconsult.nl/asp_session_manager.htm
> >
> > > File.Delete(strdir+strfilename);
> > > }
> > >
> > > </script>
> > >
> > >
> > >
> > >
> > > <html>
> > >
> > > <head>
> > > <meta http-equiv="Content-Language" content="en-us">
> > > <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> > > <title>Using ASP.NET To Send Email - Part 2</title>
> > > </head>
> > >
> > > <body>
> > >
> > > <div align="center">
> > > <form method = "post" name = "frmemail" runat = "server"
> > > enctype="multipart/form-data" onSubmit = "return Tocheck(this)">
> > > <table border="1" width="637" height="196">
> > > <tr>
> > > <td height="196" width="637" valign="top">
> > >
> > > From : <asp:TextBox ID = "txtFrom" Runat =server></asp:TextBox>
> > > <p>To: <asp:TextBox ID = "txtTo" Runat = server></asp:TextBox>
> > > <p>Subject:<asp:TextBox ID = "txtSubject" Runat = server></asp:TextBox>
> > >
> > > <p>Message:<asp:TextBox runat="server" Height="57px" TextMode="MultiLine"
> > > Width="212px" ID="txtMsg"></asp:TextBox>
> > >
> > >
> > > <p>Attach:<input type = "file" id = "txtFile" runat = "server">
> > >
> > >
> > > <p align="center"><asp:Button Runat = server ID = "btnSubmit" Text =
> > > "SEND" OnClick = "btnSubmit_Click"></asp:Button></td>
> > > </tr>
> > > </table>
> > > </form>
> > > </div>
> > >
> > > </body>
> > >
> > > </html>
> >
> >


Re: Sending Email/Attachment .NET app hangs by VinnieL

VinnieL
Sun Nov 26 06:54:01 CST 2006

Hi David,
Thanks for you quick response. I found this code on the Internet and its
having the same behavior as the developer's code. (so I'm not the developer
of the actual code thats not working for the customer) This is a shared
enviornment with over 300 web sites so we have to be careful about what we
install on the servers, even for troubleshooting. That's why I use DebugDiag,
and I found many issues in the past, for developers using this tool.
Unfortunately these apps are exhibiting the same behavior (they appear to
hang and will eventually time out but no events occur).
If the developer uses the Visual Studio to DEbug it, don't I have to install
it on the server, if yes.... this is something I can't readily do ...its a
shared enviornment. It's not occuring on any other servers, testing or prod.
This is what is unusual about this.
Thanks
Vinnie

"David Wang" wrote:

> Download Visual Web Developer from Microsoft.com and debug your ASP.Net
> application within a Visual Studio environment. You should be able to
> see the exact line of code that is hanging/failing.
>
> DebugDiag is not the appropriate tool. Treat it like a customized
> Visual Studio-like debugger with some automation scripts designed to:
> 1. trigger on "universally bad" events like crashes (or for memory
> leak/hangs, other tell-tale signs)
> 2. recognize common failure patterns (normally, debuggers just tell you
> the raw details - you're supposed to make sense of it)
> 3. and do some automated triage.
>
> It is designed to help system administrators to figure out what code is
> responsible for the observed problem of "crashes, hangs, and memory
> leaks" on a server and get the appropriate developer to fix the issue.
> On the other hand, you happen to be the developer that's supposed to
> fix the issue, so DebugDiag really isn't the tool for you.
>
>
>
> //David
> http://w3-4u.blogspot.com
> http://blogs.msdn.com/David.Wang
> //
>
>
> Vinnie L wrote:
> > Hi Ergbert, Thanks for the assistance.
> > That didn't do it. This is bewildering to me. I gave FULL control to the
> > Anon user, Network Services, Authenticated Users accounts and also Excluded
> > the dir from Application Center Sync to made sure that App Ctr wasn't the
> > cause.
> > What tools can I use to troublesshoot, I tried DebugDiag but the app really
> > isn't crashing or hanging. It will timeout eventuall but there are no dumps
> > on DebugDiag.
> > Vinnie
> >
> > "Egbert Nierop (MVP for IIS)" wrote:
> >
> > >
> > > "Vinnie L" <VinnieL@discussions.microsoft.com> wrote in message
> > > news:592106FF-4459-4C84-97CD-0432483A122F@microsoft.com...
> > > > When sending an attachment with this page the application hangs. The is
> > > > placed on the server but it's never sent and deleted.
> > > > All the permissions seem to ok but I cant seem to find out why this app
> > > > hangs.
> > > >
> > > > Thanks
> > > >
> > > >
> > > > <%@ Page Language="C#" %>
> > > > <%@ Import Namespace="System.Web.Mail" %>
> > > > <%@ Import Namespace="System.IO" %>
> > > >
> > > >
> > > > <script language = "javascript">
> > > > function Tocheck(frmemail) {
> > > > if(frmemail.txtFile.value == "") {
> > > > alert("Please attach a file");
> > > > frmemail.txtFile.focus();
> > > > return(false);
> > > > }
> > > > }
> > > > </script>
> > > >
> > > > <script runat="server">
> > > >
> > > > void btnSubmit_Click(Object sender, EventArgs e) {
> > > >
> > > > MailMessage mail = new MailMessage();
> > > > mail.From = txtFrom.Text;
> > > > mail.To = txtTo.Text;
> > > > mail.Subject = txtSubject.Text;
> > > > mail.Body = txtMsg.Text;
> > > > mail.BodyFormat = MailFormat.Html;
> > > >
> > > > string strdir = "f:\\inetpub\\webtools\\emailtest\\files\\";
> > > > //string strdir = "c:\\temp\\";
> > > >
> > > > string strfilename = Path.GetFileName(txtFile.PostedFile.FileName);
> > > >
> > > > txtFile.PostedFile.SaveAs(strdir+strfilename);
> > > >
> > > > mail.Attachments.Add(new MailAttachment(strdir+strfilename));
> > > >
> > > > try
> > > > {
> > > > SmtpMail.SmtpServer = "mail.fmr.com";
> > > > SmtpMail.Send(mail);
> > > > }
> > > > catch(Exception ex)
> > > > {
> > > > Response.Write("<b>Exception Occured:</b> " +ex);
> > > > }
> > > > finally
> > > > {
> > > > Response.Write("Your E-mail has been sent sucessfully");
> > > > }
> > > >
> > > > // Uploaded file deleted after sending e-mail
> > >
> > > Hi,
> > >
> > > Because of .NET garbage collection, you must be sure that
> > > All resources are released before you delete.
> > > I suspect a deadlock.
> > >
> > > Can you comment the File.Delete statement and retry?
> > > If this fixes, we can find an other way to solve the temp file deletion.
> > >
> > > --
> > > compatible web farm Session replacement for Asp and Asp.Net
> > > http://www.nieropwebconsult.nl/asp_session_manager.htm
> > >
> > > > File.Delete(strdir+strfilename);
> > > > }
> > > >
> > > > </script>
> > > >
> > > >
> > > >
> > > >
> > > > <html>
> > > >
> > > > <head>
> > > > <meta http-equiv="Content-Language" content="en-us">
> > > > <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> > > > <title>Using ASP.NET To Send Email - Part 2</title>
> > > > </head>
> > > >
> > > > <body>
> > > >
> > > > <div align="center">
> > > > <form method = "post" name = "frmemail" runat = "server"
> > > > enctype="multipart/form-data" onSubmit = "return Tocheck(this)">
> > > > <table border="1" width="637" height="196">
> > > > <tr>
> > > > <td height="196" width="637" valign="top">
> > > >
> > > > From : <asp:TextBox ID = "txtFrom" Runat =server></asp:TextBox>
> > > > <p>To: <asp:TextBox ID = "txtTo" Runat = server></asp:TextBox>
> > > > <p>Subject:<asp:TextBox ID = "txtSubject" Runat = server></asp:TextBox>
> > > >
> > > > <p>Message:<asp:TextBox runat="server" Height="57px" TextMode="MultiLine"
> > > > Width="212px" ID="txtMsg"></asp:TextBox>
> > > >
> > > >
> > > > <p>Attach:<input type = "file" id = "txtFile" runat = "server">
> > > >
> > > >
> > > > <p align="center"><asp:Button Runat = server ID = "btnSubmit" Text =
> > > > "SEND" OnClick = "btnSubmit_Click"></asp:Button></td>
> > > > </tr>
> > > > </table>
> > > > </form>
> > > > </div>
> > > >
> > > > </body>
> > > >
> > > > </html>
> > >
> > >
>
>

Re: Sending Email/Attachment .NET app hangs by David

David
Sun Nov 26 16:24:22 CST 2006

Yes, DebugDiag is very useful. Just do not expect it to be able to
resolve 100% of debuggable issues because it is not designed for it.

For example, the "appear to hang and will eventually time out" is not
exactly the same "hang" that DebugDiag is looking for. Hangs do not
show up in the Event Logs because it is technically impossible to
detect correctly.

Well, you're choices are to either:
1. Allow the developer to debug on your server
2. Make the developer debug on their own machine to figure out what's
wrong
3. Debug the issue yourself on your server

Sounds like you are choosing #3.

If you are debugging in proxy for the customer (the developer on your
shared server), then you need to make sure you are actually debugging
the same problem -- and not what looks to be the same. The customer
needs to provide you a short snippet that reproduces the problem. You
should not be looking on the Internet. This way, you know that you are
debugging the actual problem and not just any problem.

Assuming you have the code snippet that reliably reproduces the
problem, you can try to run it on multiple servers to see if server
configuration has anything to do with it. If the problem happens on all
servers, then the code is probably suspect and the developer is
responsible for figuring it out without access to your servers (since
you see it happens on any server, they can debug on their own machine).

If the problem happens on SOME of your servers, then you need to first
examine their code snippet to determine if it is not some latent issue
within the code itself. After the code looks sound, you can start
searching for what is different between your working and non-working
server.

There are many approaches to figure out this difference --
-- you directly know the differences between the servers and identify
the issue
-- you indirectly use tools to tell you the differences between the
servers and identify the issue
-- you attach a debugger onto the code with problems and work backwards
to determine a cause that narrows down which of the differences between
servers cause the issue

Each approach requires different skills and tools, and good
troubleshooters will strategically move between the various approaches
to get to the bottom of things. I would not insist on sticking with any
particular approach or tool to the end -- I recommend knowing the
usefulness boundaries of all tools and approaches.

It sounds like the file is sent from the browser to the server's temp
directory, and then the code sets up the file up as an email attachment
and sends it, and the "hang" happens during send. I would first try
really hard to look at things that could be preventing
SmtpMail.Send(mail) from accessing the file -- is the entire file
completely uploaded and saved BEFORE SmtpMail tries to access and send
it as attachment? Is there anything special running on this server,
like AntiVirus or other file-scanning security software that is
temporarily locking the uploaded file BEFORE SmtpMail tries to access
and send it as attachment? I also did some searching online, and it
looks like System.Web.Mail is deprecated in favor of System.Net.Mail --
you may want to see if that makes any difference

Because I've written Email Sending apps like that before and never seen
such hangs - but then again, the files in my case were long-standing,
not temporary, I did not run AntiVirus during that time, and I was
using System.Net.Mail on .Net Framework 2.0

For example, System.Net.Mail.Attachment allows attachments using a data
stream -- so the best choice there is to use ASP.Net to obtain a stream
of the uploaded file and directly create the Attachment WITHOUT needing
to save and delete the file. In this scenario, you won't need to give
anyone write access to your server, and AntiVirus/scanning issues go
out the window because no files are used.


//David
http://w3-4u.blogspot.com
http://blogs.msdn.com/David.Wang
//



Vinnie L wrote:
> Hi David,
> Thanks for you quick response. I found this code on the Internet and its
> having the same behavior as the developer's code. (so I'm not the developer
> of the actual code thats not working for the customer) This is a shared
> enviornment with over 300 web sites so we have to be careful about what we
> install on the servers, even for troubleshooting. That's why I use DebugDiag,
> and I found many issues in the past, for developers using this tool.
> Unfortunately these apps are exhibiting the same behavior (they appear to
> hang and will eventually time out but no events occur).
> If the developer uses the Visual Studio to DEbug it, don't I have to install
> it on the server, if yes.... this is something I can't readily do ...its a
> shared enviornment. It's not occuring on any other servers, testing or prod.
> This is what is unusual about this.
> Thanks
> Vinnie
>
> "David Wang" wrote:
>
> > Download Visual Web Developer from Microsoft.com and debug your ASP.Net
> > application within a Visual Studio environment. You should be able to
> > see the exact line of code that is hanging/failing.
> >
> > DebugDiag is not the appropriate tool. Treat it like a customized
> > Visual Studio-like debugger with some automation scripts designed to:
> > 1. trigger on "universally bad" events like crashes (or for memory
> > leak/hangs, other tell-tale signs)
> > 2. recognize common failure patterns (normally, debuggers just tell you
> > the raw details - you're supposed to make sense of it)
> > 3. and do some automated triage.
> >
> > It is designed to help system administrators to figure out what code is
> > responsible for the observed problem of "crashes, hangs, and memory
> > leaks" on a server and get the appropriate developer to fix the issue.
> > On the other hand, you happen to be the developer that's supposed to
> > fix the issue, so DebugDiag really isn't the tool for you.
> >
> >
> >
> > //David
> > http://w3-4u.blogspot.com
> > http://blogs.msdn.com/David.Wang
> > //
> >
> >
> > Vinnie L wrote:
> > > Hi Ergbert, Thanks for the assistance.
> > > That didn't do it. This is bewildering to me. I gave FULL control to the
> > > Anon user, Network Services, Authenticated Users accounts and also Excluded
> > > the dir from Application Center Sync to made sure that App Ctr wasn't the
> > > cause.
> > > What tools can I use to troublesshoot, I tried DebugDiag but the app really
> > > isn't crashing or hanging. It will timeout eventuall but there are no dumps
> > > on DebugDiag.
> > > Vinnie
> > >
> > > "Egbert Nierop (MVP for IIS)" wrote:
> > >
> > > >
> > > > "Vinnie L" <VinnieL@discussions.microsoft.com> wrote in message
> > > > news:592106FF-4459-4C84-97CD-0432483A122F@microsoft.com...
> > > > > When sending an attachment with this page the application hangs. The is
> > > > > placed on the server but it's never sent and deleted.
> > > > > All the permissions seem to ok but I cant seem to find out why this app
> > > > > hangs.
> > > > >
> > > > > Thanks
> > > > >
> > > > >
> > > > > <%@ Page Language="C#" %>
> > > > > <%@ Import Namespace="System.Web.Mail" %>
> > > > > <%@ Import Namespace="System.IO" %>
> > > > >
> > > > >
> > > > > <script language = "javascript">
> > > > > function Tocheck(frmemail) {
> > > > > if(frmemail.txtFile.value == "") {
> > > > > alert("Please attach a file");
> > > > > frmemail.txtFile.focus();
> > > > > return(false);
> > > > > }
> > > > > }
> > > > > </script>
> > > > >
> > > > > <script runat="server">
> > > > >
> > > > > void btnSubmit_Click(Object sender, EventArgs e) {
> > > > >
> > > > > MailMessage mail = new MailMessage();
> > > > > mail.From = txtFrom.Text;
> > > > > mail.To = txtTo.Text;
> > > > > mail.Subject = txtSubject.Text;
> > > > > mail.Body = txtMsg.Text;
> > > > > mail.BodyFormat = MailFormat.Html;
> > > > >
> > > > > string strdir = "f:\\inetpub\\webtools\\emailtest\\files\\";
> > > > > //string strdir = "c:\\temp\\";
> > > > >
> > > > > string strfilename = Path.GetFileName(txtFile.PostedFile.FileName);
> > > > >
> > > > > txtFile.PostedFile.SaveAs(strdir+strfilename);
> > > > >
> > > > > mail.Attachments.Add(new MailAttachment(strdir+strfilename));
> > > > >
> > > > > try
> > > > > {
> > > > > SmtpMail.SmtpServer = "mail.fmr.com";
> > > > > SmtpMail.Send(mail);
> > > > > }
> > > > > catch(Exception ex)
> > > > > {
> > > > > Response.Write("<b>Exception Occured:</b> " +ex);
> > > > > }
> > > > > finally
> > > > > {
> > > > > Response.Write("Your E-mail has been sent sucessfully");
> > > > > }
> > > > >
> > > > > // Uploaded file deleted after sending e-mail
> > > >
> > > > Hi,
> > > >
> > > > Because of .NET garbage collection, you must be sure that
> > > > All resources are released before you delete.
> > > > I suspect a deadlock.
> > > >
> > > > Can you comment the File.Delete statement and retry?
> > > > If this fixes, we can find an other way to solve the temp file deletion.
> > > >
> > > > --
> > > > compatible web farm Session replacement for Asp and Asp.Net
> > > > http://www.nieropwebconsult.nl/asp_session_manager.htm
> > > >
> > > > > File.Delete(strdir+strfilename);
> > > > > }
> > > > >
> > > > > </script>
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > <html>
> > > > >
> > > > > <head>
> > > > > <meta http-equiv="Content-Language" content="en-us">
> > > > > <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> > > > > <title>Using ASP.NET To Send Email - Part 2</title>
> > > > > </head>
> > > > >
> > > > > <body>
> > > > >
> > > > > <div align="center">
> > > > > <form method = "post" name = "frmemail" runat = "server"
> > > > > enctype="multipart/form-data" onSubmit = "return Tocheck(this)">
> > > > > <table border="1" width="637" height="196">
> > > > > <tr>
> > > > > <td height="196" width="637" valign="top">
> > > > >
> > > > > From : <asp:TextBox ID = "txtFrom" Runat =server></asp:TextBox>
> > > > > <p>To: <asp:TextBox ID = "txtTo" Runat = server></asp:TextBox>
> > > > > <p>Subject:<asp:TextBox ID = "txtSubject" Runat = server></asp:TextBox>
> > > > >
> > > > > <p>Message:<asp:TextBox runat="server" Height="57px" TextMode="MultiLine"
> > > > > Width="212px" ID="txtMsg"></asp:TextBox>
> > > > >
> > > > >
> > > > > <p>Attach:<input type = "file" id = "txtFile" runat = "server">
> > > > >
> > > > >
> > > > > <p align="center"><asp:Button Runat = server ID = "btnSubmit" Text =
> > > > > "SEND" OnClick = "btnSubmit_Click"></asp:Button></td>
> > > > > </tr>
> > > > > </table>
> > > > > </form>
> > > > > </div>
> > > > >
> > > > > </body>
> > > > >
> > > > > </html>
> > > >
> > > >
> >
> >


Re: Sending Email/Attachment .NET app hangs by Steve

Steve
Sun Nov 26 23:01:43 CST 2006

I would check the IIS server to ensure it is not blocking the size of your
attachment causing the error. This is configurable on the SMTP portion of
the server. I would try getting it working locally first before putting on
the server. Consider what types and size of attachments being sent.

'How to send attachments in asp.net.
http://www.systemnetmail.com/faq/3.4.1.aspx

Tx,

Steve Schofield
Microsoft MVP - IIS


"Vinnie L" <VinnieL@discussions.microsoft.com> wrote in message
news:592106FF-4459-4C84-97CD-0432483A122F@microsoft.com...
> When sending an attachment with this page the application hangs. The is
> placed on the server but it's never sent and deleted.
> All the permissions seem to ok but I cant seem to find out why this app
> hangs.
>
> Thanks
>
>
> <%@ Page Language="C#" %>
> <%@ Import Namespace="System.Web.Mail" %>
> <%@ Import Namespace="System.IO" %