asp.net
You are currently browsing the articles from TechToolBlog matching the category asp.net.
ASP.NET 2.0 Web.Config are much different then 1.0/1.1. I’ll be keeping a running log of the changes I have found, watch outs, and a general lessons learned.
slidingExpiration - I’ve never heard of the thing in 1.1, but it was there the whole time. It is a boolean that tells an authetication cookie to refresh the timeout time on every new request. This makes sense, in fact I’m not entirely sure why you would want it different. In ASP.NET 1.1 this was defaulted as TRUE, however in 2.0 it is default as FALSE. Now I know why everyone was being logged out of the application at 5:00 pm everyday.
<authentication mode=“Forms“>
<forms loginUrl=“Login.aspx“ name=“.ADAuthCookie“ timeout=“480“ slidingExpiration=“true“/>
</authentication>

Written by Tim on April 21st, 2006 with 2 comments.
Read more articles on asp.net.
I am loving Microsoft’s Vista new font Consolas as my new IDE font for Visual Studio 2005. I used to switch between Courier New 9 pt and Anonymous but Consolas rocks!
Screen Shots:


Also exciting about new Vista fonts is Calibri, which should give web developers another choice besides Verdana for a rounded corner font.

I happened to still have the zip file of Vista Fonts. I know that Microsoft is not giddy about people getting these fonts but I have to ask why? Do they not get that this only drums up interest in Vista (I believe the term is Viral Marketing) Anyways, get your download until they tell me to stop.
Get
testking EC0-350 microsoft training to pass
a+ certification exam and become expert of microsoft visual studio using our advance
mcts web development course.

Written by Tim on April 13th, 2006 with 860 comments.
Read more articles on asp.net.
One thing I was looking forward with asp.net 2.0 release was improved viewstate optimization. The truth is it has improved, but for me there is still something desirable to be had.
Where I have run into the problems is a web application I am working on the must allow the user to add an infinate amount of web controls dynamically. The results below are pretty amazing. I ended up using SharpZipLib for the compressing algorithm.
Test Scenerio: One web page with that ended up with 116 asp.net web controls add to it.
Result of ViewState Size:
Before Compression: 43.3 KB
After Compression using SharpZipLib: 3.50 KB
Below is the code to get you started
Imports System.IO
Imports Zip = ICSharpCode.SharpZipLib.Zip.Compression
Public Class PageViewStateZip : Inherits System.Web.UI.Page
Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
Dim vState As String = Me.Request.Form(“__VSTATE”)
Dim bytes As Byte() = System.Convert.FromBase64String(vState)
bytes = vioZip.Decompress(bytes)
Dim format As New LosFormatter
Return format.Deserialize(System.Convert.ToBase64String(bytes))
End Function
Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal viewState As Object)
Dim format As New LosFormatter
Dim writer As New StringWriter
format.Serialize(writer, viewState)
Dim viewStateStr As String = writer.ToString()
Dim bytes As Byte() = System.Convert.FromBase64String(viewStateStr)
bytes = vioZip.Compress(bytes)
Dim vStateStr As String = System.Convert.ToBase64String(bytes)
RegisterHiddenField(“__VSTATE”, vStateStr)
End Sub
End Class
Public Class vioZip
Shared Function Compress(ByVal bytes() As Byte) As Byte()
Dim memory As New MemoryStream
Dim stream = New Zip.Streams.DeflaterOutputStream(memory, _
New Zip.Deflater(Zip.Deflater.BEST_COMPRESSION), 131072)
stream.Write(bytes, 0, bytes.Length)
stream.Close()
Return memory.ToArray()
End Function
Shared Function Decompress(ByVal bytes() As Byte) As Byte()
Dim stream = New Zip.Streams.InflaterInputStream(New MemoryStream(bytes))
Dim memory As New MemoryStream
Dim writeData(4096) As Byte
Dim size As Integer
While True
size = stream.Read(writeData, 0, writeData.Length)
If size > 0 Then memory.Write(writeData, 0, size) Else Exit While
End While
stream.Close()
Return memory.ToArray()
End Function
End Class

Written by Tim on March 2nd, 2006 with 27 comments.
Read more articles on asp.net.
One asp.net custom control that I am loving right now is Denis Baur’s Dynamic PlaceHolder. I’m having to do an web application that must allow for an infinite number of standard web controls and maintain state as these are entered. I went down the AJAX.NET Professional route for a minute but ran into some issues. Instead of recreating the controls on Page_INIT on every request to add a control, I’m able to add to the the new controls to the placeholder list.
Example:
Function AddProduct(Byval strPN as String)
Dim Count As Int32 = CType(ViewState(strPN & "Count_v"), Int32)
Count += 1 'increase viewstate count
Dim ddlProduct as New DropDownList
with ddlproduct
.id = "ddl" & strPN "Product" & Count.ToString()
dphP.Controls.Add(ddlproduct) 'add to dynamic placeholder
end with
ViewState(pn & "Count_v") = Count 'add back to viewstate count
End Function

Written by Tim on March 2nd, 2006 with 4 comments.
Read more articles on asp.net.
We have been doing a lot of asp.net 2.0 development lately. Here is how we are setting up the web.config file to hold our connection settings. First, set your web.config file Connection String settings as follows:
<connectionStrings>
<add name="YourConnectionString" connectionString="Data Source=YourSQLServer;Initial Catalog=YourDatabase;User ID=YourUserID;Password=YourPassword" providerName="System.Data.SqlClient" />
</connectionStrings>
In your data access layer classes set the sqlconnection object to the web.config connection string thru the constructor. For VB.NET that is the class’s New() function. In C# it is the function named the same as the class. Below are both examples or download the C# version or VB.NET version directly.
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI
Public Class DataAccess
Dim conn As New SqlConnection
Dim sql As String
Dim objSql As SqlCommand
Dim MyDataReader As SqlDataReader
Public Sub New()
If ConfigurationManager.ConnectionStrings("YourConnectionString") Is Nothing OrElse _
ConfigurationManager.ConnectionStrings("YourConnectionString").ConnectionString.Trim() = "" Then
Throw New Exception("Connection Error")
Else
conn.ConnectionString = ConfigurationManager.ConnectionStrings("YourConnectionString").ConnectionString
End If
End Sub
Public Function GetMSRP(ByVal productid As Int32) As String
Dim strUnitPrice As String = Nothing
sql = "SELECT UnitPrice FROM Products WHERE productid = @productid"
‘Set SQL OBJECT
objSql = New SqlCommand(sql, conn)
‘Add Parameters
objSql.Parameters.AddWithValue("@productid", productid)
Try
‘Open Connection
conn.Open()
‘Execute DataReader
MyDataReader = objSql.ExecuteReader
‘Store Values in String Variables
While (MyDataReader.Read())
strUnitPrice = MyDataReader.Item("UnitPrice")
End While
‘Close Connection
conn.Close()
Catch ex As Exception
‘TODO HANDLE EX
End Try
Return strUnitPrice
End Function
End Class
################### c# version
using Microsoft.VisualBasic;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
public class DataAccess {
private SqlConnection conn = new SqlConnection();
private string sql;
private SqlCommand objSql;
private SqlDataReader MyDataReader;
public DataAccess() {
if (((ConfigurationManager.ConnectionStrings("YourConnectionString") == null)
|| _)) {
ConfigurationManager.ConnectionStrings("YourConnectionString").ConnectionString.Trim() = "";
throw new Exception("Connection Error");
}
else {
conn.ConnectionString = ConfigurationManager.ConnectionStrings("YourConnectionString").ConnectionString;
}
}
public string GetMSRP(Int32 productid) {
string strUnitPrice = null;
sql = "SELECT UnitPrice FROM Products WHERE productid = @productid";
objSql = new SqlCommand(sql, conn);
// Add Parameters
objSql.Parameters.AddWithValue("@productid", productid);
try {
// Open Connection
conn.Open();
// Execute DataReader
MyDataReader = objSql.ExecuteReader;
// Store Values in String Variables
while (MyDataReader.Read()) {
strUnitPrice = MyDataReader.Item["UnitPrice"];
}
// Close Connection
conn.Close();
}
catch (Exception ex) {
// TODO HANDLE EX
}
return strUnitPrice;
}
}
Subscribe for mcitp training and learn about different ccie tools and tips for web configuration using ccnp programming tutorials.

Written by Tim on February 13th, 2006 with 7 comments.
Read more articles on asp.net.
No older articles
Newer articles »