<?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>SteveX Compiled &#187; .NET</title>
	<atom:link href="http://blog.stevex.net/category/dotnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stevex.net</link>
	<description>Software development and other notes.</description>
	<lastBuildDate>Sun, 25 Jul 2010 17:13:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>String Formatting FAQ</title>
		<link>http://blog.stevex.net/2007/09/string-formatting-faq/</link>
		<comments>http://blog.stevex.net/2007/09/string-formatting-faq/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 12:32:10 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2007/09/28/string-formatting-faq/</guid>
		<description><![CDATA[My String Formatting in C# article has been one of the most popular on this site for the last two years, and it&#8217;s received dozens of comments, many of which were formatting questions or answers to formatting questions. This article is a round-up of those comments &#8211; all credit to the original commenters, whose comments [...]]]></description>
			<content:encoded><![CDATA[<p>My String Formatting in C# article has been one of the most popular on this site for the last two years, and it&#8217;s received dozens of comments, many of which were formatting questions or answers to formatting questions.  This article is a round-up of those comments &#8211; all credit to the original commenters, whose comments are on the <a href="http://blog.stevex.net/index.php/string-formatting-in-csharp/">original article</a>. </p>
<table>
<tr>
<td><b>Q:</b></td>
<td>
<p>How do I show numbers with 5 fixed digits with leading zeroes</p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<pre>int _num1 = 123;
int _num2 = 45;
int _num3 = 123456;</pre>
<pre>String.Format(&quot;{0:00000}&quot;, _num1); //&quot;00123&quot;
       String.Format(&quot;{0:00000}&quot;,   _num2); //&quot;00045&quot;
       String.Format(&quot;{0:00000}&quot;, _num3); //&quot;123456&quot;</pre>
<pre>String.Format(&quot;{0:d5}&quot;, _num1); //&quot;00123&quot;
       String.Format(&quot;{0:d5}&quot;, _num2);   //&quot;00045&quot;
       String.Format(&quot;{0:d5}&quot;, _num3); //&quot;123456&quot;</pre>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>Can I substitute a string for a value? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<p>Yes:</p>
<pre>String.Format(&quot;{0:yes;;no}&quot;, value)</pre>
<p>This will print &quot;no&quot; if value is 0, &quot;yes&quot; if value is 1.</p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>What&#8217;s the most efficient way to convert a type into a string? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<p>Double testDouble = 19.95;</p>
<p>String testString1 = String.Format(&quot;{0:C}&quot;, testDouble); // Boxing operation   required.</p>
<p>String testString2 = testDouble.ToString(&rdquo;C&rdquo;); // No boxing operation   required. </p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>How can I format as percentage without having the number multiplied by 100? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<p>Put a single quote (&rsquo;) before the % in the format string. </p>
<pre>myString.Format(&quot;{0:##.00&prime;%&quot;, 1.23);</pre>
<p>This will yield &quot;1.23%&quot;.</p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>Can I convert a number with a thousand separator to an int? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<p>Yes &#8211; no matter what thousand separator is in use for your locale.</p>
<p>int x = int.Parse(&quot;1,345&quot;); // fails</p>
<p>      int x =   int.Parse(&quot;1,345&quot;,System.Globalization.NumberStyles.AllowThousands)</p>
<p>This gives you an x of 1345.</p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>How can I use curly brackets within a formatted number? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<p>Yes &#8211; doubling them escapes them. For example:</p>
<p>string.format(&quot;{{SomeString}}={0}&quot;,&quot;Hello&quot;);<br />
      will produce:   &quot;{SomeString}=Hellow&quot; </p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>How can I convert from currency back to a number? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<p>You can add the bitmapped values of the   Globalization.NumberStyles enumeration. </p>
<pre>// format double to currency
str = string.Format(&quot;{0:c}&quot;, pmt);

// parse currency formatted string to   double
double.Parse(str,   Globalization.NumberStyles.AllowCurrencySymbol +
   Globalization.NumberStyles.AllowDecimalPoint +
   Globalization.NumberStyles.AllowThousands);</pre>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>So what do google ads G Strings for men have to do with your site?</p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<p>Ask Google! <img src='http://blog.stevex.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>What&#8217;s a good way to format currency? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<pre>double val = 4219.6;
str = string.Format(&quot;{0:$#,#.00;Call Us;Call Us}&quot;, val); </pre>
<p>      This will return &quot;$4,219.60&quot;. The .00 will force 2 decimals and the &ldquo;;Call Us;Call Us&rdquo; to show the text   &ldquo;Call Us&rdquo; in place of negative and null values respectively. (Just in case)</p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>How do I format an integer, with commas for thousands? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<pre>string str = string.Format(&quot;{0:#,0}&quot;, intValue); </pre>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><b>Q:</b></td>
<td>
<p>How can I format a phone number to look like 800.555.1212? </p>
</td>
</tr>
<tr>
<td valign="top"><b>A:</b></td>
<td>
<p>There&#8217;s no direct way to do this; however you can get dashes in the output. So you can do this:</p>
<pre>string tempStr = String.Format(&rdquo;{0:###-###-####}&rdquo;, 8005551212);
string result =tempStr.Replace(&rsquo;-',&rsquo;.'); </pre>
</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2007/09/string-formatting-faq/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Bjarne Stroustrup on C++/CLI</title>
		<link>http://blog.stevex.net/2006/08/bjarne-stroustrup-on-ccli/</link>
		<comments>http://blog.stevex.net/2006/08/bjarne-stroustrup-on-ccli/#comments</comments>
		<pubDate>Tue, 22 Aug 2006 12:50:26 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2006/08/22/bjarne-stroustrup-on-ccli/</guid>
		<description><![CDATA[I hadn&#8217;t seen this before; Bjarne Stroustrup&#8217;s FAQ has an entry that describes his position on C++/CLI.&#160; It&#8217;s worth reading. In a nutshell, he acknowledges that to use the BCL and write .NET classes in .NET you need language features that C++ doesn&#8217;t have.&#160; So you need something like C++/CLI. But he also makes it [...]]]></description>
			<content:encoded><![CDATA[<p>I hadn&#8217;t seen this before; Bjarne Stroustrup&#8217;s FAQ has an entry that describes <a href="http://www.research.att.com/%7Ebs/bs_faq.html#CppCLI">his position on C++/CLI</a>.&nbsp; It&#8217;s worth reading.</p>
<p>In a nutshell, he acknowledges that to use the BCL and write .NET classes in .NET you need language features that C++ doesn&#8217;t have.&nbsp; So you need something like C++/CLI.</p>
<p>But he also makes it clear that you don&#8217;t want code that uses C++/CLI&nbsp;extensions scattered throughout your application.</p>
<p>Well, maybe you do.&nbsp; These features are there for&nbsp;a reason &#8211; because they make development easier &#8211; but using them ties your application to the CLR.</p>
<p>It&#8217;s possible to write a managed application in C++ and still maintain separation between the portable C++ and the .NET specific C++.</p>
<p>And if you&#8217;re going to do that, my suggestion would be to write the managed portion in C#.&nbsp; </p>
<p>If you know C++ you already mostly know C#, and writing the .NET specific portion of your app in C# and calling it from the C++ code makes the separation clear.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2006/08/bjarne-stroustrup-on-ccli/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CRegKey::QueryStringValue</title>
		<link>http://blog.stevex.net/2006/05/cregkeyquerystringvalue/</link>
		<comments>http://blog.stevex.net/2006/05/cregkeyquerystringvalue/#comments</comments>
		<pubDate>Thu, 11 May 2006 05:55:42 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2006/05/11/cregkeyquerystringvalue/</guid>
		<description><![CDATA[Seriously, who decided that MFC&#8217;s CRegKey::QueryStringValue should return a LONG instead of a CString?&#160; It&#8217;s an MFC class.&#160; MFC has a string class.&#160; The purpose of this function is to query a string.&#160; Why do I have to pass in a buffer and a buffer size?&#160; Why can&#8217;t it just return me a string? I [...]]]></description>
			<content:encoded><![CDATA[<p>Seriously, who decided that MFC&rsquo;s CRegKey::QueryStringValue should return a LONG instead of a CString?&nbsp; It&rsquo;s an MFC class.&nbsp; MFC has a string class.&nbsp; The purpose of this function is to query a string.&nbsp; Why do I have to pass in a buffer and a buffer size?&nbsp; Why can&rsquo;t it just return me a string?</p>
<p>I miss working&nbsp;with the&nbsp;.NET Framework.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2006/05/cregkeyquerystringvalue/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Parameterized Queries in HQL</title>
		<link>http://blog.stevex.net/2006/01/parameterized-queries-in-hql/</link>
		<comments>http://blog.stevex.net/2006/01/parameterized-queries-in-hql/#comments</comments>
		<pubDate>Mon, 16 Jan 2006 12:25:39 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2006/01/16/parameterized-queries-in-hql/</guid>
		<description><![CDATA[NHibernate supports parameterized queries but unless you go looking in the Java documentation it&#8217;s not obvious how to do it.&#160; Turns out it&#8217;s really simple: IList results = _session.Find(&#8220;from MyAssembly.MyClass as&#160;MyClass where MyClass.Foo = ?&#8221;, &#160;&#160;&#160; tagText, TypeFactory.GetStringType(64)); You can pass in arrays of objects and types for the last two parameters if you have [...]]]></description>
			<content:encoded><![CDATA[<p>NHibernate supports parameterized queries but unless you go looking in the Java documentation it&rsquo;s not obvious how to do it.&nbsp; Turns out it&rsquo;s really simple:<font size="2"></p>
<p></font><font color="#008080" size="2">IList</font><font size="2"> results = _session.Find(</font><font color="#800000" size="2">&#8220;from MyAssembly.MyClass as&nbsp;MyClass where MyClass.Foo = ?&#8221;</font><font size="2">, <br />&nbsp;&nbsp;&nbsp; </font><font size="2">tagText, </font><font color="#008080" size="2">TypeFactory</font><font size="2">.GetStringType(64));</font></p>
<p>You can pass in arrays of objects and types for the last two parameters if you have more than one parameter in your HQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2006/01/parameterized-queries-in-hql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NHibernate</title>
		<link>http://blog.stevex.net/2006/01/nhibernate/</link>
		<comments>http://blog.stevex.net/2006/01/nhibernate/#comments</comments>
		<pubDate>Sat, 14 Jan 2006 23:01:41 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2006/01/14/nhibernate/</guid>
		<description><![CDATA[&#8220;Learn NHibernate&#8221; has been on my todo list for a while now, and I finally spent some time doing it today. I must say I&#8217;m impressed.&#160; The folks who ported Hibernate from Java to .NET did a good job of making it feel like a first class .NET library, and not just a port.&#160; This [...]]]></description>
			<content:encoded><![CDATA[<p>&ldquo;Learn <a href="http://www.nhibernate.org/">NHibernate</a>&rdquo; has been on my todo list for a while now, and I finally spent some time doing it today.</p>
<p>I must say I&rsquo;m impressed.&nbsp; The folks who ported Hibernate from Java to .NET did a good job of making it feel like a first class .NET library, and not just a port.&nbsp; This <a href="http://www.theserverside.net/articles/showarticle.tss?id=NHibernate">introduction to NHibernate by Jason Gehtland</a> is excellent (and here&#8217;s <a href="http://www.theserverside.net/articles/showarticle.tss?id=NHibernateP2">part two</a>), and with it I had my first classes mapped into database tables in just a few minutes.</p>
<p>I haven&rsquo;t taken the item off my todo list because there&rsquo;s still so much to learn about it, but I can see it&rsquo;s going to be a huge time saver.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2006/01/nhibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BackgroundWorker</title>
		<link>http://blog.stevex.net/2005/12/backgroundworker/</link>
		<comments>http://blog.stevex.net/2005/12/backgroundworker/#comments</comments>
		<pubDate>Thu, 22 Dec 2005 12:34:26 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2005/12/22/backgroundworker/</guid>
		<description><![CDATA[I just had my first opportunity to use the BackgroundWorker object, and I must say I&#8217;m very impressed. Part of creating a user interface is separating the work from the UI thread, so that the UI can remain responsive and report progress while a long operation is running.&#160; This isn&#8217;t rocket science, but it is [...]]]></description>
			<content:encoded><![CDATA[<p>I just had my first opportunity to use the BackgroundWorker object, and I must say I&rsquo;m very impressed.</p>
<p>Part of creating a user interface is separating the work from the UI thread, so that the UI can remain responsive and report progress while a long operation is running.&nbsp; This isn&rsquo;t rocket science, but it is a bit of tedious development that every Windows Forms developer has had to learn how to do.&nbsp; Not anymore.</p>
<p>Let&rsquo;s say you want to count to a billion, on a background thread.&nbsp; Here&rsquo;s how you&rsquo;d do it:</p>
<ol>
<li>Drop the BackgroundWorker object from the Toolbox onto your form.</li>
<li>Add a handler for the DoWork event (double-click on DoWork in the Properties for your BackgroundWorker object)</li>
<li>Call or write your code in the DoWork handler.</li>
<li>When you want to run your asynchronous operation, call the backgroundWorker.RunWorkerAsync() method.</li>
</ol>
<p>That&rsquo;s it &ndash; no messing with threading or locking, it&rsquo;s all handled by the BackgroundWorker object.&nbsp; </p>
<p>The only thing that would have made it easier to implement background operations would have been supplying a standard progress dialog &ndash; you&rsquo;ll have to implement that yourself.&nbsp; Reporting progress is also handled through the BackgroundWorker object &ndash; in your worker thread you call ReportProgress, and on the main thread handle the ProgressChanged event.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2005/12/backgroundworker/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Forms Authentication and Shared Domains</title>
		<link>http://blog.stevex.net/2005/11/forms-authentication-and-shared-domains/</link>
		<comments>http://blog.stevex.net/2005/11/forms-authentication-and-shared-domains/#comments</comments>
		<pubDate>Sat, 19 Nov 2005 05:28:47 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2005/11/19/forms-authentication-and-shared-domains/</guid>
		<description><![CDATA[I have a number of sites that I&#8217;m running on the same domain.&#160; I started the Ottawa Events site, and a friend of mine wanted to do a similar thing for Brantford, London, and Woodstock, so I set up a domain for that and have all four of these virtual sites configured in IIS as [...]]]></description>
			<content:encoded><![CDATA[<p>I have a number of sites that I&rsquo;m running on the same domain.&nbsp; I started the <a href="http://www.ottawaevents.org/">Ottawa Events</a> site, and a friend of mine wanted to do a similar thing for <a href="http://inandaround.ca/brantford">Brantford</a>, <a href="http://inandaround.ca/london">London</a>, and <a href="http://inandaround.ca/woodstock">Woodstock</a>, so I set up a domain for that and have all four of these virtual sites configured in IIS as pointing to the same directory.</p>
<p>A problem I ran into is that the 3 new sites share the same domain name, and the same directory (and thus the same web.config file) but they&rsquo;re actually 3 different ASP.NET application domains.&nbsp; This is okay &ndash; I sniff out in the first Request_Start what the requesting directory is (ie, &ldquo;/brantford&rdquo;) and from that look up the configuration for that specific site in the database.&nbsp; </p>
<p>The cookie&nbsp;path that Forms Authentication uses, however, is specified in the web.config file, and isn&rsquo;t modifiable once set (FormsAuthentication.CookieDomain is a read-only property).</p>
<p>I wanted a different cookie path for each virtual site, so I had to override this.&nbsp; There are two places where this involved changes.</p>
<p>The first is when the user logs in:</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="COLOR: blue">protected</span> <span style="COLOR: blue">void</span> Login1_LoggedIn(<span style="COLOR: blue">object</span> sender, <span style="COLOR: teal">EventArgs</span> e)<?xml:namespace prefix ="" o /><o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="COLOR: teal">HttpCookie</span> cookie = <span style="COLOR: teal">FormsAuthentication</span>.GetAuthCookie(Login1.UserName,&nbsp;</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Login1.RememberMeSet);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">string</span> cookiePath = Request.Url.AbsolutePath;<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">int</span> slashIdx = cookiePath.IndexOf(<span style="COLOR: maroon">&#8220;/&#8221;</span>, 1);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">if</span> (slashIdx != -1)<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>cookiePath = cookiePath.Substring(0, slashIdx);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>cookie.Path = cookiePath;<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Response.Cookies.Set(cookie);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"></span>&nbsp;</p>
<p><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"></span></p>
<p>This code finds the cookie that Forms Authentication created when the user logged in, and replaces the cookie path with one calculated for this site.</p>
<p>The second change is when the user logs out:</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="COLOR: blue">protected</span> <span style="COLOR: blue">void</span> loginStatus_LoggedOut(<span style="COLOR: blue">object</span> sender, <span style="COLOR: teal">EventArgs</span> e)<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">{<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">string</span> cookiePath = Request.Url.AbsolutePath;<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">int</span> slashIdx = cookiePath.IndexOf(<span style="COLOR: maroon">&#8220;/&#8221;</span>, 1);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span><span style="COLOR: blue">if</span> (slashIdx != -1)<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>{<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>cookiePath = cookiePath.Substring(0, slashIdx);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="COLOR: teal">HttpCookie</span> cookie = Request.Cookies[<span style="COLOR: teal">FormsAuthentication</span>.FormsCookieName];<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>cookie.Path = cookiePath;<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>cookie.Expires = <span style="COLOR: teal">DateTime</span>.Now.AddDays(-1);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Response.Cookies.Add(cookie);<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">}</span></p>
<p>This ensures that the correct cookie is set to expire when the user logs out.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2005/11/forms-authentication-and-shared-domains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mono Status &#8217;05</title>
		<link>http://blog.stevex.net/2005/11/mono-status-05/</link>
		<comments>http://blog.stevex.net/2005/11/mono-status-05/#comments</comments>
		<pubDate>Fri, 18 Nov 2005 00:21:16 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2005/11/17/mono-status-05/</guid>
		<description><![CDATA[Miguel posted a great Mono status report. If you&#8217;re interested in cross platform .NET have a look.]]></description>
			<content:encoded><![CDATA[<p>Miguel posted a great <a href="http://tirania.org/blog/archive/2005/Nov-17.html">Mono status report</a>.  If you&#8217;re interested in cross platform .NET have a look.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2005/11/mono-status-05/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Invalid Use of Default Parameter</title>
		<link>http://blog.stevex.net/2005/11/invalid-use-of-default-parameter/</link>
		<comments>http://blog.stevex.net/2005/11/invalid-use-of-default-parameter/#comments</comments>
		<pubDate>Wed, 16 Nov 2005 11:52:22 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2005/11/16/invalid-use-of-default-parameter/</guid>
		<description><![CDATA[If you get this message: &#160;ERROR [07S01] [Microsoft][ODBC SQL Server Driver]Invalid use of default parameter It means you tried to insert a row with a null value in a column that doesn&#8217;t allow nulls.&#160; Bad message. &#160;]]></description>
			<content:encoded><![CDATA[<p>If you get this message:</p>
<p><font size="2"></p>
<p><!--StartFragment -->&nbsp;<span><i>ERROR [07S01] [Microsoft][ODBC SQL Server Driver]Invalid use of default parameter</i></span></p>
<p></font>It means you tried to insert a row with a null value in a column that doesn&rsquo;t allow nulls.&nbsp; Bad message.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2005/11/invalid-use-of-default-parameter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Data Access using TableAdapters</title>
		<link>http://blog.stevex.net/2005/11/data-access-using-tableadapters/</link>
		<comments>http://blog.stevex.net/2005/11/data-access-using-tableadapters/#comments</comments>
		<pubDate>Tue, 01 Nov 2005 12:59:36 +0000</pubDate>
		<dc:creator>stevex</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.stevex.net/index.php/2005/11/01/data-access-using-tableadapters/</guid>
		<description><![CDATA[I just posted an article on accessing databases using the TableAdapter object in VS 2005. It&#8217;s mostly for my own reference in the future but maybe others will find it useful.]]></description>
			<content:encoded><![CDATA[<p>I just posted an article on <a href="http://blog.stevex.net/index.php/data-access-using-tableadapter/">accessing databases using the TableAdapter object</a> in VS 2005.  It&#8217;s mostly for my own reference in the future but maybe others will find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stevex.net/2005/11/data-access-using-tableadapters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
