This is working on my local computer but not on the ASPnix server

This post has 13 Replies | 1 Follower

Top 50 Contributor
Posts 34
Points 710
devbanana Posted: Wed, May 31 2006 4:57 AM

hi,

 

I have been trying to create an error handler to send me mail whenever an error occurs. This error handler is finally working ok on my local computer, but not so on the web site itself when I upload it.

 

The environment between the two are almost exactly the same. The local even uses the remote database, and the smtp tag of the configuration file uses my SMTP information for my web site. So nothing should need changed when it is uploaded, as long as I'm allowed to set the port, because on my local computer port 25 is blocked, so I have it using 587.

 

This error handler is compiled into a DLL and placed into bin.

 

Maybe if I show the code, someone can see what is wrong? It's nto giving an error, the mail just isn't being sent once I upload the site and provoke an error, such as going to a non-existent page.

 

Err, how do you post code here? I know of no code tags :(. I'm just going to paste it, and if there is some formatting to use, either someone who can change it, please do so, or tell me and I'll edit.

 

using System;

using System.IO;

using System.Net;

using System.Net.Mail;

using System.Reflection;

using System.Text;

using System.Threading;

using System.Web;

namespace Banana.ErrorHandling

{

/// <summary>

/// Logs uncaught exceptions via e-mail

/// </summary>

public class EmailErrorHandlerModule : IHttpModule

{

#region IHttpModule Members

public void Dispose()

{

}

public void Init(HttpApplication context)

{

context.Error += new EventHandler(OnError);

}

public void OnError(Object sender, EventArgs e)

{

HttpContext context = HttpContext.Current;

MailMessage mailMessage = new MailMessage(

new MailAddress("webmaster@devbanana.com", "Dev Banana"),

new MailAddress("webmaster@devbanana.com", "Dev Banana")

);

mailMessage.Subject = "Error on Dev Banana";

mailMessage.Body = File.ReadAllText(context.Server.MapPath("~/App_Data/MailMessages/Error.txt"));

mailMessage.Body = ReplaceTemplateVariables(mailMessage.Body);

mailMessage.IsBodyHtml = true;

mailMessage.Priority = MailPriority.High;

SmtpClient smtpClient = new SmtpClient();

smtpClient.Send(mailMessage);

}

private string ReplaceTemplateVariables(string message)

{

HttpContext context = HttpContext.Current;

Exception exception = context.Server.GetLastError();

message = message.Replace("<%Date%>", DateTime.Now.ToUniversalTime().ToLongDateString());

message = message.Replace("<%Time%>", DateTime.Now.ToUniversalTime().ToLongTimeString());

message = message.Replace("<%RequestedUrl%>", context.Request.Url.ToString());

message = message.Replace("<%MachineName%>", Environment.MachineName);

message = message.Replace("<%ExceptionSource%>", exception.Source);

message = message.Replace("<%ExceptionType%>", exception.GetType().FullName);

message = message.Replace("<%ExceptionMessage%>", exception.Message);

message = message.Replace("<%ExceptionStackTrace%>", context.Server.HtmlEncode(exception.StackTrace));

message = message.Replace("<%CallStack%>", context.Server.HtmlEncode(Environment.StackTrace));

message = message.Replace("<%ApplicationDomainName%>", AppDomain.CurrentDomain.FriendlyName);

message = message.Replace("<%AssemblyName%>", Assembly.GetCallingAssembly().FullName);

message = message.Replace("<%ThreadID%>", Thread.CurrentThread.ManagedThreadId.ToString());

message = message.Replace("<%ThreadUser%>", Thread.CurrentPrincipal.ToString());

return message;

}

#endregion

}

}

  • | Post Points: 25
Top 50 Contributor
Posts 46
Points 930
Keyvan replied on Thu, Jun 1 2006 3:22 AM

I had a problem with my HTTP module on one of my sites. It just gave back an error without any information about the reason.

I think it can be an issue about HTTPModules in ASP.NET 2.0 on ASPnix.

But for you, please check that you have configured SMTP server in Web.Config manually or from website configuration tool.

  • | Post Points: 25
Top 50 Contributor
Posts 34
Points 710

Quite interesting. Why wouldn't http modules work?

 

Yeah, I have the SMTP section of web.config configured just fine. Like I said, I have it so I won't have to change those settings even when I upload it.

 

Does anyone know if applications using the Enterprise Library can work OK on ASPnix? It seems like it'll be a lot easier to use that.

 

thanks for the response.

  • | Post Points: 25
Top 10 Contributor
Posts 1,718
Points 30,875
I am not sure if this is why but remember we are running asp.net 2 in medium trust.  Also if this is some sort of handler than maybe it will need to be setup by us if it's not one of the default handlers that you can configure it Helm.
Rick
  • | Post Points: 45
Top 50 Contributor
Posts 46
Points 930
Keyvan replied on Thu, Jun 1 2006 10:16 AM

HTTPModules are not handler indeed but they are being proceed in a same process as handlers.

It can be caused by medium trust but can I add that famous line to my web.config or you have disabled it via machine.config?

  • | Post Points: 25
Top 10 Contributor
Posts 1,718
Points 30,875

If you mean the medium trust line then no sorry it's disabled in the config. Do you have a suggestion?

Rick
  • | Post Points: 25
Top 50 Contributor
Posts 34
Points 710

It's just an http module, which you're supposed to be able to set up in web.config.

 

I don't know; is there something in the code I posted that cannot be executed in medium trust?

 

*DevBanana thinks he needs to get a VPS so he can do more messing around with configuration

  • | Post Points: 5
Top 50 Contributor
Posts 34
Points 710

hi,

 

Well, I am now using the Enterprise Library to do these tasks, and it worked wonderfully on my computer, very nicely, yet when I upload it, well: http://www.devbanana.com [:9]

 

Is there someone from support who might be able to take a look at the error at their convenience? This is quite impossible for me, and annoying too, lol.

  • | Post Points: 25
Top 10 Contributor
Posts 1,718
Points 30,875

I can look at it tomorrow maybe because we are very busy with a server issue and normally we don't support code but I will try for you. Smile

 

Rick
  • | Post Points: 25
Top 50 Contributor
Posts 34
Points 710

That's no problem, and I understand...

 

I'm going to try to upgrade to a VPS so I don't have to worry about permissions and configuration limitations and so I can get more experience setting up this kind of thing, for future purposes. But I'm not positive yet. I'm trying to keep costs as low as I possibly can but still not limit myself too much. And given I do a lot of development and testing, a VPS might be better. I asked a question in a ticket I just o pened about vpses

  • | Post Points: 5
Top 50 Contributor
Posts 46
Points 930
Keyvan replied on Fri, Jun 2 2006 9:37 AM
The Wizard:

If you mean the medium trust line then no sorry it's disabled in the config. Do you have a suggestion?

Rick, can you enable custom policy for some operations in web.config?

This is my suggestion to enable some operations in custom policy. If you disable this completely, probably no one can use HTTPModules in his/her application.

  • | Post Points: 25
Top 10 Contributor
Posts 1,718
Points 30,875
Everything we have set now is for security reasons, I am sure most of those changes would or might open us up to other vulnerablities so unless someone has a specific idea then things will stay the way they are but we alway welcome feedback or ideas from those who know. Smile



Rick
  • | Post Points: 25
Top 50 Contributor
Posts 46
Points 930
Keyvan replied on Fri, Jun 2 2006 2:10 PM

I sent a blog post about this issue:

http://nayyeri.net/archive/2006/06/02/938.aspx

Please keep up the conversation to get a good result. We need to solve this anyway. I asked Scott Guthrie to give a short description about this.

  • | Post Points: 25
Top 10 Contributor
Posts 1,718
Points 30,875

After reading your blog post I want to tell you something to help you understand why shared hosts run in Medium Trust.

When we first deployed ASP.NET 2 on our servers it was set to Full Trust and some wonderful client who is no longer with us ran a nicely crafted ASP.NET script and deleted all domain web files on the server he was on and this is why we went to Medium Trust and I might add that we are using a slightly customized version of Medium Trust to allow file IO access and DNN 4 runs fine on our config so the DNN core team has found a way to make it work so it's very possible without the server config being changed. Wink

 

Rick
  • | Post Points: 5
Page 1 of 1 (14 items) | RSS
©2003-2009 ASPnix, an Anaxa Company. All rights reserved. Privacy Policy. Terms of Service. SLA.