<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>HeartattacK : .NET</title><link>http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx</link><description>Tags: .NET</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Ajax, Asp.net Ajax, jQuery – Misconceptions and Facts</title><link>http://weblogs.asp.net/ashicmahtab/archive/2009/12/10/ajax-asp-net-ajax-jquery-misconceptions-and-facts.aspx</link><pubDate>Wed, 09 Dec 2009 18:24:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7274752</guid><dc:creator>HeartattacK</dc:creator><slash:comments>0</slash:comments><description>&lt;P&gt;There seems to be some confusion among a lot of developers about Asp.net Ajax. This article will hopefully clear some doubts regarding what it is, what it isn’t and where jQuery comes in.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Note:&lt;/B&gt; Cross posted from &lt;A href="http://www.heartysoft.com/post/2009/12/09/aspnet-ajax-misconceptions-and-facts.aspx" mce_href="http://www.heartysoft.com/post/2009/12/09/aspnet-ajax-misconceptions-and-facts.aspx"&gt;Heartysoft.com&lt;/A&gt;. &lt;BR&gt;&lt;A href="http://www.heartysoft.com/post/2009/12/09/aspnet-ajax-misconceptions-and-facts.aspx" mce_href="http://www.heartysoft.com/post/2009/12/09/aspnet-ajax-misconceptions-and-facts.aspx"&gt;Permalink&lt;/A&gt; &lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7274752" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/JQuery/default.aspx">JQuery</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/AJAX+Control+Toolkit/default.aspx">AJAX Control Toolkit</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category></item><item><title>Speaking at Microsoft Day @ Dhaka- June 20, 2009</title><link>http://weblogs.asp.net/ashicmahtab/archive/2009/06/13/speaking-at-microsoft-day-dhaka-june-20-2009.aspx</link><pubDate>Fri, 12 Jun 2009 18:04:43 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7119628</guid><dc:creator>HeartattacK</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;p&gt;It’s finally happening…we’re having an MS dev (and IT) event here in Dhaka, Bangladesh. This is the first one ever and marks a significant landmark for the software industry here. It’s going to be held on June 20, at IDB Bhaban Auditorium. You can find details and register (mandatory) for the event here:&lt;span&gt;...&lt;/span&gt;&lt;/p&gt;&lt;/p&gt;&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.heartysoft.com"&gt;Heartysoft.com&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.heartysoft.com/post/2009/06/12/Speaking-at-Microsoft-Day-Dhaka-June-20-2009.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7119628" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/Community/default.aspx">Community</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category></item><item><title>Finally Set Up My Own Site: BlogEngine.Net</title><link>http://weblogs.asp.net/ashicmahtab/archive/2009/06/10/finally-set-up-my-own-site-blogengine-net.aspx</link><pubDate>Tue, 09 Jun 2009 17:13:50 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7114814</guid><dc:creator>HeartattacK</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=7114814</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2009/06/10/finally-set-up-my-own-site-blogengine-net.aspx#comments</comments><description>&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.heartysoft.com"&gt;Heartysoft.com&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.heartysoft.com/post/2009/06/09/Finally-Set-Up-My-Own-Site-BlogEngine-Net.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt;In this article, I've looked at a few CMSes for my site. I've looked at Graffiti, Umbraco, Dnn, AxCMS and BlogEngine.Net. I've found the last one to fulfil most of my needs. This article explores how.&lt;b&gt;Note:&lt;/b&gt; Cross posted from &lt;a href="http://www.heartysoft.com"&gt;Heartysoft.com&lt;/a&gt;.
&lt;br /&gt;&lt;a href="http://www.heartysoft.com/post/2009/06/09/Finally-Set-Up-My-Own-Site-BlogEngine-Net.aspx"&gt;Permalink&lt;/a&gt;
&lt;br /&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7114814" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/CMS/default.aspx">CMS</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/BlogEngine.Net/default.aspx">BlogEngine.Net</category></item><item><title>FileUpload Control Doesn’t Give Full Path….HELP!!!!</title><link>http://weblogs.asp.net/ashicmahtab/archive/2009/05/20/fileupload-control-doesn-t-give-full-path-help.aspx</link><pubDate>Tue, 19 May 2009 20:44:07 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7093042</guid><dc:creator>HeartattacK</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=7093042</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2009/05/20/fileupload-control-doesn-t-give-full-path-help.aspx#comments</comments><description>&lt;p&gt;I’ve answered this question about five times in the last few days at the forums. It’s getting tedious so I thought I’d make a blog post about it.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Issue:&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;The FileUpload control has a FileName property. In FireFox (FF) and some other standards compliant browsers, the filename only holds the name of the file. It does NOT hold the full path. In some versions of Internet Explorer (perhaps all versions, but at least up until v7), the FileName property holds a full path. Hence, people see discrepancies among the browsers in terms of the FileName property. A lot of you guys are asking how to get the full path from the file upload control.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What does the FileName property do?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The FileName property holds the name of the uploaded file. In FF, it holds only the file name. In IE7 and earlier (possibly IE8 too – I’ll refer to all of them as IE from here on) it holds &lt;strong&gt;THE FULL PATH TO THE FILE ON THE &lt;/strong&gt;&lt;font size="5"&gt;&lt;strong&gt;&lt;em&gt;CLIENT’S MACHINE. &lt;/em&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font size="2"&gt;Read that again, and again, and one more time. It’s the full path of the uploaded file on the client’s machine. &lt;strong&gt;NOT THE PATH OF THE UPLOADED FILE ON THE&lt;em&gt; SERVER. &lt;/em&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;WHOAH…Hang on a minute…the client machine?&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Yes. It holds the path to the uploaded file on the machine of the user using the website, not the server. It’s the path you see in the file upload controls text box. It’s the user’s &lt;em&gt;local path &lt;/em&gt;to the file. The user may have an M drive with a pics folder. The FileName property will then hold something like M:/pics/pic1.png. The server may not even have an M drive with a pics folder.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="2"&gt;That SUCKS!!!! What good is that?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;This is a decision made by the creators of IE. It was done to enable easier automation of intranet apps where file operations across the network could be accomplished easier. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="2"&gt;Hmmm…Why do them FF guys not support it?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Them FF guys think that letting the server know about the folder structure of a user’s machine is a serious breach of security. For example, if for some reason you had a pic with the path D:\My Racy Photos With X\pic112.jpg (which may be an official photo for whatever reason) and you upload that to the office server, you wouldn’t want your boss (or anyone else) to know that you have a folder called “My Racy Photos With X” on your pc. That’s private info and would be embarrassing if leaked. The worst case scenario would be a few blushes. Now think if you had a folder with some secure info in the name. Even if the contents were secure and not the folder name, you wouldn’t want to make it easier on anyone to get to them. Hence, this can be considered a security flaw.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="2"&gt;Ok…err…So where does my uploaded file go to?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;The uploaded file is uploaded to a temp location on the server. If you process it, fine. If not, it’s purged (read deleted).&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="2"&gt;Wait…how do I store the uploaded file then?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Simple. The FileUpload control has a SaveAs(string path) method. You can use that method to save the file to any path using any filename you want. Just make sure asp.net has permissions to write to that path. So, you can do something like this to save the uploaded file to the uploads folder in the root of your website:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;fileUpload1.SaveAs(Server.MapPath(“~/uploads/”) + System.IO.Path.GetFilename(fileUpload1.FileName));&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;[The reason I’m doing a Path.GetFileName is to ensure that even in IE, I only pass the filename and not the entire client side path to the SaveAs method.]&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;If you wish to provide a different username, you can do that just by changing the parameter. If you wish to append a unique key to each upload, you can use something like Guid.NewGuid().ToString() –or any other technique you want.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="2"&gt;Ok smarty pants…saving to the file system is old school. I wanna save it to a database as an array of bytes. If I don’t have the file location, how do I get the array of bytes? How do I use File.ReadAllBytes if I don’t have a path? Huh? Huh?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Glad you asked. The FileUpload control ha a FileBytes property that gives you an array of bytes with all the contents of the file. Just use that.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="2"&gt;Now I want to do some processing on the uploaded file. How do I get a Stream without the path?&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;The FileUpload control has a FileContent property that gives you a stream to the file. You can use it like this:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Stream str = fileUpload1.FileContent;      &lt;br /&gt;StreamReader sr = new StreamReader(str);       &lt;br /&gt;string contentText = sr.ReadToEnd();&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What about the normal &amp;lt;input type=file&amp;gt; file uploads? I don’t like the FileUpload control. Can I get the full filename from that?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The FileUpload control uses the &amp;lt;input type=’file’&amp;gt; tag behind the covers. You’ll get no added info about the path from using a basic &amp;lt;input type=’file’&amp;gt; tag. The same restrictions apply. Using the input tag, you’ll have to do a bit more work to get to the file bytes. You can get to each uploaded file in a postback by using Request.Files. This will give you every HttpFileUpload in the request, regardless of if you use a &amp;lt;input type=’file’&amp;gt; or a FileUpload control. If using the input tag, you can set the runat=’server’ and id attributes to access it from server side code. You can then access it’s PostedFile in postback. Each object in Request.Files and each PostedFile of each &amp;lt;input type=’file’ runat=’server&amp;gt; and also each PostedFile of each FileUpload is of type HttpFileUpload. That class also has a SaveAs method that does exactly what you’d expect it to. If you need to access the stream, then it has an Inputstream property. You can use it to read the contents using a StreamReader as I’ve shown above. If you need to access the bytes, the following code will help [please note that HttpFileUpload does not have any direct way to give you all the bytes in a byte array, like the FileUpload control does]:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;HttpPostedFile file = Request.Files[0]; &lt;/em&gt;&lt;em&gt;//you can use input&lt;/em&gt;&lt;em&gt;id.PostedFile too      &lt;br /&gt;Stream str = file.InputStream;       &lt;br /&gt;byte[] bytes = new byte[file.ContentLength];       &lt;br /&gt;str.Read(bytes, 0, file.ContentLength);&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;After that, bytes will hold the binary content of the file.&lt;/p&gt;  &lt;p&gt;Hope that helps.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7093042" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category></item><item><title>How to Send Emails from .Net [example uses GMail SMTP]</title><link>http://weblogs.asp.net/ashicmahtab/archive/2009/04/28/how-to-send-emails-from-net-example-uses-gmail-smtp.aspx</link><pubDate>Tue, 28 Apr 2009 05:10:09 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7062968</guid><dc:creator>HeartattacK</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=7062968</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2009/04/28/how-to-send-emails-from-net-example-uses-gmail-smtp.aspx#comments</comments><description>&lt;p&gt;We frequently see questions about sending emails using .Net in the asp.net forums. The process of sending mail is the same for Windows apps and asp.net websites as the same .Net classes are used. The process can be slightly shortened by specifying default SMTP settings in the web.config or app.config file. Here, I’m showing the full version of the code and it does not rely on any configuration settings. The code also specifies unicode encoding for the subject and body.&lt;/p&gt;  &lt;p&gt;using System.Net.Mail;   &lt;br /&gt;using System.Net;&lt;/p&gt;  &lt;p align="left"&gt;&lt;em&gt;//Create the mail message      &lt;br /&gt;MailMessage mail = new MailMessage();       &lt;br /&gt;mail.Subject = &amp;quot;Subject&amp;quot;;       &lt;br /&gt;mail.Body = &amp;quot;Main body goes here&amp;quot;;&lt;/em&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;em&gt;//the displayed &amp;quot;from&amp;quot; email address      &lt;br /&gt;mail.From = new System.Net.Mail.MailAddress(&lt;/em&gt;&lt;a href="mailto:you@live.com"&gt;&lt;em&gt;you@live.com&lt;/em&gt;&lt;/a&gt;&lt;em&gt;);&amp;#160; &lt;br /&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;em&gt;mail.IsBodyHtml = false;      &lt;br /&gt;mail.BodyEncoding = System.Text.Encoding.Unicode;       &lt;br /&gt;mail.SubjectEncoding = System.Text.Encoding.Unicode;       &lt;br /&gt;//Add one or more addresses that will receive the mail       &lt;br /&gt;mail.To.Add(&amp;quot;me@live.com&amp;quot;); &lt;/em&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;em&gt;//create the credentials      &lt;br /&gt;NetworkCredential cred = new NetworkCredential(       &lt;br /&gt;&amp;quot;you@live.com&amp;quot;, //from email address of the sending account       &lt;br /&gt;&amp;quot;password&amp;quot;); //password of the sending account &lt;/em&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;em&gt;//create the smtp client...these settings are for gmail      &lt;br /&gt;SmtpClient smtp = new SmtpClient(&amp;quot;smtp.gmail.com&amp;quot;);       &lt;br /&gt;smtp.UseDefaultCredentials = false;       &lt;br /&gt;smtp.EnableSsl = true;&lt;/em&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;em&gt;//credentials (username, pass of sending account) assigned here      &lt;br /&gt;smtp.Credentials = cred;&amp;#160; &lt;br /&gt;smtp.Port = 587; &lt;/em&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;em&gt;//let her rip      &lt;br /&gt;smtp.Send(mail);&lt;/em&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p align="left"&gt;Hope that helps.&lt;/p&gt;  &lt;p align="left"&gt;&lt;strong&gt;EDIT: I just added the namespaces. MailMessage exists in both System.Net.Mail and System.Web.Mail. System.Web.Mail has been deprecated and you should use System.Net.Mail.&lt;/strong&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7062968" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>How to Read the HTML of a Web Page Programmatically</title><link>http://weblogs.asp.net/ashicmahtab/archive/2008/11/21/how-to-read-the-html-of-a-web-page-programmatically.aspx</link><pubDate>Fri, 21 Nov 2008 04:38:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6749058</guid><dc:creator>HeartattacK</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=6749058</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2008/11/21/how-to-read-the-html-of-a-web-page-programmatically.aspx#comments</comments><description>&lt;P&gt;We might need to read the contents of some page (local or remote) by code. This is quite simple in .net.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;using System.Net; &lt;BR&gt;using System.IO;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;WebRequest req = WebRequest.Create("&lt;/EM&gt;&lt;A href="http://www.asp.net/" );?=");?" mce_href="http://www.asp.net"&gt;&lt;EM&gt;http://www.asp.net");&lt;/EM&gt;&lt;/A&gt; &lt;BR&gt;&lt;EM&gt;WebResponse res = req.GetResponse(); &lt;BR&gt;StreamReader sr = new StreamReader(res.GetResponseStream()); &lt;BR&gt;string html = sr.ReadToEnd();&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The string &lt;EM&gt;html&lt;/EM&gt; will then hold the html contents of &lt;A href="http://www.asp.net/" mce_href="http://www.asp.net"&gt;www.asp.net&lt;/A&gt;. We can also use relative uris in the same website:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;WebRequest req = WebRequest.Create(new Uri("somepage.aspx", UriKind.Relative));&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6749058" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category></item><item><title>WCF .svc Gives HTTP 404 on Host, Works Perfectly on Local</title><link>http://weblogs.asp.net/ashicmahtab/archive/2008/10/01/wcf-svc-gives-http-404-on-host-works-perfectly-on-local.aspx</link><pubDate>Wed, 01 Oct 2008 00:19:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6649327</guid><dc:creator>HeartattacK</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=6649327</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2008/10/01/wcf-svc-gives-http-404-on-host-works-perfectly-on-local.aspx#comments</comments><description>&lt;P&gt;I was recently working on a project that used WCF web services extensively. Everything was ready for deployment, I deployed to the remote host, and voila – nothing works (nothing WCF related). After a LOT of frustration, I managed to make it work. I found two areas which were causing the problem:&lt;/P&gt;
&lt;P&gt;1. The .svc extension was &lt;STRONG&gt;NOT&lt;/STRONG&gt; setup right at our host. You can set this in the web.config webhandlers section for IIS 7, but not for IIS 6.0. I had IIS 7, but decided to bug my host to set up the extension on the server ;)&lt;/P&gt;
&lt;P&gt;2. I had multiple host headers; i.e. my site worked for both &lt;A href="http://mysite.com/" mce_href="http://mysite.com"&gt;http://mysite.com&lt;/A&gt; and &lt;A href="http://www.mysite.com/" mce_href="http://www.mysite.com"&gt;http://www.mysite.com&lt;/A&gt;. To resolve this issue, you can either disable all but one if your host permits. Otherwise, you need to use a factory. Here’s an example of such a factory:&lt;/P&gt;
&lt;TABLE border=0 cellSpacing=0 cellPadding=2 width=513&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=511&gt;
&lt;P&gt;using System; &lt;BR&gt;using System.Collections.Generic; &lt;BR&gt;using System.Linq; &lt;BR&gt;using System.Web; &lt;BR&gt;using System.ServiceModel; &lt;BR&gt;using System.ServiceModel.Activation; &lt;/P&gt;
&lt;P&gt;namespace Shipping.WebService &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class MultipleIISBindingSupportServiceHostFactory : ServiceHostFactory &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Uri[] requiredAddress = GetAppropriateBase(baseAddresses); &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return base.CreateServiceHost(serviceType, requiredAddress); &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Uri[] GetAppropriateBase(Uri[] baseAddresses) &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;Uri&amp;gt; retAddress = new List&amp;lt;Uri&amp;gt;(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retAddress.Add(baseAddresses[0]); &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return retAddress.ToArray(); &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;Granted, it can be way more efficient and you can do nifty tricks with the url to support both http:// and &lt;A href="http://www/" mce_href="http://www"&gt;http://www&lt;/A&gt;, but I can happy to have just one for my webservice. &lt;/P&gt;
&lt;P&gt;Next, you need to set the factory in the markup of the ,svc file. You can do it like this:&lt;/P&gt;
&lt;P&gt;&amp;lt;%@ ServiceHost Language="C#" Debug="false" &lt;STRONG&gt;Factory="Shipping.WebService.MultipleIISBindingSupportServiceHostFactory"&lt;/STRONG&gt; Service="Shipping.WebService.ClientService" CodeBehind="ClientService.svc.cs" %&amp;gt;&lt;/P&gt;
&lt;P&gt;Hope that helps. &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6649327" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/Web+Services/default.aspx">Web Services</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/WCF/default.aspx">WCF</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/IIS/default.aspx">IIS</category></item><item><title>Disable Caching in an HttpHandler</title><link>http://weblogs.asp.net/ashicmahtab/archive/2008/09/18/disable-caching-in-an-httphandler.aspx</link><pubDate>Thu, 18 Sep 2008 10:56:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6631843</guid><dc:creator>HeartattacK</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=6631843</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2008/09/18/disable-caching-in-an-httphandler.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;I was generating some custom reports in Word 2007 format today. The reports were being served by an HttpHandler and various params are passed to it (mostly by query string). One report needed a list of ids to be passed and the query string wasn't an option there, so I put that in Session. [My other post today shows how]. The trouble was that the urls were identical and someone clever (the browser or the server) was caching the report. So, changing the parameter that was made up of ids resulted in no change of the report. Now, output caching is pretty simple to eliminate on pages, and for asmx web services for that matter, but I found that doing so for a handler is slightly tricky. Here's what I did:&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-themecolor: text1; mso-no-proof: yes"&gt;context.Response.Clear();&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Consolas; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-themecolor: text1; mso-no-proof: yes"&gt;context.Response.Cache.SetCacheability(HttpCacheability.Public);&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt; 
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; COLOR: black; FONT-SIZE: 10pt; mso-bidi-font-family: 'Times New Roman'; mso-themecolor: text1; mso-no-proof: yes"&gt;context.Response.Cache.SetExpires(DateTime.MinValue);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&amp;nbsp;in the ProcessRequest method.&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;I would've thought context.Response.Cache.SetCacheability(HttpCacheability.None) would do it, but that kept giving me errors when downloading the docx file. Rather, enabling cacheing and forcing a timeout seems to do it.&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;Hope that helps.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6631843" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category></item><item><title>How to use Session values in an HttpHandler</title><link>http://weblogs.asp.net/ashicmahtab/archive/2008/09/18/how-to-use-session-values-in-an-httphandler.aspx</link><pubDate>Thu, 18 Sep 2008 08:30:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6631570</guid><dc:creator>HeartattacK</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=6631570</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2008/09/18/how-to-use-session-values-in-an-httphandler.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;When writing a custom HttpHandler, by default you have no access to the Session object. Doing something like HttpContext.Current.Session also returns null. The workaround is quite simple:&lt;/P&gt;
&lt;P mce_keep="true"&gt;Reference the System.Web.SessionState namespace:&lt;/P&gt;
&lt;P mce_keep="true"&gt;using System.Web.SessionState;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;...and decorate the handler with either the IRequiresSessionState attribute:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;public class MyHandler:IHttpHandler, IRequiresSessionState&lt;/STRONG&gt;&lt;FONT color=#e0e0e0 size=2&gt;&lt;FONT color=#e0e0e0 size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;FONT color=#e0e0e0 size=2&gt;&lt;FONT color=#e0e0e0 size=2&gt;&lt;FONT color=#000000&gt;or the IReadOnlySessionState attribute:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#e0e0e0 size=2&gt;&lt;FONT color=#e0e0e0 size=2&gt;&lt;FONT color=#000000&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;public class MyHandler:IHttpHandler, IReadOnlySessionState&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;with the latter giving read only access to the seesion object.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Hope that helps.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;EDIT: As pointed out...IReadOnlySessionState and IRequiresSessionState are not attributes, but empty interfaces. This is pretty apparent from the fact that we're not decorating the handler, rather the handler implements the interface [and since it's an empty interface, we don't need to implement anything to do so]. Late night blogging can lure the fingers to strange routes on the keyboard, it seems 8)&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6631570" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Memorystream Not Expandable: Invalid Operation Exception</title><link>http://weblogs.asp.net/ashicmahtab/archive/2008/08/25/memorystream-not-expandable-invalid-operation-exception.aspx</link><pubDate>Sun, 24 Aug 2008 19:31:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6560764</guid><dc:creator>HeartattacK</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=6560764</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2008/08/25/memorystream-not-expandable-invalid-operation-exception.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;There's a little&amp;nbsp;gotcha with the MemoryStream class that I just found out. It has 7 constructors. The default constructor has the stream set as expandable, with an initial capacity of 0. The ctors that take the capacity set the capacity to the param, but also keeps the stream expandable. If, however, you use a ctor with the byte[] param, it initializes the stream with the contents of the buffer, but the stream becomes non-expandable.&lt;/P&gt;
&lt;P mce_keep="true"&gt;So, if you have something like this:&lt;/P&gt;
&lt;P mce_keep="true"&gt;byte[] buffer = File.ReadAllBytes("filaname.docx");&lt;/P&gt;
&lt;P mce_keep="true"&gt;MemoryStream ms = new MemoryStream(buffer);&lt;/P&gt;
&lt;P mce_keep="true"&gt;MemoryStream ms2 = new MemoryStream();&lt;/P&gt;
&lt;P mce_keep="true"&gt;ms2.Write(buffer, 0, buffer.Length);&lt;/P&gt;
&lt;P mce_keep="true"&gt;then, ms will NOT be expandable, ms2 will be. So, if you are modifying the stream and the size may increase, the first ctor will not work, but the second approach will work just fine.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Hope that helps :)&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6560764" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>.Net 3.5 SP1...finally</title><link>http://weblogs.asp.net/ashicmahtab/archive/2008/08/12/net-3-5-sp1-finally.aspx</link><pubDate>Tue, 12 Aug 2008 09:47:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6507606</guid><dc:creator>HeartattacK</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/ashicmahtab/rsscomments.aspx?PostID=6507606</wfw:commentRss><comments>http://weblogs.asp.net/ashicmahtab/archive/2008/08/12/net-3-5-sp1-finally.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Fate has a weird sense of humour. I held out from installing .net 3.5 sp1 all through the CTPs, then beta 1 and beta 2. This is also the first time I restrained myself from installing new stuff (coz simply put, having to uninstall a bunch of betas and patches and what not was getting to me). Well, I couldn't hold out any longer. I downloaded the entire thing. My internet is pretty crap, so I had to download the packages individually, then run a command line switch to download the final files. After that, was a quite long install. It failed. I removed silverlight tools. Tried again. Worked perfectly. I played around for a few hours. Made a few apps. Liked the new stuff quite a bit. And then, at 4 am, I went to bed.&lt;/P&gt;
&lt;P mce_keep="true"&gt;I wake up, and what do I see? Damn you Microsoft...you just released the final .net 3.5 sp1 bits while I was asleep. Couldn't you have done it ONE day earlier or a month later? It HAD to be today, right? Why God, WHY?!?!?!&lt;/P&gt;
&lt;P mce_keep="true"&gt;Ah well...guess I'll be downloading it all over again. And I gues I can forgive MS as the sp1 is actually available as an ISO. That is SO much more convenient to me. Thanks guys.&lt;/P&gt;
&lt;P mce_keep="true"&gt;You can download .net 3.5 sp1 from bootstrapper&amp;nbsp;&lt;A class="" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&amp;amp;displaylang=en"&gt;here&lt;/A&gt;. You can download the FULL .net 3.5 sp1 from &lt;A class="" href="http://download.microsoft.com/download/2/0/e/20e90413-712f-438c-988e-fdaa79a8ac3d/dotnetfx35.exe" mce_href="http://download.microsoft.com/download/2/0/e/20e90413-712f-438c-988e-fdaa79a8ac3d/dotnetfx35.exe"&gt;here&lt;/A&gt;. You can download the Visual Studio 2008 sp1 bootstrapper &lt;A class="" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en"&gt;here&lt;/A&gt;. And you can download the FULL VS 2008 sp1 from &lt;A class="" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=27673C47-B3B5-4C67-BD99-84E525B5CE61&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=27673C47-B3B5-4C67-BD99-84E525B5CE61&amp;amp;displaylang=en"&gt;here&lt;/A&gt;. Please note that the VS 2008 sp1s contain .net 3.5 sp1. Also note that the bootsrappers will require internet connectivity during installation, while the full versions will not.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6507606" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/ASP.NET.NET/default.aspx">ASP.NET.NET</category><category domain="http://weblogs.asp.net/ashicmahtab/archive/tags/.NET/default.aspx">.NET</category></item></channel></rss>