Miguelangelgonzalez

Sin viento, el pasto no se mueve. Sin software, el hardware es inútil.

Posts etiquetados ‘ASP.NET 2.0’

Error Unable to connect to Visual Stutio’s localhost web server

Publicado por Miguel Gonzalez en 8 Enero 2009

El Problema

Yo tengo este problema en Visual Studio 2005 despues de instalar Visual Studio 2008 y he leido que pasa tambien luego de instalar Visual Web Developer 2008 cuando quiero realizar el debugging de mi aplicacion web sale un mensaje diciendo que Visual Studio no se puede conectar con el el web server (cassini en vs2005) por el puerto xxx por que ya esta en uso, lo primero que hice es comprobar esto con el comando “netstat” y el numero de puerto esta libre.

Por ejemplo el cassini web development server que viene con vs2005 cuando inicia puedo ver el numero de puerto en uso en el area de notificaciones.

port-number

En lugar de hacer esto me aparece un cartel con el siguiente mensaje “Unable to connect to Visual Studio’s Localhost Web Server…”

La Solucion

El problema en mi caso es un filtro en el firewall que es parte del softwasre ESET Smart Security Suite.  Pasos para la solucion:

  1. Si estas usando  ESET Smart Security Suite entonces puede que este usando el protocilo de filtro( debes fijarte en la configuracion avanzada del firewall).
  2. En la configuracion avanzada necesitas localizar la seccion mostrada en la imagen debajo y deschequear el web development server.setup-dialog
  3. Asegurate de parar el web development server si aun este esta corriendo y trata de debuguear desde Visual Studio nuevamente.
  4. Otra forma de levantar el web development server es  atravez de linea de comando de esta forma
    WebDev.WebServer /port:7171 /path:"F:\My Web Site"

Post original: Visual Studio development web server dynamic port numbering problem

Publicado en ASP.NET | Etiquetado: , | Deja un Comentario »

Log4net con Gmail

Publicado por Miguel Gonzalez en 23 Diciembre 2008

Como el servidor de correo de gmail tiene ssl tenemos que realizar unos ajustes en una clase personalizada para tal fin. Para esto vamos a heredar de log4net.Appender.SmtpAppender para agregar estas nuevas caracteristicas. De esta forma nace la clase MyApp.SmtpSslAppender que usaremos siempre que queramos enviar nuestro logs atraves de una cuenta gmail.

public class SmtpSslAppender : log4net.Appender.SmtpAppender
{
private bool m_enableSsl = true;
public bool EnableSsl
{
get{return m_enableSsl;}
set{this.m_enableSsl = value;}
}

protected override void SendEmail(string messageBody) {
SmtpClient smtpClient = new SmtpClient();
if( SmtpHost != null & SmtpHost.Length > 0 ){
smtpClient.Host = SmtpHost;
}

smtpClient.Port = Port;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = EnableSsl;

if( Authentication == SmtpAuthentication.Basic ){
smtpClient.Credentials = new System.Net.NetworkCredential(Username, Password);
}else if( Authentication == SmtpAuthentication.Ntlm ){
smtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
}

MailMessage mailMessage = new MailMessage();
mailMessage.Body = messageBody;
mailMessage.From = new MailAddress(From);
mailMessage.To.Add(To);
mailMessage.Subject = Subject;
mailMessage.Priority = Priority;

smtpClient.Send(mailMessage);
}
}

A continuacion se ve como dentro del web.config se hace uso de esta nueva clase.

<appender name=”SmtpSslAppender” type=”MyApp.SmtpSslAppender”>
<to value=”xxx@gmail.com” />
<from value=”yyy@gmail.com” />
<subject value=”LoggerName” />
<smtpHost value=”smtp.gmail.com” />
<bufferSize value=”1″ />
<port value=”587″ />
<lossy value=”false” />
<authentication value=”Basic” />
<userName value=”usuario” />
<password value=”clave” />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%newline%date [%thread] %-5level %logger [%property{NDC}] – %message%newline%newline%newline” />
</layout>
<filter type=”log4net.Filter.LevelRangeFilter”>
<levelMin value=”FATAL”/>
<levelMax value=”FATAL”/>
</filter>
</appender>

Publicado en Log4net | Etiquetado: , , | 1 comentario

Log4net con Exchange

Publicado por Miguel Gonzalez en 22 Diciembre 2008

Para realizar esto primero tenemos que crear una clase personalizada para tal fin. Para esto vamos a heredar de “log4net.Appender.SmtpAppender” para agregar esta nueva caracteristica. De esta forma nace la clase “MyApp.ExchangeAppender” que usaremos siempre que queramos enviar nuestro logs atraves de una cuenta exchange. Aqui tiene la clase que yo utilizo para esto.

using System;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace MyApp
{
public class ExchangeAppender : log4net.Appender.SmtpAppender
{
protected override void SendEmail(string messageBody)
{
try
{
string sUri;
sUri = “https://miservidor/exchange/” + Username;
sUri = sUri + “/%23%23DavMailSubmissionURI%23%23″;

System.Uri myUri = new System.Uri(sUri);
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri);
string sQuery;
sQuery = “From: ” + From + “n” +
“To: ” + To + “n” +
//”CC: ” + cc + “n” +
“Subject: ” + Subject + “n” +
“Date: ” + DateTime.Now.ToString() + “n” +
“X-Mailer: My DAV mailer” + “n” +
“MIME-Version: 1.0″ + “n” +
“Content-Type: text/plain;” + “n” +
“Charset = “iso-8859-1″” + “n” +
“Content-Transfer-Encoding: 7bit” + “n” + “n” +
messageBody;
// Set the credentials.
// TODO: Replace with the appropriate user credential.
NetworkCredential myCred = new NetworkCredential(Username, Password);
CredentialCache myCredentialCache = new CredentialCache();
myCredentialCache.Add(myUri, “Basic”, myCred);
HttpWRequest.Credentials = myCredentialCache;
// Set the headers.
HttpWRequest.Headers.Set(“Translate”, “f”);
HttpWRequest.ContentType = “message/rfc822″;
HttpWRequest.ContentLength = sQuery.Length;
//Set the request timeout to 5 minutes.
HttpWRequest.Timeout = 300000;
// Set the request method.
HttpWRequest.Method = “PUT”;
// Store the data in a byte array.
byte[] ByteQuery = System.Text.Encoding.ASCII.GetBytes(sQuery);
HttpWRequest.ContentLength = ByteQuery.Length;
Stream QueryStream = HttpWRequest.GetRequestStream();
// write the data to be posted to the Request Stream
QueryStream.Write(ByteQuery, 0, ByteQuery.Length);
QueryStream.Close();
// Send the request and get the response.
HttpWebResponse HttpWResponse =(HttpWebResponse)HttpWRequest.GetResponse();
// Get the Status code.
int iStatCode = (int)HttpWResponse.StatusCode;
string sStatus = iStatCode.ToString();
//log.DebugFormat(“Status Code: {0}”, sStatus);
// Get the request headers.
string sReqHeaders = HttpWRequest.Headers.ToString();
//log.Debug(sReqHeaders);
// Read the response stream.
Stream strm = HttpWResponse.GetResponseStream();
StreamReader sr = new StreamReader(strm);
string sText = sr.ReadToEnd();
// Close the stream.
strm.Close();
// Clean up.
myCred = null;
myCredentialCache = null;
HttpWRequest = null;
HttpWResponse = null;
QueryStream = null;
strm = null;
sr = null;
}
catch (Exception e)
{throw new Exception(e.Message);}
}
}
}

Y aqui tienen la configuracion correspondiente:

<appender name=”ExchangeAppender” type=”MyApp.ExchangeAppender”>
<to value=”xxx@dominio.com” />
<from value=”yyy@dominio.com” />
<subject value=”Asunto” />
<bufferSize value=”1″ />
<port value=”587″ />
<lossy value=”false” />
<authentication value=”Basic” />
<userName value=”usuario_exchange” />
<password value=”clave_exchange” />
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%newline%date [%thread] %-5level %logger [%property{NDC}] – %message%newline%newline%newline” />
</layout>
<filter type=”log4net.Filter.LevelRangeFilter”>
<levelMin value=”FATAL”/>
<levelMax value=”FATAL”/>
</filter>

Publicado en Log4net | Etiquetado: , , , | Deja un Comentario »