<?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/"
	>
<channel>
	<title>  ASP/.NET</title>
	<link>http://asp-dot-net.assistProgramming.com</link>
	<description>Codding World &#187; ASP/.NET</description>
	<pubDate>Sat, 23 Aug 2008 05:10:57 +0000</pubDate>
	<language>en</language>
			<item>
		<title>How to upload files in .NET programing?</title>
		<link>http://asp-dot-net.AssistProgramming.com/how-to-upload-files-in-net-programing.html</link>
		<pubDate>Thu, 12 Jun 2008 04:28:28 +0000</pubDate>
		<description><![CDATA[General things
The first version of Microsoft ASP.NET was 1.0. Since then the team worked for introducing possibilities to create web applications that had the ability to upload files to the hosting server. This was done through the use of the FileField HTML server control. Now we refer to the 2.0 version of ASP.NET.This article try [...]]]></description>
			<content:encoded><![CDATA[<h2>General things</h2>
<p>The first version of Microsoft ASP.NET was 1.0. Since then the team worked for introducing possibilities to create web applications that had the ability to upload files to the hosting server. This was done through the use of the <strong>FileField</strong> <acronym title='HyperText Markup Language'><span class='caps'>HTML</span></acronym> server control. Now we refer to the 2.0 version of ASP.NET.This article try to introduce you to the new <strong>FileUpload</strong> server control.</p>
<h2>FileUpload Server Control Example</h2>
<p>If  you want to use the FileField control in ASP.NET 1.<em>x</em> version you must know that you had to take a few extra steps to get everything in line and working. In ASP .NET 2.0 version things are ease to be done. The new version of FileUpload  server control makes the process of uploading files to the hosting server as simple as possible.</p>
<p>I will show you how to use the FileUpload control to upload files to the server. Here are two examples of using FileUploade: one of them is wrote in Microsoft Visual Basic and the other one in Microsoft Visual C#:</p>
<p><strong>Visual Basic Example:</strong></p>
<pre>&lt;%@ Page Language="VB" %&gt;

&lt;script runat="server"&gt;
    Protected Sub Button1_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs)
        If FileUpload1.HasFile Then
            Try
                FileUpload1.SaveAs("C:Uploads\" &amp; _
                   FileUpload1.FileName)
                Label1.Text = "File name: " &amp; _
                   FileUpload1.PostedFile.FileName &amp; "&lt;br&gt;" &amp; _
                   "File Size: " &amp; _
                   FileUpload1.PostedFile.ContentLength &amp; " kb&lt;br&gt;" &amp; _
                   "Content type: " &amp; _
                   FileUpload1.PostedFile.ContentType
            Catch ex As Exception
                Label1.Text = "ERROR: " &amp; ex.Message.ToString()
            End Try
        Else
            Label1.Text = "You have not specified a file."
        End If
    End Sub
&lt;/script&gt;

&lt;html  &gt;
&lt;head runat="server"&gt;
    &lt;title&gt;Upload Files&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt;&lt;br /&gt;
        &lt;br /&gt;
        &lt;asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
         Text="Upload File" /&gt; &lt;br /&gt;
        &lt;br /&gt;
        &lt;asp:Label ID="Label1" runat="server"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>Visual C# Example:</strong></p>
<pre>&lt;%@ Page Language="C#" %&gt;

&lt;script runat="server"&gt;
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
            try
            {
                FileUpload1.SaveAs("C:Uploads\" +
                     FileUpload1.FileName);
                Label1.Text = "File name: " +
                     FileUpload1.PostedFile.FileName + "&lt;br&gt;" +
                     FileUpload1.PostedFile.ContentLength + " kb&lt;br&gt;" +
                     "Content type: " +
                     FileUpload1.PostedFile.ContentType;
            }
            catch (Exception ex)
            {
                Label1.Text = "ERROR: " + ex.Message.ToString();
            }
        else
        {
            Label1.Text = "You have not specified a file.";
        }
    }
&lt;/script&gt;

&lt;html  &gt;
&lt;head runat="server"&gt;
    &lt;title&gt;Upload Files&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt;&lt;br /&gt;
        &lt;br /&gt;
&lt;asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Upload File" /&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;asp:Label ID="Label1" runat="server"&gt;&lt;/asp:Label&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Running this you will obtain the source code generated from the FileUpload control:</p>
<pre>&lt;html  &gt;
&lt;head&gt;&lt;title&gt;
   Upload Files
&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
    &lt;form name="form1" method="post" action="MyFileUpload.aspx"
     id="form1" enctype="multipart/form-data"&gt;
&lt;div&gt;
&lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNDcxNTg5NDg3D2QWAgIEDxYCHgdlbmN0eXBlBRNtdWx0aXBhcnQvZm9yb
       S1kYXRhZGQUQEUFMY1+/fp1mnrkbqmVNQIzFA==" /&gt;
&lt;/div&gt;

    &lt;div&gt;
        &lt;input type="file" name="FileUpload1" id="FileUpload1" /&gt;&lt;br /&gt;
        &lt;br /&gt;
        &lt;input type="submit" name="Button1" value="Upload File"
         id="Button1" /&gt; &lt;br /&gt;
        &lt;br /&gt;
        &lt;span id="Label1"&gt;&lt;/span&gt;
    &lt;/div&gt;

&lt;div&gt;

   &lt;input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
    value="/wEWAgLB+7jIAwKM54rGBv2Iz6LxVY7jWec0gZMxnuaK2ufq" /&gt;
&lt;/div&gt;&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>As you can see ASP.NET 2.0 modified the page&#8217;s<code>&lt;form &gt;</code> element on your behalf by adding the appropriate enctype attribute. Another important thing to remark here is that the FileUpload control was converted to an <acronym title='HyperText Markup Language'><span class='caps'>HTML</span></acronym>  <code>&lt;input type="file" &gt;</code> element.<br />
If you run the file from the examples you can upload files to the server by clicking on the Upload File button and selecting the file that you want to upload and that’s a very ease job.</p>
]]></content:encoded>
			</item>
		<item>
		<title>Sending Authenticated Emails in .NET 2.0</title>
		<link>http://asp-dot-net.AssistProgramming.com/sending-authenticated-emails-in-net-20.html</link>
		<pubDate>Thu, 21 Feb 2008 14:17:28 +0000</pubDate>
		<description><![CDATA[Sending e-mails in the .NET Framework 2.0 is about the same as in version 1.x. There are just a couple of variations. First, all the functionality is within the new System.Net.Mail namespace. The System.Web.Mail namespace, which was used in the 1.x frameworks is now considered obsolete.
Below is the code. It&#8217;s really straight forward and self [...]]]></description>
			<content:encoded><![CDATA[<p>Sending e-mails in the .NET Framework 2.0 is about the same as in version 1.x. There are just a couple of variations. First, all the functionality is within the new <code>System.Net.Mail</code> namespace. The <code>System.Web.Mail</code> namespace, which was used in the 1.x frameworks is now considered obsolete.</p>
<p>Below is the code. It&#8217;s really straight forward and self explanatory:</p>
<pre lang="cs">MailMessage oMsg = <span class="cpp-keyword">new</span> MailMessage();<span class="cpp-comment">// Set the message sender
</span>oMsg.From = <span class="cpp-keyword">new</span> MailAddress(<span class="cpp-literal">&#8220;xavier@devel.oping.net&#8221;</span>, <span class="cpp-literal">&#8220;Xavier Larrea&#8221;</span>);<span class="cpp-comment"></span>
<span class="cpp-comment">// The .To property is a generic collection,</span>

<span class="cpp-comment">// so we can add as many recipients as we like.</span>

oMsg.To.Add(<span class="cpp-keyword">new</span> MailAddress(<span class="cpp-literal">&#8220;fox@foxcorp.org&#8221;</span>,<span class="cpp-literal">&#8220;John Doe&#8221;</span>));

<span class="cpp-comment">// Set the content</span>

oMsg.Subject = <span class="cpp-literal">&#8220;My First .NET email&#8221;</span>;

oMsg.Body = <span class="cpp-literal">&#8220;Test body - .NET Rocks!&#8221;</span>;

oMsg.IsBodyHtml = <span class="cpp-keyword">true</span>;

SmtpClient oSmtp = <span class="cpp-keyword">new</span> SmtpClient(<span class="cpp-literal">&#8220;smtp.myserver.com&#8221;</span>);

<span class="cpp-comment">//You can choose several delivery methods.</span>

<span class="cpp-comment">//Here we will use direct network delivery.</span>

oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;

<span class="cpp-comment">//Some SMTP server will require that you first</span>

<span class="cpp-comment">//authenticate against the server.</span>

NetworkCredential oCredential = <span class="cpp-keyword">new</span> NetworkCredential(<span class="cpp-literal">&#8220;myusername&#8221;</span>,<span class="cpp-literal">&#8220;mypassword&#8221;</span>);

oSmtp.UseDefaultCredentials = <span class="cpp-keyword">false</span>;

oSmtp.Credentials = oCredential;

<span class="cpp-comment">//Let&#8217;s send it already</span>

oSmtp.Send(oMsg);</pre>
<p>Very easy, right? Remember always to use the <code>Try-Catch</code> block when sending emails because lot of things can cause an exception: bad email addresses, authentication errors, network failure, etc.</p>
<p>I hope you find this code useful. Happy coding!</p>
<p><a rel="nofollow" href="http://www.developerfusion.co.uk/show/5456/">Here is the source of this article.</a></p>
]]></content:encoded>
			</item>
		<item>
		<title>Take Advantage of SQLXML with ASP.NET</title>
		<link>http://asp-dot-net.AssistProgramming.com/take-advantage-of-sqlxml-with-aspnet.html</link>
		<pubDate>Mon, 03 Dec 2007 17:29:42 +0000</pubDate>
		<description><![CDATA[Looking for advantages of SQLXML I found some interesting things:
&#8220;SQLXML is a set of supplemental tools that extend SQL Server&#8217;s existing support for retrieving and storing XML data. With SQLXML 3.0, you are now able to use SQL Server to expose Web services. SQLXML&#8217;s Web services let you execute stored procedures, user-defined functions, and they [...]]]></description>
			<content:encoded><![CDATA[<p>Looking for advantages of SQLXML I found some interesting things:</p>
<p>&#8220;<strong>SQLXML</strong> is a set of supplemental tools that extend <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server&#8217;s existing support for retrieving and storing <acronym title='eXtensible Markup Language'><span class='caps'>XML</span></acronym> data. With SQLXML 3.0, you are now able to use <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server to expose Web services. SQLXML&#8217;s Web services let you execute stored procedures, user-defined functions, and they support templates.</p>
<p>While SQLXML&#8217;s Web services capabilities do not offer the flexibility or portability that can be gained by developing your own Web service applications to access data, they are ideal for rapid application development because you can offer SQLXML Web services without writing any code! In addition, the technology is well-suited for exposing reports over the Web. You can develop a client application that consumes SQLXML Web services with very little client-side code. From there, you have a number of options to shape, format, or parse the result set.</p>
<p>In this article you&#8217;ll see how to expose a stored procedure as a Web service and build a simple ASP.NET Web Form-based client to access and test the Web service.</p>
<p>You should have a basic of understanding of <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server 2000 and <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym>, including knowledge of how to setup a virtual directory in <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> and how to grant permissions to a user in <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server. You can find basic documentation on these subjects in <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server 2000 Books Online and in the SQLXML 3.0 Documentation . To begin, you need an instance of <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server 2000, a Windows 2000 server running <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym>, Microsoft&#8217;s MSXML 4.0 <acronym title='eXtensible Markup Language'><span class='caps'>XML</span></acronym> parser, the SQLXML 3.0 toolkit, and Visual Studio .NET (VS.NET). You can download the <acronym title='eXtensible Markup Language'><span class='caps'>XML</span></acronym> parser and SQLXML tools and documentation from the SQLXML resource link in the Resources column of this article.</p>
<p><strong>Configuring a Web Service</strong><br />
The demonstration application for this article uses the Northwind sample database that&#8217;s installed by default with <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server. To get started, follow the instructions in the SQLXML 3.0 Documentation, available for download with the SQLXML 3.0 installer.</p>
<p>First, perform the steps in the procedure labeled Creating the nwind Virtual Directory under the topic <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> Virtual Directory Management for <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server in the SQLXML 3.0 documentation.</p>
<p>Go to the Configure <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> Support MMC snap-in application under the SQLXML 3.0 program group.</p>
<p>Select the default web site for your server, go to the Action menu and select New, then click on Virtual Directory.</p>
<p>Create a virtual directory named nwind under <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> that supports SQLXML applications accessing the Northwind database.</p>
<p>Configure the security settings to support the access to the Northwind database by the virtual directory application.</p>
<p>Under the Settings tab, check the Allow Post option. This allows HTTP POST requests, which are required to support SQLXML Web.</p>
<p>Under this virtual directory, you can configure different types of SQLXML applications, including templates, schemas, and dbobjects, which support template execution, XPath queries against a mapping schema file, and direct access of database objects respectively. These different types of applications under the virtual directory are called virtual name types. There is also a <acronym title='Simple Object Access Protocol'><span class='caps'>SOAP</span></acronym> virtual name type that identifies Web services using <acronym title='Simple Object Access Protocol'><span class='caps'>SOAP</span></acronym> messaging. Create a <acronym title='Simple Object Access Protocol'><span class='caps'>SOAP</span></acronym> virtual name type and name it MyWebService. Now you need to follow the steps in the section labeled Step 2: Configuring the Virtual Name under the topic Initial Setup for Sending <acronym title='Simple Object Access Protocol'><span class='caps'>SOAP</span></acronym> Requests.</p>
<p>Enter MyWebService as the name for the new virtual directory application and select the virtual name type <acronym title='Simple Object Access Protocol'><span class='caps'>SOAP</span></acronym>. This creates a reference to the Web Service extensions of the Northwind database. Configuring MyWebService creates a WSDL (Web Services Definition Language) file and a <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> Server Configuration (.ssc) configuration file for your Web service. The .ssc file describes the virtual name type configuration, and SQLXML uses it to generate the WSDL file. The WSDL file describes the Web services and the methods that your client application can call when using the service.</p>
<p>After setting up a <acronym title='Simple Object Access Protocol'><span class='caps'>SOAP</span></acronym> virtual name type, select the Configure option under the Virtual Names tab of the <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> Virtual Directory management tool for SQLXML 3.0. To set up a stored procedure method mapping type for your soap virtual name type, select the CustOrdersDetail stored procedure under SP/Template option and select the Save option. Saving the stored procedure mapping adds a CustOrdersDetail method to MyWebService. After completing this step, browse to your nwind virtual directory and look for a file named soap.wsdl, which is the <acronym title='eXtensible Markup Language'><span class='caps'>XML</span></acronym>-formatted WSDL file that describes the services you configured. In a text editor the file looks like this:</p>
<pre>
&lt;xsd:element name="CustOrdersDetail"&gt;

&lt;xsd:complexType&gt;

&lt;xsd:sequence&gt;

&lt;xsd:element minOccurs="0" maxOccurs="1"

name="OrderID" type="xsd:int"

nillable="true"/&gt;

&lt;/xsd:sequence&gt;

&lt;/xsd:complexType&gt;

&lt;/xsd:element&gt;

&lt;xsd:element name="CustOrdersDetailResponse"&gt;

&lt;xsd:complexType&gt;

&lt;xsd:sequence&gt;

&lt;xsd:element minOccurs="1" maxOccurs="1"

name="CustOrdersDetailResult"

type="sqlresultstream:SqlResultStream"/&gt;

&lt;xsd:element name="returnValue"

type="xsd:int" nillable="true"/&gt;

&lt;/xsd:sequence&gt;

&lt;/xsd:complexType&gt;

&lt;/xsd:element&gt;"</pre>
<p><a rel="nofollow" href="http://www.devx.com/xml/article/16433">See the source.</a></p>
]]></content:encoded>
			</item>
		<item>
		<title>ASP.NET 2.0 Performance Tuning Considerations</title>
		<link>http://asp-dot-net.AssistProgramming.com/aspnet-20-performance-tuning-considerations.html</link>
		<pubDate>Fri, 16 Nov 2007 16:36:06 +0000</pubDate>
		<description><![CDATA[ASP.NET 2.0 has started picking up the  momentum and already there are a large scale of companies using it for developing  cutting edge web applications.
While the features have been  very good, the decisive factor in web applications development is  performance.
ASP.NET 2.0 in general has a lot of performance enhancement  feature [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: trebuchet ms">ASP.NET 2.0 has started picking up the  momentum and already there are a large scale of companies using it for developing  cutting edge web applications.</span></p>
<p>While the features have been  very good, the decisive factor in web applications development is  <strong>performance</strong>.</p>
<p>ASP.NET 2.0 in general has a lot of performance enhancement  feature starting from compilation model to ADO.NET 2.0 DataSets which is comparatively faster than its predecessor. <span style="font-family: trebuchet ms">Here below are some of the performance considerations:</span></p>
<p><span style="font-family: trebuchet ms"><br />
<strong>Paging through Records</strong><br />
Always use  Custom Paging and dont rely on the default built-in paging mechanism for  GridView, DataGrid etc.,</span></p>
<p><span style="font-family: trebuchet ms"><br />
<strong>Turn off Session  State</strong><br />
ASP.NET uses a built-in session state mechanism as well as  supports your Custom Session State model. However, the cost of Session storage  becomes heavy when the users, objects stored increase significantly. <strong>Turn off  Session State for pages which dont require Session.</strong> Typically in a web  application there may be static as well as dynamic pages. In the static pages,  which dont require Session, the Session State can be turned off. Wherever, you  just require Session Data as ReadOnly (where you wont be updating the Session  Data), the SessionState can be made ReadOnly.</span></p>
<p>To turn off Session State  at page level,</p>
<p><em>&lt;%@ Page EnableSessionState=&#8221;False&#8221;  %&gt;</em></p>
<p>To make it ReadOnly at page level,</p>
<p><em>&lt;%@ Page  EnableSessionState=&#8221;ReadOnly&#8221; %&gt;</em></p>
<p>If your Website has a lot of  content pages which are static and only certain pages require Session Data, try  considering Turning off SessionState at the Web.Config level and only enable it  for those pages which require Session Data. Always the Page settings will  override the web.config settings. Session State can be turned off in the  web.config as follows:-</p>
<p><em>&lt;pages  enableSessionState=&#8221;false&#8221;&gt;&lt;/pages&gt;</em></p>
<p><strong>Turn off View  State</strong><br />
View State is the wonderful mechanism which stores the page as  well as controls&#8217; data, state etc., across round trips. However, the View State  can grow heavy significantly increasing the load and hence, View State must be  turned off for pages which dont require the same. ViewState can be turned off at  page level as follows:-</p>
<p><em>&lt;%@ Page EnableViewState=&#8221;False&#8221;  %&gt;</em></p>
<p><strong>Use Caching </strong><br />
Cache your pages wherever  possible. When implementing OutputCache, set a longer duration than setting a  shorter duration. A longer duration Cache is much more better than quick short  duration caches.</p>
<p>When the content of page can change, try using Cache  with Dependency. There are various dependency techniques such as FileDependency,  Database Dependency etc., to invalidate the cache.</p>
<p><strong>Use IsPostBack  </strong><br />
The IsPostBack is your best friend in controlling when to load the  controls, populate data. ASP.NET, by default postbacks to the server for any/all  operations and the number of Page_Loads you would be having will be significant.  When using IsPostBack, it validates that the DataBinding methods are called only  the first time the page loads and not for subsequent  PostBacks.</p>
<p>if(!IsPostBack)<br />
{<br />
// Data Bind your  Controls<br />
}</p>
<p><strong>Use DataSources</strong><br />
The Provider model and  the DataSource controls in ASP.NET 2.0 not only simplify the Data Binding  techniques but also provide significant performance enhancements by caching the  Data as well as reducing the number of DB hits required to populate similar data  on different controls. The Provider model eliminates the Control from the  underlying Data Model thereby making it a thin layer which just represents  whatever is bound to it.</p>
<p>When using SqlDataSource, ObjectDataSource etc.,  an important point to note is that, you dont need to bind the Data explicitly to  the controls using DataBind.Ex.-</p>
<p><em>GridView1.DataSourceId =  SqlDataSource1</em> // where SqlDataSource1 is the ID of the Datasource  control.</p>
<p>That is all required. You dont require the  <em>GridView1.DataBind();</em> method which we are very familiar from .NET 1.0.  The reason is that, the DataBind method is implicitly called by the  EnsureDataBound method of the DataSource control. If we call it explicitly, then  it results in a double binding of Data.</p>
<p>Please note that  some of the points are not specific to ASP.NET 2.0 but do apply for ASP.NET 1.x  versions as well. Secondly the performance considerations are mentioned assuming  the implementations are done in the proper way with best practices in coding  standards etc.,<br />
<a rel="nofollow" href="http://harishmvp.blogspot.com/2006/06/aspnet-20-performance-tuning.html">See the source&#8230;</a></p>
]]></content:encoded>
			</item>
		<item>
		<title>Performance Tuning Tips</title>
		<link>http://asp-dot-net.AssistProgramming.com/performance-tuning-tips.html</link>
		<pubDate>Fri, 26 Oct 2007 20:32:56 +0000</pubDate>
		<description><![CDATA[Any programming model has its common performance pitfalls, and ASP.NET is no  exception. This section describes some of the ways in which you can avoid  performance bottlenecks in your code.
&#160;


Disable Session State when not in use: Not all applications or pages  require per-user session state. If it is not required, disable it [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Any programming model has its common performance pitfalls, and ASP.NET is no  exception. This section describes some of the ways in which you can avoid  performance bottlenecks in your code.</p>
<p align="justify">&nbsp;</p>
<ul>
<li>
<p align="justify"><strong>Disable Session State when not in use</strong>: Not all applications or pages  require per-user session state. If it is not required, disable it completely.  This is easily accomplished using a page-level directive, such as the following:</p>
<p class="code">&nbsp;</p>
<p><code>&lt;%@ Page EnableSessionState="false" %&gt;</code><br />
<strong>Note:</strong> If a page requires access to session variables but does not  create or modify them, set the value of the directive to <em>ReadOnly</em>.  Session State can also be disabled for <acronym title='eXtensible Markup Language'><span class='caps'>XML</span></acronym> Web service methods. See Using Objects and Intrinsics in the <acronym title='eXtensible Markup Language'><span class='caps'>XML</span></acronym> Web  services section.</li>
<li>
<p align="justify"><strong>Choose your Session State provider carefully</strong>: ASP.NET provides three  distinct ways to store session data for your application: in-process session  state, out-of-process session state as a Windows Service, and out-of-process  session state in a <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> database. Each has its advantages, but in-process session  state is by far the fastest solution. If you are only storing small amounts of  volatile data in session state you should use the in-process provider. The  out-of-process solutions are primarily useful in Web garden and Web farm  scenarios or in situations in which data cannot be lost in the event of a  server/process restart.</p>
</li>
<li>
<p align="justify"><strong>Avoid excessive round trips to the server</strong>: The Web Forms page  framework is one of the best features of ASP.NET, because it can dramatically  reduce the amount of code you need to write to accomplish a task. Programmatic  access to page elements using server controls and the postback event handling  model are arguably the most time-saving features. However, there are appropriate  and inappropriate ways to use these features, and it is important to know when  it is appropriate to use them.An application typically needs to make a round trip to the server only when  retrieving data or storing data. Most data manipulations can take place on the  client between round trips. For example, validating form entries can often take  place on the client before the user submits data. In general, if you do not need  to relay information back to the server, then you should not make a round trip  to the server.If you are writing your own server controls, consider having them render  client-side code for up-level (ECMAScript-capable) browsers. By employing  &#8220;smart&#8221; controls, you can dramatically reduce the number of unecessary hits to  your Web server.</p>
</li>
<li>
<p align="justify"><strong>Use Page.IsPostback to avoid extra work on a round trip</strong>: If you are  handling server control postbacks, you often need to execute different code the  first time the page is requested from the code you do use for the round trip  when an event is fired. If you check the <strong>Page.IsPostBack</strong> property, your  code can execute conditionally, depending on whether there is an initial request  for the page or a responce to a server control event. It might seem obvious to  do this, but in practice it is possible to omit this check without changing the  behavior of the page. For example:</p>
<pre id="codectl01">&lt;script language="VB" runat="server"&gt;    Public ds As DataSet

    ...

Sub Page_Load(sender As Object, e As EventArgs)

        ' ...set up a connection and command here...

        If Not (Page.IsPostBack)

            Dim query As String = "select * from Authors where FirstName like '%JUSTIN%'"

            myCommand.Fill(ds, "Authors")

            myDataGrid.DataBind()

        End If

    End Sub

Sub Button_Click(sender As Object, e As EventArgs)

        Dim query As String = "select * from Authors where FirstName like '%BRAD%'"

        myCommand.Fill(ds, "Authors")

        myDataGrid.DataBind()

    End Sub

&lt;/script&gt;

&lt;form runat="server"&gt;

  &lt;asp:datagrid datasource='&lt;%# ds.Tables["Authors"].DefaultView %&gt;' runat="server"/&gt;&lt;br&gt;

  &lt;asp:button onclick="Button_Click" runat="server"/&gt;

&lt;/form&gt;</pre>
<p>The <code>Page_Load</code> event executes on every request, so we checked  <strong>Page.IsPostBack</strong> so that the first query does not execute when we process  the <code>Button_Click</code> event postback. Note that even without this check  our page would behave identically, since the binding from the first query would  be overturned by the call to <strong>DataBind</strong> in the event handler. Keep in mind  that it can be easy to overlook this simple performance improvement when you  write your pages.</li>
<li>
<p align="justify"><strong>Use server controls sparingly and appropriately</strong>: Even though it is  extremely easy to use, a server control might not always be the best choice. In  many cases, a simple rendering or databinding substitution will accomplish the  same thing. For example:</p>
<pre id="codectl02">&lt;script language="VB" runat="server"&gt;    Public imagePath As String

    Sub Page_Load(sender As Object, e As EventArgs)

        '...retrieve data for imagePath here...

        DataBind()

    End Sub

&lt;/script&gt;

&lt;%--the span and img server controls are unecessary...--%&gt;

The path to the image is: &lt;span innerhtml='&lt;%# imagePath %&gt;' runat="server"/&gt;&lt;br&gt;

&lt;img src='&lt;%# imagePath %&gt;' runat="server"/&gt;

&lt;br&gt;&lt;br&gt;

&lt;%-- use databinding to substitute literals instead...--%&gt;

The path to the image is: &lt;%# imagePath %&gt;&lt;br&gt;

&lt;img src='&lt;%# imagePath %&gt;' /&gt;

&lt;br&gt;&lt;br&gt;

&lt;%-- or a simple rendering expression...--%&gt;

The path to the image is: &lt;%= imagePath %&gt;&lt;br&gt;

&lt;img src='&lt;%= imagePath %&gt;' /&gt;</pre>
<p>In this example, a server control is not needed to substitute values into the  resulting <acronym title='HyperText Markup Language'><span class='caps'>HTML</span></acronym> sent back to the client. There are many other cases where this  technique works just fine, even in server control templates. However, if you  want to programmatically manipulate the control&#8217;s properties, handle events from  it, or take advantage of its state preservation, then a server control would be  appropriate. You should examine your use of server controls and look for code  you can optimize.</li>
<li>
<p align="justify"><strong>Avoid excessive server control view state</strong>: Automatic state management is  a feature that enables server controls to re-populate their values on a round  trip without requiring you to write any code. This feature is not free however,  since the state of a control is passed to and from the server in a hidden form  field. You should be aware of when <strong>ViewState</strong> is helping you and when it  is not. For example, if you are binding a control to data on every round trip  (as in the datagrid example in tip #4), then you do not need the control to  maintain it&#8217;s view state, since you will wipe out any re-populated data in any  case.<strong>ViewState</strong> is enabled for all server controls by default. To disable  it, set the <strong>EnableViewState</strong> property of the control to false, as in the  following example:</p>
<p class="code">&nbsp;</p>
<pre>&lt;asp:datagrid EnableViewState="false" datasource="..." runat="server"/&gt;</pre>
<p>You can also turn <strong>ViewState</strong> off at the page level. This is useful when  you do not post back from a page at all, as in the following example:</p>
<p class="code">&nbsp;</p>
<pre>&lt;%@ Page EnableViewState="false" %&gt;</pre>
<p>Note that this attribute is also supported by the <strong>User  Control</strong> directive. To analyze the amount of view state used by the server  controls on your page, enable tracing and look at the View State column of the  Control Hierarchy table. For more information about the Trace feature and how to  enable it, see the Application-level Trace  Logging feature.</li>
<li>
<p align="justify"><strong>Use Response.Write for String concatenation</strong>: Use the HttpResponse.Write  method in your pages or user controls for string concatenation. This method  offers buffering and concatenation services that are very efficient. If you are  performing extensive concatenation, however, the technique in the following  example, using multiple calls to <strong>Response.Write</strong>, is faster than  concatenating a string with a single call to the <strong>Response.Write</strong> method.</p>
</li>
<li>
<p align="justify"><strong>Do not rely on exceptions in your code</strong>: Exceptions are very expensive and  should rarely occur in your code. You should never use exceptions as a way to  control normal program flow. If it is possible to detect in code a condition  that would cause an exception, you should do that instead of waiting to catch  the exception before handling that condition. Common scenarios include checking  for null, assigning to a string that will be parsed into a numeric value, or  checking for specific values before applying math operations.</p>
</li>
<li>
<p align="justify"><strong>Use early binding in Visual Basic or JScript code</strong>: One of the advantages  of Visual Basic, VBScript, and JScript is their typeless nature. Variables can  be created simply by using them and need no explicit type declaration. When  assigning from one type to another, conversions are performed automatically, as  well. This can be both an advantage and a disadvantage, since late binding is a  very expensive convenience in terms of performance.The Visual Basic language now supports type-safe programming through the use  of a special <strong>Option Strict</strong> compiler directive. For backward  compatibility, ASP.NET does not enable <strong>Option Strict</strong> by default. However,  for optimal perfomance, you should enable <strong>Option Strict</strong> for your pages by  using a <strong>Strict</strong> attribute on the page or Control directive:</p>
<p class="code">&nbsp;</p>
<pre>&lt;%@ Page Language="VB" Strict="true" %&gt;&lt;%

Dim B

Dim C As String

' This causes a compiler error:

A = "Hello"

' This causes a compiler error:

B = "World"

' This does not:

C = "!!!!!!"

' But this does:

C = 0</pre>
<p>JScript also supports typeless programming, though it offers no compiler  directive to force early binding. A variable is late-bound if:</p>
<ul>
<li>
<p align="justify">It is declared explicitly as an object.</p>
</li>
<li>
<p align="justify">It is a field of a class with no type declaration.</p>
</li>
<li>
<p align="justify">It is a private function/method member with no explicit type declaration and  the type cannot be inferred from its use.</p>
</li>
</ul>
<p>The last distinction is complicated. The JScript compiler optimizes if it can  figure out the type, based on how a variable is used. In the following example,  the variable <em>A</em> is early-bound but the variable <em>B</em> is late-bound:</p>
<p class="code">&nbsp;</p>
<pre>var A;

var B;A = "Hello";

B = "World";

B = 0;</pre>
<p>For the best performance, declare your JScript variables as having a type.  For example, &#8220;var A : String&#8221;.</p>
<pre>
%&gt;</pre>
<p>JScript also supports typeless programming, though it offers no compiler  directive to force early binding. A variable is late-bound if:</p>
<ul>
<li>
<p align="justify">It is declared explicitly as an object.</p>
</li>
<li>
<p align="justify">It is a field of a class with no type declaration.</p>
</li>
<li>
<p align="justify">It is a private function/method member with no explicit type declaration and  the type cannot be inferred from its use.</p>
</li>
</ul>
<p>The last distinction is complicated. The JScript compiler optimizes if it can  figure out the type, based on how a variable is used. In the following example,  the variable <em>A</em> is early-bound but the variable <em>B</em> is late-bound:</p>
<p class="code">&nbsp;</p>
<pre>var A;

var B;A = "Hello";

B = "World";

B = 0;</pre>
<p>For the best performance, declare your JScript variables as having a type.  For example, &#8220;var A : String&#8221;.</li>
<li>
<p align="justify"><strong>Port call-intensive COM components to managed code</strong>: The .NET Framework  provides a remarkably easy way to interoperate with traditional COM components.  The benefit is that you can take advantage of the new platform while preserving  your existing code. However, there are some circumstances in which the  performance cost of keeping your old components is greater than the cost to  migrate your components to managed code. Every situation is unique, and the best  way to decide what needs to be changed is to measure site performance. In  general, however, the performance impact of COM interoperability is proportional  to the number of function calls made or the amount of data marshaled from  unmanaged to managed code. A component that requires a high volume of calls to  interact with it is called &#8220;chatty,&#8221; due to the number of communications between  layers. You should consider porting such components to fully managed code to  benefit from the performance gains provided by the .NET platform. Alternatively,  you might consider redesigning your component to require fewer calls or to  marshal more data at once.</p>
</li>
<li>
<p align="justify"><strong>Use <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> stored procedures for data access</strong>: Of all the data access methods  provided by the .NET Framework, <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym>-based data access is the best choice for  building scalable web applications with the best performance. When using the  managed <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> provider, you can get an additional performance boost by using  compiled stored procedures instead of ad hoc queries.</p>
</li>
<li>
<p align="justify"><strong>Use SqlDataReader for a fast-forward, read-only data cursor</strong>: A  <strong>SqlDataReader</strong> object provides a forward, read-only cursor over data  retrieved from a <acronym title='Structured Query Language'><span class='caps'>SQL</span></acronym> database. <strong>SqlDataReader</strong> is a more performant option  than using a <strong>DataSet</strong> if it can be used for your scenario. Because  <strong>SqlDataReader</strong> supports the <strong>IEnumerable</strong><strong>SqlDataReader</strong>.</p>
<p>interface, you can even  bind server controls, as well. For an example of using</li>
<li>
<p align="justify"><strong>Cache data and output wherever possible</strong>: The ASP.NET programming model  provides a simple mechanism for caching page output or data when it does not  need to be dynamically computed for every request. You can design your pages  with caching in mind to optimize those places in your application that you  expect to have the most traffic. More than any feature of the .NET Framework,  the appropriate use of caching can enhance the performance of your site,  sometimes by an order of magnitude or more. For more information about how to  use caching.</p>
</li>
<li>
<p align="justify"><strong>Enable Web gardening for multiprocessor computers</strong>: The ASP.NET process  model helps enable scalability on multiprocessor machines by distributing the  work to several processes, one for each <acronym title='Central Processing Unit'><span class='caps'>CPU</span></acronym>, each with processor affinity set to  its <acronym title='Central Processing Unit'><span class='caps'>CPU</span></acronym>. The technique is called <em>Web gardening</em>, and can dramatically  improve the performance of some applications.</p>
</li>
<li>
<p align="justify"><strong>Do not forget to disable Debug mode</strong>: The <strong>&lt;compilation&gt;</strong>  section in ASP.NET configuration controls whether an application is compiled in  Debug mode, or not. Debug mode degrades performance significantly. Always  remember to disable Debug mode before you deploy a production application or  measure performance.</p>
</li>
</ul>
<p><a rel="nofollow" href="http://samples.gotdotnet.com/quickstart/aspplus/doc/perftuning.aspx">Read the full article&#8230;</a></p>
]]></content:encoded>
			</item>
		<item>
		<title>Uploading files in ASP .NET 2.0. Is it safe?</title>
		<link>http://asp-dot-net.AssistProgramming.com/uploading-files-in-asp-net-20-is-it-safe.html</link>
		<pubDate>Wed, 19 Sep 2007 21:27:57 +0000</pubDate>
		<description><![CDATA[Choosing to upload files with ASP .NET proved to be inefficient. The way IIS 5 and IIS 6 runs is: when you pick a file in the form, IIS need to &#8220;absorb&#8221; the whole file and you can have access to the file properties only after. IIS 7 promised to be more like Apache in [...]]]></description>
			<content:encoded><![CDATA[<p>Choosing to upload files with ASP .NET proved to be inefficient. The way <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> 5 and <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> 6 runs is: when you pick a file in the form, <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> need to &#8220;absorb&#8221; the whole file and you can have access to the file properties only after. <acronym title='Internet Infomation Server'><span class='caps'>IIS</span></acronym> 7 promised to be more like Apache in this case, but until then we have to wait for a long upload and the worst thing is u can&#8217;t display a progress bar. If you want to see how a file is uploaded using <acronym title='PHP Hypertext Processor'><span class='caps'>PHP</span></acronym> read the full article <a href="http://php.assistprogramming.com/upload-files-using-php.html">here</a>.</p>
<p>Another bad thing is that you cannot upload more than 4MB without raising the limit in <code>maxRequestLength</code> in the <code>&lt;httpRuntime&gt;</code> config section. We have to be careful because isn&#8217;t enough to raise the limit for upload; we also should know that we have to increase <code>executionTimeout</code>, otherwise ASP.NET close requests that take too long. How should an user know whose fault is for an unsuccessful upload? One solution is to override <code>Page.OnError</code> and inspect the HTTP code, which should be 400, if the exception happens to be of type <code>HttpException</code>. You may also implement an HttpModule, set up its <code>BeginRequest</code> handler and compare <code>Request.ContentLength</code> with the size limit. If <code>ContentLength</code> is too high, redirect to a page with a meaningful error message.</p>
<h3>Uploading Multiple Files</h3>
<p>Uploading more than one files is made via the <code>Request.Files</code> collection:</p>
<pre>HttpFileCollection uploads = HttpContext.Current.Request.Files;</pre>
<p>Let&#8217;s have an example for uploading multiple files:</p>
<pre class="coloredcode">&lt;<span class="tag">form</span><span class="attr"> id=</span><span class="attrv">&#8220;form&#8221;</span><span class="attr"> runat=</span><span class="attrv">&#8220;server&#8221;</span><span class="attr"> enctype=</span><span class="attrv">&#8220;multipart/form-data&#8221;</span>&gt;
&lt;<span class="tag">p</span><span class="attr"> id=</span><span class="attrv">&#8220;upload&#8221;</span>&gt;
   &lt;<span class="tag">input</span><span class="attr"> type=</span><span class="attrv">&#8220;file&#8221;</span><span class="attr"> runat=</span><span class="attrv">&#8220;server&#8221;</span><span class="attr"> size=</span><span class="attrv">&#8220;60&#8243;</span> /&gt;
&lt;/<span class="tag">p</span>&gt;

&lt;<span class="tag">p</span>&gt;&lt;<span class="tag">a</span><span class="attr"> href=</span><span class="attrv">&#8220;#&#8221;</span><span class="attr"> onclick=</span><span class="attrv">&#8220;addFile(); return false;&#8221;</span>&gt;Add a file&lt;/<span class="tag">a</span>&gt;&lt;/<span class="tag">p</span>&gt;

&lt;<span class="tag">p</span>&gt;&lt;<span class="tag">asp:Button</span><span class="attr"> ID=</span><span class="attrv">&#8220;butSubmit&#8221;</span><span class="attr"> runat=</span><span class="attrv">&#8220;server&#8221;</span><span class="attr"> Text=</span><span class="attrv">&#8220;Upload Here&#8221;</span><span class="attr"> OnClick=</span><span class="attrv">&#8220;butSubmit_Click&#8221;</span> /&gt;&lt;/<span class="tag">p</span>&gt;
class=&#8221;coloredcode&#8221;&gt;&lt;<span class="tag">script</span><span class="attr"> type=</span><span class="attrv">&#8220;text/javascript&#8221;</span>&gt;
class=&#8221;coloredcode&#8221;&gt;function addFile(){
    if (!document.getElementById || !document.createElement)
        return false;

    var uploadArea = document.getElementById (&#8221;upload&#8221;);

    if (!uploadArea)
        return;

    var newLine = document.createElement (&#8221;br&#8221;);
    uploadArea.appendChild (newLine);

    var newUpload = document.createElement (&#8221;input&#8221;);
	newUpload.type = &#8220;file&#8221;;
        newUpload.size = &#8220;70&#8243;;

    if (!addFile.lastAssignedId)
        addFile.lastAssignedId = 100;

    newUpload.setAttribute (&#8221;id&#8221;, &#8220;dynamic&#8221; + addFile.lastAssignedId);
    newUpload.setAttribute (&#8221;name&#8221;, &#8220;dynamic:&#8221; + addFile.lastAssignedId);
    uploadArea.appendChild (newUpload);

    addFile.lastAssignedId++;
}
&lt;/<span class="tag">script</span>&gt;

&lt;<span class="tag">script</span><span class="attr"> type=</span><span class="attrv">&#8220;text/C#&#8221;</span><span class="attr"> runat=</span><span class="attrv">&#8220;server&#8221;</span>&gt;
void butSubmit_Click(object sender, EventArgs e){
    HttpFileCollection uploads = HttpContext.Current.Request.Files;

    for (int i = 0; i &lt; uploads.Count; i++){
        HttpPostedFile upload = uploads[i];

        if (upload.ContentLength == 0)
            continue;
    }
}
&lt;/<span class="tag">script</span>&gt;

&lt;/<span class="tag">form</span>&gt;</pre>
]]></content:encoded>
			</item>
		<item>
		<title>How to Easily Use FTP in WSH</title>
		<link>http://asp-dot-net.AssistProgramming.com/how-to-easily-use-ftp-in-wsh.html</link>
		<pubDate>Mon, 10 Sep 2007 22:13:59 +0000</pubDate>
		<description><![CDATA[In my last article I showed you a work around that allowed you to use FTP in WSH. This time I’m going to show you a much easier, more flexible approach using a third-party ActiveX control designed to expand WSH.  ActiveX controls can be used to add functionality to WSH that it does not [...]]]></description>
			<content:encoded><![CDATA[<p>In my last article I showed you a work around that allowed you to use FTP in WSH. This time I’m going to show you a much easier, more flexible approach using a third-party ActiveX control designed to expand WSH.  ActiveX controls can be used to add functionality to WSH that it does not have natively. The ActiveX must be written for this purpose and must provide a COM interface.</p>
<p>Once the ActiveX control is instantiated in your script, you will be able to access all of the methods and properties that it provides.  ActiveX controls must be installed on the system on which they are being used. Simply referencing a file is not enough. To install an ActiveX control, it must be registered, meaning that a set of registry keys must be created that reference it as a COM object.</p>
<p>Many third parties will include installers for this.  If your ActiveX control does not have an installer, you can register it yourself from the command line. Navigate to the directory where your control is located and use the command regsvr32 activex.ocx with the name of your control.  We’ll be using Chilkat’s Free FTP ActiveX control. This ActiveX control acts as a sort of scriptable FTP client that provides access to the most common FTP functions. There are two versions—one free and one commercial.</p>
<p>While we’ll be using the free control for this demonstration, the paid version offers some very cool functionality.  Once you’ve installed the control, you’ll be able to access it through its COM interface by connecting to the ChilkatFTP.ChilkatFTP namespace.</p>
<pre>Set objFtp = CreateObject("ChilkatFTP.ChilkatFTP")</pre>
<p>Next you’ll want to make a connection. To do that you’ll need to provide the hostname, username, and password. The FTP control provides properties for this.</p>
<pre>objFtp.Hostname = "ftp.mysite.com"objFtp.Username = USERNAME

objFtp.Password = PASSWORD

success = objFtp.Connect()

Finally, the Connect method makes the connection. Be sure to catch the return code for error handling purposes.

If (success &lt;&gt; 1) Then

Wscript.Echo objFtp.LastErrorText

Wscript.Quit

End If</pre>
<p>It’s obviously not enough to just connect to an FTP server. You undoubtedly have some task to perform. One of the most common is a file download. Let’s take a look at how to create a simple function for performing file downloads with the Chilkat FTP component.</p>
<p>In order to download a file we need to provide three pieces of information: what file to download, where to save it locally, and where to find it on the remote server. We’ll pass these values as parameters to our function.</p>
<p>Our function first needs to navigate to the proper remote directory. We can do this with the ChangeRemoteDir method provided by the Chilkat component.</p>
<p><a rel="nofollow" href="http://www.aspfree.com/c/a/Windows-Scripting/How-to-Easily-Use-FTP-in-WSH/1/" target="_blank">Read the full article </a></p>
]]></content:encoded>
			</item>
	</channel>
</rss>
