Archive for March 8th, 2008

How to use an AdRotator in ASP.NET?

Saturday, March 8th, 2008

The AdRotator control is used to display a sequence of ad images.

This control uses an XML file to store the ad information. The XML file must begin and end with an <Advertisements> tag. Inside the <Advertisements> tag there may be several <Ad> tags which defines each ad.

<asp:AdRotator id=”AdRotator1″ AdvertisementFile=”adrot.xml”
runat=”server” Width=”468px” Height=”60px”></asp:AdRotator>

adrot.xml
<Advertisements>
<Ad>
<ImageUrl>b2346.jpg</ImageUrl>
<NavigateUrl>http://ww.tryangled.com</NavigateUrl>
<AlternateText>
The site for ASP.Net FAQs
</AlternateText>
<Impressions>5</Impressions>
</Ad>
</Advertisements>

Posted by Mahesh ( Tryangled )

How do I send non US-ASCII mails?

Saturday, March 8th, 2008

To send US-ASCII mail using encoding method.

VB.NET
mail.BodyEncoding = System.Text.Encoding.GetEncoding( “ISO-2022-JP” )
C#
mail.BodyEncoding = System.Text.Encoding.GetEncoding( “ISO-2022-JP” );

Posted by Mahesh ( Tryangled )

What is the namespace used for sending mails?

Saturday, March 8th, 2008

Use System.Web.Mail

The System.Web.Mail namespace contains classes that enable you to construct and send messages using the CDOSYS (Collaboration Data Objects for Windows 2000) message component. The mail message is delivered either through the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server. The classes in this namespace can be used from ASP.NET or from any managed application.
For more details refer System.Web.Mail Namespace

Posted by Mahesh ( Tryangled )

Why do I get the error message “Sender address rejected: need fully-qualified address?

Saturday, March 8th, 2008

This is happening because your SmtpMail.SmtpServer is rejecting addresses.
To resolve this make sure
* all email addresses specified at MailMessage.To, MailMessage.Cc, MailMessage.Bcc and MailMessage.From are valid email addresses
* you have permissions to relay through the server.
* MailMessage.From has permissions to relay through the server

Posted by Mahesh ( Tryangled )

How do I configure a local SMTP server?

Saturday, March 8th, 2008

Install the SMTP virtual server that is part of IIS.
* You will need your Windows installation CD.
* Use Add or Remove Programs in the Windows Control Panel to launch Add/Remove Windows Components.
* Select Internet Information Services (IIS) and then click Details.
* Check SMTP Service and then click OK.
* The installation process will prompt you for your Windows CD and will install the SMTP virtual server.

After installing the SMTP server (also reboot), configure it by following these steps:

1. In the Control Panel, choose Administrative Tools, and then choose Internet Information Services.
2. Open the node for your computer, right-click the Default SMTP Virtual Server node and choose Properties.
3. In the Access tab, click Connection.
4. Select Only the list below, click Add and add the IP 127.0.0.1. This restricts connections to just the local computer, i.e., localhost. Close the Connection dialog box.
5. Click Relay and repeat Step 5 to allow only localhost to relay through this server.
In your firewall or router (or both), close incoming port 25. This is an important         security measure that will prevent spammers from finding your SMTP server and using it to relay spam.

Posted by Mahesh ( Tryangled )

Can I use IIS as an alternative way of configuring Custom error pages?

Saturday, March 8th, 2008

Yes, you can. But the preferable way would be ASP.NET, as the ASP.NET custom pages are configured in XML based web.config (application configuration) file, resulting in easy (xcopy) deployment and management.

Posted by Mahesh ( Tryangled )

In Visual Studio .NET, how do I create a new ASP.NET application for an existing ASP.NET project?

Saturday, March 8th, 2008

First create an IIS application using the IIS MMC. Then in Visual Studio .NET, use the “New Project In Existing Folder” project template (at the end of the template list). It will first ask you for the project name (use the same one you created for the IIS application). Click OK button. Then enter in physical folder location.

Posted by Mahesh ( Tryangled )

How can I have a particular Web page in an ASP.NET application which displays its own error page.

Saturday, March 8th, 2008

This can be done by setting the ErroPage attribute of Page Directive or ErrorPage property of Page Class to the desired Custom Error Page
<%@Page Language=”C#” ErrorPage=”tryspecificerropage.htm”%>
In web.config
<customErrors mode=”On” />

Posted by Mahesh ( Tryangled )

Why do I get the error message “Object must implement IConvertible”. How can I resolve it?

Saturday, March 8th, 2008

The common cause for this error is specifying a control as a SqlParameter’s Value instead of the control’s text value.
For example, if you write code as below you’ll get the above error:
VB.NET
Dim nameParameter As SqlParameter = command.Parameters.Add(”@name”, SqlDbType.NVarChar, 50)
nameParameter.Value = txtName

C#
SqlParameter nameParameter = command.Parameters.Add(”@name”, SqlDbType.NVarChar, 50);
nameParameter.Value = txtName ;

To resolve it, specify the control’s Text property instead of the control itself.

VB.NET
nameParameter.Value = txtName.Text
C#
nameParameter.Value =txtName.Text;

Posted by Mahesh ( Tryangled )

What is the difference between Response.Redirect() and Server.Transfer().

Saturday, March 8th, 2008

Response.Redirect
* Tranfers the page control to the other page, in other words it sends the request to the other page.
* Causes the client to navigate to the page you are redirecting to.
Server.Transfer
* Only transfers the execution to another page and during this you will see the URL of the old page since only execution is transfered to new page and not control.
* Occurs entirely on the server, no action is needed by the client.

Posted by Mahesh ( Tryangled )