<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Behan's Blog &#187; ASP/SQL/JS Code</title>
	<atom:link href="http://www.davidbehan.com/blog/index.php/category/aspsql-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidbehan.com/blog</link>
	<description>David Behan's Blog on web design, the Internet, business and company news</description>
	<lastBuildDate>Wed, 23 Dec 2009 10:32:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ASP: NON-WWW 301 Redirect on IIS</title>
		<link>http://www.davidbehan.com/blog/non-www-301-redirect-on-iis/</link>
		<comments>http://www.davidbehan.com/blog/non-www-301-redirect-on-iis/#comments</comments>
		<pubDate>Tue, 29 May 2007 07:44:03 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[ASP/SQL/JS Code]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Marketing]]></category>

		<guid isPermaLink="false">http://www.davidbehan.com/blog/?p=34</guid>
		<description><![CDATA[I was doing some research on how to do a non-www 301 redirect on a Windows IIS server and I found the usual response.status and response.addheader solution, which also required access to IIS for spliting up the www and non-www part of your domain. If you are on a shared server, this isn&#8217;t always possible. [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing some research on how to do a non-www 301 redirect on a Windows IIS server and I found the usual response.status and response.addheader solution, which also required access to IIS for spliting up the www and non-www part of your domain. If you are on a shared server, this isn&#8217;t always possible. I wanted a pure code version of the redirect that I could drop into my pages so that if somebody visited a page on the site that had sub folders and/or querystrings without the www part, it would preserve these and redirect to the www version. I couldn&#8217;t find exactly what I was looking for  so I decided to write my own in ASP.</p>
<p>The script below should be inserted into the top of all the pages you want this to work. The best way to do this is using an include file or adding it to the top of one of your existing include files that runs before anything is written to the page. The pages also need to be ASP. This will not work on plain html pages. This isn&#8217;t a perfect solution as it will only work on actual pages but it will help a lot of people out there I think. On linux, this is much easier using the htaccess solution but as IIS doesn&#8217;t have this, this is a good alternative. If www exists in the URL, this script will not execute. You may want to do the same in reverse, as in redirect www to non-www URL&#8217;s. If there is a demand for this, I&#8217;ll modify the script to support it.</p>
<p><span id="more-34"></span></p>
<p>You can see a working example of this by trying to visit <a href="http://davidbehan.com/?test=ok">http://davidbehan.com/?test=ok</a>. It should redirect to <a href="http://www.davidbehan.com/?test=ok">http://www.davidbehan.com/?test=ok</a>.</p>
<div class="code-block">
<p><span class="code-comment">&#8216;Collect url information being requested</span><br />
	svrHttps = request.servervariables(&quot;HTTPS&quot;)<br />
	svrHost = request.servervariables(&quot;HTTP_HOST&quot;)<br />
	svrUrl = request.servervariables(&quot;URL&quot;)<br />
	svrQueryString = request.servervariables(&quot;QUERY_STRING&quot;)</p>
<p><span class="code-comment">&nbsp;<br />&#8216;Check if www appears in the domain and begin building url to redirect to if it doesn&#8217;t</span><br />
	IF left(svrHost,4) &lt;&gt; &quot;www.&quot; THEN</p>
<blockquote>
<p><span class="code-comment">&nbsp;<br />&#8216;Check if the page is secure or not</span><br />
		IF svrHttps = &quot;off&quot; THEN</p>
<blockquote>
<p>svrNewUrl = &quot;http://www.&quot;</p>
</blockquote>
<p>ELSE</p>
<blockquote>
<p>svrNewUrl = &quot;https://www.&quot;</p>
</blockquote>
<p>END IF</p>
<p><span class="code-comment">&nbsp;<br />&#8216;Add the domain, folder(s) and page requested as well as remove directory indexes</span><br />
		svrNewUrl = svrNewUrl &amp; svrHost &amp; svrUrl<br />
		svrNewUrl = replace(svrNewUrl,&quot;default.asp&quot;,&quot;&quot;)<br />
		svrNewUrl = replace(svrNewUrl,&quot;index.asp&quot;,&quot;&quot;)</p>
<p><span class="code-comment">&nbsp;<br />&#8216;If there is a querystring, add it to the redirect link</span><br />
		IF len(svrQueryString) &gt; 0 THEN</p>
<blockquote>
<p>svrNewUrl = svrNewUrl &amp; &quot;?&quot; &amp; svrQueryString</p>
</blockquote>
<p>END IF</p>
<p><span class="code-comment">&nbsp;<br />
		&#8216;Do the actual 301 redirect to the newly constructed url</span><br />
		response.status = &quot;301 Moved Permanently&quot;<br />
		response.addheader &quot;Location&quot;, svrNewUrl<br />
		response.end</p>
</blockquote>
<p>&nbsp;<br />END IF</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.davidbehan.com/blog/non-www-301-redirect-on-iis/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Test in IE7 and IE6 using VPC on the same machine</title>
		<link>http://www.davidbehan.com/blog/test-in-ie7-and-ie6-using-vpc-on-the-same-machine/</link>
		<comments>http://www.davidbehan.com/blog/test-in-ie7-and-ie6-using-vpc-on-the-same-machine/#comments</comments>
		<pubDate>Mon, 04 Dec 2006 14:13:41 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[ASP/SQL/JS Code]]></category>
		<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://www.davidbehan.com/blog/?p=20</guid>
		<description><![CDATA[Microsoft release VPC to test your sites in IE6 and IE7 from the same machine]]></description>
			<content:encoded><![CDATA[<p>Ok, IE7 was released recently and for a lot of designers/developers out there it means having to use two machines to do the testing or using hacks (that don&#8217;t work 100%). Microsoft have just released a FREE Virtual PC containing a pre-activated Windows XP SP2, with IE6 and the IE7 Readiness Toolkit to allow you to easily test in both IE6 and IE7 on the same machine.</p>
<p><a rel="lightbox" href="http://www.davidbehan.com/_images/blog/ie6ie7/ie6ie7ff2.jpg"><img width="160" height="128" border="0" alt="ie6ie7ff2.jpg" title="ie6ie7ff2.jpg" class="tn" src="http://www.davidbehan.com/_images/blog/ie6ie7/.thumbs/.ie6ie7ff2.jpg" /></a></p>
<p>Read about the release at the <a target="_blank" href="http://blogs.msdn.com/ie/archive/2006/11/30/ie6-and-ie7-running-on-a-single-machine.aspx">IEBlog</a> or <a target="_blank" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&#038;displaylang=en">download</a> it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidbehan.com/blog/test-in-ie7-and-ie6-using-vpc-on-the-same-machine/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP Send E-Mail Function</title>
		<link>http://www.davidbehan.com/blog/asp-send-mail-function/</link>
		<comments>http://www.davidbehan.com/blog/asp-send-mail-function/#comments</comments>
		<pubDate>Fri, 27 Oct 2006 16:44:57 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[ASP/SQL/JS Code]]></category>

		<guid isPermaLink="false">http://www.davidbehan.com/blog/?p=8</guid>
		<description><![CDATA[ASP Function for sending mail using CDONTS, JMAIL, ASPEmail, ASPMail, etc]]></description>
			<content:encoded><![CDATA[<p>This neat little ASP send mail function can be included and called to quickly send e-mails using CDONTS, CDOSYS, ASPMail, ASPEmail, Dundas Mailer or Jmail. All you need to do is copy the code below into a file, say sendmail.asp and include that file in any page you want to send a mail in.</p>
<p><strong>Copy the following lines of code into sendmail.asp:</strong></p>
<pre><code>&lt; %
'--------------------------------------
'Notes - Read Me!
'--------------------------------------
'sToName - can be any type of text string, e.g. Joe Bloggs
'sToAddress - must be a valid email address as this is the email address the mail will be sent, e.g. joe@bloggs.com
'sFromName - can be any type of text string, e.g. Mary Bloggs
'sFromAddress - must be a valid email address as this is the email address the mail will come from, e.g. mary@bloggs.com
'sSubject - can be any type of text string, e.g. July Newsletter
'sContent - this is the actual body content of the email. can be html or just text, just make sure you have set the correct mail body settings
'sFormat - enter 'html' or 'text'
'sImportance - enter 'high', 'normal' or 'low'

sComponent = "jmail" 'can be cdonts, cdosys, aspmail, aspemail, dundas, jmail
sMailServer = "mail.yourdomain.com"

FUNCTION SendMail(sToName, sToAddress, sFromName, sFromAddress, sSubject, sContent, sFormat, sImportance)

SELECT CASE sComponent

'-------------------------------
'CDONTS - www.microsoft.com
'-------------------------------
CASE "cdonts"

SET objMail = Server.CreateObject("CDONTS.NewMail")

IF sFormat = "text" THEN
objMail.BodyFormat = 1
objMail.MailFormat = 1
ELSE
objMail.BodyFormat = 0
objMail.MailFormat = 0
END IF

IF sImportance = "high" THEN
objMail.Importance = 2
ELSEIF sImportance = "low" THEN
objMail.Importance = 0
ELSE
objMail.Importance = 1
END IF

objMail.From = sFromName &amp; "&lt;" &amp; sFromAddress &amp; "&gt;"
objMail.To = sToName &amp; "&lt; " &amp; sToAddress &amp; "&gt;"
objMail.Subject = sSubject
objMail.Body = sContent
objMail.Send

'-------------------------------
'CDONTS - www.microsoft.com
'-------------------------------
CASE "cdosys"

SET objMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject ("CDO.Configuration")

objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServer 'change this to your websites mail domain
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")  = 25
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
Set objMail.Configuration = objConfig

IF sFormat = "text" THEN
objMail.TextBody = sContent
ELSE
objMail.HtmlBody = sContent
END IF

IF sImportance = "high" THEN
objMail.Fields ("urn:schemas:httpmail:importance").Value = 2
objMail.Fields.Update()
ELSEIF sImportance = "low" THEN
objMail.Fields ("urn:schemas:httpmail:importance").Value = 0
objMail.Fields.Update()
ELSE
objMail.Fields ("urn:schemas:httpmail:importance").Value = 1
objMail.Fields.Update()
END IF

objMail.From = sFromName &amp; "&lt; " &amp; sFromAddress &amp; "&gt;"
objMail.To = sToName &amp; "&lt; " &amp; sToAddress &amp; "&gt;"
objMail.Subject = sSubject
objMail.Send

Set objMail = Nothing
Set objConfig = Nothing

'-------------------------------
'ASPMail - www.serverobjects.com
'-------------------------------
CASE "aspmail"

SET objMail = Server.CreateObject("SMTPsvg.Mailer")

IF sFormat = "text" THEN
objMail.CharSet = 2
Else
objMail.ContentType = "text/html"
End If

If sImportance = "high" Then
objMail.Priority = 1
ElseIf sImportance = "low" Then
objMail.Priority = 5
Else
objMail.Priority = 3
End If

objMail.FromName = sFromName
objMail.FromAddress= sFromAddress
objMail.RemoteHost = sMailServer
objMail.Subject = sSubject
objMail.BodyText = sContent
objMail.AddRecipient sToAddress, sToName
objMail.SendMail

'-------------------------------
'ASPEmail - www.aspemail.com
'-------------------------------
Case "aspemail"

Set objMail = Server.CreateObject("Persits.MailSender")

If sFormat = "text" Then
objMail.Ishtml = False
Else
objMail.Ishtml = True
End If

If sImportance = "high" Then
objMail.Priority = 1
ElseIf sImportance = "low" Then
objMail.Priority = 5
Else
objMail.Priority = 3
End If

objMail.Host = sMailServer
objMail.From = sFromAddress
objMail.FromName = sFromName
objMail.AddAddress sToAddress, sToName
objMail.Subject = sSubject
objMail.Body = sContent
objMail.Send

'-------------------------------
'JMail - www.dimac.net
'-------------------------------
Case "jmail"

set objMail = Server.CreateOBject("JMail.Message")

If sImportance = "high" Then
objMail.Priority = 1
ElseIf sImportance = "low" Then
objMail.Priority = 5
Else
objMail.Priority = 3
End If

If sFormat = "text" Then
objMail.body = sContent
Else
objMail.HTMLBody = sContent
END IF

objMail.Logging = true
objMail.silent = true
objMail.From = sFromAddress
objMail.FromName = sFromName
objMail.AddRecipient sToAddress, sToName
objMail.Subject = sSubject
objMail.Send(sMailServer)

'-------------------------------
'Dundas - www.dundas.com
'-------------------------------
Case "dundas"

set objMail = Server.CreateOBject("Dundas.Mailer")

If sImportance = "high" Then
objMail.Priority = 1
ElseIf sImportance = "low" Then
objMail.Priority = 5
Else
objMail.Priority = 3
End If

If sFormat = "text" Then
objMail.body = sContent
Else
objMail.htmlBody = sContent
End If

objMail.FromAddress = sFromAddress
objMail.FromName = sFromName
objMail.TOs.Add sToAddress, sToName
objMail.Subject = sSubject
objMail.SMTPRelayServers.Add sMailServer
objMail.SendMail

End Select

END FUNCTION
%&gt;</code></pre>
<p><strong>To send the mail, include sendmail.asp and use the following lines of code:</strong></p>
<pre><code>CALL SendMail("Joe Bloggs","joe@bloggs.com","Jane Bloggs","jane@bloggs.com","Test Email","Test Content","html","high")</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.davidbehan.com/blog/asp-send-mail-function/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
