June 28th, 2007 — Administration
Was anyone able to get this running on Windows Vista 32Bit or Windows Vista 64Bit? The funny thing is, 32Bit throws a different Error than 64Bit.
While Vista 64Bit is complaining about some folder called DavWWWRoot, Vista 32Bit says no matter what the folder I would like to set up is invalid.
I found this fix here: Software Update for Web Folders but it didn’t help me, same error.
How did I setup the WebDAV Folder on Windows 2003 Server? Pretty straight forward in fact:
- Created a folder called WebDAV in my WWW root, in details: C:\root\domains\WebDAV
- My Website is located in C:\root\domains\WebDAV\domain.com
- I added a virtual folder to my website in IIS6, pointing to C:\root\domains\WebDAV and carrying the name WebDAV
- I disabled anonymous connections and just enabled Windows Authentication
- I made sure I got proper rights on that folder with my local Account
- I fired up “Computer” on my local PC, added a network ressource and filled in http://www.mydomain.de/WebDAV as path.
- I received an invalid folder error after typing in my credentials on Vista 32Bit, just using the domain without the WebDAV folder doesn’t help either.
- On Vista 64Bit I’m receiving another error includin something about a DavWWWRoot which is as far as I know the standard root directory for WebDAVs - I even tried calling my folder DavWWWRoot but it didn’t change anything
So I were not able to get it running on Vista x32 or x64. This seems to be a serious bug in Vista as XP seems to do just fine. I can even connect to the folder with IE7 after filling in the credentials, but no drag&drop supported anymore as you can’t open it as WebFolder in IE7.
Does anyone have a fix or workaround for that? It’s really pretty annoying, I can’t believe Vista implented a buggy WebDAV Gateway and noone cared about it after almost 6 months!
June 26th, 2007 — ASP.NET
Here is an very easy client-side javascript to check or uncheck all your checkboxes from your CheckBoxList at once:
<script language="javascript" type="text/javascript">function Select(Select){
for (var n=0; n < document.forms[0].length; n++) if (document.forms[0].elements[n].type==’checkbox’)
document.forms[0].elements[n].checked=Select; return false; }</script>
Select <a href="#" onclick="javascript:Select(true)">All</a> | <a href="#" onclick="javascript:Select(false)">None</a>
Just put it at the top of your ASP.NET page and you’re set. It won’t get any easier than that 
June 24th, 2007 — ASP.NET
A pretty simple piece of code drove me into hell lately:
270 if (!System.IO.Directory.Exists(Server.MapPath(“GamePics\\” + CatName + “\\” + URL)))
271 {
272 System.IO.Directory.CreateDirectory(Server.MapPath(“GamePics\\” + CatName + “\\” + URL));
273 }
Nothing special in fact. However, if you run Windows Vista this could result into a serious problem. The problem only occurs if the folders (in this case) “CatName” and “URL” didn’t exist before. Meaning, ASP.NET creates the CatName folder AND the URL folder in one go.
If that happens, you won’t have any access to the “URL” Folder - meaning the secondly created folder. You will not be able to delete or access it as it doesn’t have an owner and you will not be able to set an owner either.
I was able to get rid of the folder by logging into the Vista Administrator Account (you have to enable it first). I browsed to the location and the folder was already gone by then, maybe a restart will fix this problem, too.
A workaround:
- Never create more than one folder at the same time in one line.
- Create one folder and then make a seperate System.IO.File.Create call to create the second folder.
In my case this didn’t fire up the Access denied problem. I hope this post will help people facing the same weird problem someday.
May 23rd, 2007 — ASP.NET
The default forms authentication timeout value is set on 30 minutes. Increasing the ASP.NET Membership-Cookie Timeout is most easily possible by setting the timeout attribute in the web.config:
<authentication mode="Forms">
<forms name="ApplicationLogin" loginUrl="Login.aspx" path="/" protection="All" timeout="10080">
</forms>
timeout=”10080″ is meassured in minutes, meaning we got a timeout of 10080 minutes here.
If you don’t want to set the forms timeout value that high you have to give up on the standard login controls supplied with ASP.NET 2.0. Here’s what you have to do:
1) Create a custom Login Page aka Login.aspx, this is just an example:
4 <asp:Panel ID=”Panel1″ runat=”server” DefaultButton=”Button1″>
5 <div align=”center”>
6 User: <br />
7 <asp:TextBox ID=”TextUser” runat=”server”></asp:TextBox>
8 <br />
9 Password:<br />
10 <asp:TextBox ID=”TextPass” runat=”server” TextMode=”Password”></asp:TextBox>
11 <br />
12 <asp:CheckBox ID=”CheckBox1″ runat=”server” Checked=”True” />
13 <asp:Button ID=”Button1″ runat=”server” Text=”Login” OnClick=”Button1_Click” /><br /><br />
14 <asp:Literal ID=”Literal1″ runat=”server”></asp:Literal>
15 </div>
16 </asp:Panel>
2) Create a new class auth.cs and add the following:
43 public static bool CheckLogins(string UserName, string Password)
44 {
45 if (Membership.ValidateUser(UserName, Password))
46 {
47 return true;
48 }
49 else
50 {
51 return false;
52 }
53
54 return false;
55 }
75 public static bool CreateTicket(string UserName, bool StayLoggedIn, string Type, DateTime CookieTime)
76 {
77 FormsAuthentication.Initialize();
78
79 // Create a new ticket used for authentication
80 FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UserName, DateTime.Now, CookieTime, StayLoggedIn, Type, FormsAuthentication.FormsCookiePath);
81
82 string hash = FormsAuthentication.Encrypt(ticket);
83 HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
84
85 if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
86
87 HttpContext.Current.Response.Cookies.Add(cookie);
88
89 return true;
90 }
3) Now insert this into the button click event routine of Login.aspx:
43 public static bool CheckLogins(string UserName, string Password)
44 {
45 if (auth.CheckLogins(TextUser.Text, TextPass.Text))
46 {
47 auth.CreateTicket(TextUser.Text, CheckBox1.Checked, “Regged”, DateTime.Now.AddDays(350));
48 }
49 }
Note: “Regged” indicates the UserRole in this case. You just added a Cookie with a timeout of 350 days now. This was just a rough example, of course you still have to add some kind of notice if the login failed and so on.
May 22nd, 2007 — Silverlight
Now this is great, I found a Reflector Tool for .NET Silverlight sites on Ernie Booth’s Blog. It acts as a plugin for the well known Reflector of Lutz Roeder.
You just have to fill in the URL and get the assembly, javascript and root Xaml for the Silverlight Page.
Download: Reflector for Silverlight
May 22nd, 2007 — SQL
Just a quick note on Error Handling for people switching from SQL Server 2000 to SQL Server 2005. The new structured error handing mechanism provided in T-SQL 2005 provides a more simple way to handle exceptions in code. Let’s have a look at the following example which is catching a divide by zero error:
BEGIN TRY
SELECT 5/0
END TRY
BEGIN CATCH
PRINT 'Error Number = ' + CONVERT(VARCHAR(10), Error_Number())
PRINT 'Error Message = ' + Error_Message()
END CATCH
This is serving you with a well formed error message and a clean try/catch error handling as known from programming in .NET. Moreover these classes are available:
ERROR_NUMBER() - Number of error
ERROR_MESSAGE() - Error Message
ERROR_LINE() - Line on which error occurred
ERROR_PROCEDURE() - Procedure in which error occurred
ERROR_SEVERITY() - Severity of error
ERROR_STATE() - State of error
XACT_STATE() - Transaction state
Enjoy 
May 2nd, 2007 — Silverlight
Prepare yourself for some interesting Silverlight posts in the upcoming weeks, I fell in love with the new Microsoft Technology and would like to quote the following statement:
Nik (a long-time developer) was most impressed by how small Silverlight is (4 MB) and how fast it is (it blows away native Javascript routines - without exaggeration, Ajax looks like a bicycle next to a Ferrari when compared to Silverlight).
I agree, I hope Microsoft is promoting it right and will establish Silverlight as a real Flash enemy in the upcoming months. Samples, Tutorials and of course more information on Silverlight will be posted soon. As of now Silverlight Gold is scheduled for summer 2007.
March 29th, 2007 — ASP.NET, WPF
Lester made a sweet WPF/E video carousel which looks pretty nice:
You can download the code on his blog: WPF/E video carousel
March 27th, 2007 — ASP.NET
There are several ways to show who is currently online within your ASP.NET Application if you use the build in Membership Provider. I tested a few on performance and accuary which lead me to the following conclusion:
Using a stored procedure on LastActivityDate is the winner.
Here is how I did it, create this stored procedure:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
– =============================================
– Author: Andreas Kraus
– Create date: 2007-03-27
– Description: Who Is Online Box
– =============================================
CREATE PROCEDURE [dbo].[xx_WhoIsOnline]
@TimeWindow DATETIME
AS
BEGIN
– SET NOCOUNT ON added to prevent extra result sets from
– interfering with SELECT statements.
SET NOCOUNT ON;
— Insert statements for procedure here
SELECT UserName FROM aspnet_Users
WHERE IsAnonymous = ‘FALSE’ AND LastActivityDate > @TimeWindow
END
GO
and create a custom ASP.NET Control featuring this code:
18 cn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
19
20 SqlCommand cmd = new SqlCommand();
21 SqlDataReader dr;
22
23 DateTime TimeWindow = DateTime.Now;
24 TimeSpan TimeSpanWindow = new TimeSpan(0, 10, 0);
25 TimeWindow = TimeWindow.Subtract(TimeSpanWindow);
26
27 cmd.Connection = cn;
28 cmd.CommandText = “battle_WhoIsOnline”;
29 cmd.Parameters.AddWithValue(“@TimeWindow”, TimeWindow);
30 cmd.CommandType = System.Data.CommandType.StoredProcedure;
31
32 cn.Open();
33 dr = cmd.ExecuteReader();
34
35 System.Text.StringBuilder sb = new System.Text.StringBuilder();
36 while (dr.Read())
37 {
38 sb.Append(dr["UserName"].ToString());
39 }
40 dr.Close();
41 cn.Close();
42
43 if (sb.Length > 0)
44 {
45 sb.Remove(sb.Length - 2, 2);
46 }
47
48 Literal1.Text = sb.ToString();
Include the control on any .aspx page and you are set.
March 9th, 2007 — ASP.NET
We recently dropped one of our commercial libraries, the Rebex.Net.Mail Tool. Instead we are using the build in System.NET.Mail Class from ASP.NET 2.0. In ASP.NET 1.1 you were able to use the System.Web.Mail Class and you were able to send mail via GMail by adding those filters:
ASP.NET v1.1:
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
// - smtp.gmail.com use smtp authentication
mailMsg.Filters.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mailMsg.Filters.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "xx");
mailMsg.Filters.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xx");
// - smtp.gmail.com use port 465 or 587
mailMsg.FiltersAdd("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
// - smtp.gmail.com use STARTTLS (some call this SSL)
mailMsg.Filters.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
// try to send Mail
As I switched to the new ASP.NET 2.0 System.Net.Mail class the filters function was gone. Important: mailMsg.Headers.Add in the new class is not the equivalent class to that Filters.Add method, that’s what I thought, too, in the beginning.
In fact it got much easier now, but totally different:
ASP.NET v2.0:
// Smtp configuration
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("xx", "xx");
smtp.EnableSsl = true;
I’d love to have more specific documentations on those changes, but thanks to Microsoft for making our code smaller once again ;).
February 10th, 2007 — ASP.NET
In case you are using the ASP.NET Membership Provider you probably noticed that LastActivityDate doesn’t update correctly whenever someone checked Remember me on his Login. I got a site running with a Cookie timeout of 10080 seconds, a pretty long time. I need to have an accurate LastActivityDate because I want to display whenever a user has actually been active.
So what now? I want to stick to my cookie timeout value and need to update the LastActivityDate manually. Here’s my approach (I love stored procedures).
First create a stored Procedure:
31 set ANSI_NULLS ON
32 set QUOTED_IDENTIFIER OFF
33 GO
34 – =============================================
35 – Author: Andreas Kraus (http:/www.andreas-kraus.net/blog)
36 – Create date: 2007-02-10
37 – Description: Updates LastActivityDate
38 – =============================================
39 ALTER PROCEDURE [dbo].[aspnet_Membership_UpdateLastActivityDate]
40 @UserName nvarchar(256),
41 @LastActivityDate datetime
42
43 AS
44 BEGIN
45 IF (@UserName IS NULL)
46 RETURN(1)
47
48 IF (@LastActivityDate IS NULL)
49 RETURN(1)
50
51 UPDATE dbo.aspnet_Users WITH (ROWLOCK)
52 SET
53 LastActivityDate = @LastActivityDate
54 WHERE
55 @UserName = UserName
56 END
Then use this code in your global.asax by hitting the Application_AuthenticateRequest Event:
31 void Application_AuthenticateRequest(object sender, EventArgs e)
32 {
33 if (User.Identity.IsAuthenticated)
34 {
35 System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
36 System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
37 cmd.Connection = cn;
38 cmd.CommandText = “aspnet_Membership_UpdateLastActivityDate”;
39 cmd.Parameters.AddWithValue(“@UserName “, User.Identity.Name);
40 cmd.Parameters.AddWithValue(“@LastActivityDate”, DateTime.Now);
41 cmd.CommandType = System.Data.CommandType.StoredProcedure;
42 cn.Open();
43 cmd.ExecuteNonQuery();
44 cn.Close();
45 }
46 }
That’s it, now you have a most accurate LastActivityDate value to work with.
February 1st, 2007 — Administration
I bought a new PC for Vista this month. Here’s what I got:
- CPU Intel Core2 Duo E6600 2×2.4GHz TRAY 4MB
- ASUS P5N32-E SLI nForce680i SLI
- 2x 2048MB Corsair PC2-800 CL5 KIT TWIN2X2048
- Coolermaster Mystique RC631 Black ALU o.N
- 500W Enermax Liberty ELT500AWT
- Zalman CNPS 9500 AT
- 2x WD SE16 250GB WD2500KS 7200U/m 16MB
- ASUS (R) 8800GTS 640MB 2xDVI/TV
- Creative (B) X-Fi Xtreme Gamer
I put everything together, started up the PC and was introduced to a freezing/reboot hell. At first it looked like the RAM didn’t work that well with the motherboard, so I changed them. Thing’s were still not stable at all. I upgraded the bios to the latest beta bios (successfully) and BAWM.. that was the end of it. Just a black screen, no booting up anymore. Lots of people are reporting that they have got big problems with nForce680i Chipsets. I’ve sent the board back for a repair now.
In the meantime I got myself the Abit AB9 QuadGT with Intel Chipset. I put everything together yesterday and it’s running very smooth without ANY problems. Intel is the way to go.
nForce is really bogus, I wouldn’t recommend it anymore. Nvidia does great gfx cards but the mainboard chipsets are just horrible.
However, finally I’m setup with Vista, .NET 3.0 and all the other new shiny stuff 
January 14th, 2007 — Personal
I will be in the USA for one week, flying on Monday from Frankfurt/Germany to Los Angeles. The NAMM Show 2007 takes place in Anaheim, I’ll post some impressions when I got back!
Side node: If you installed .NET 3.0 already and use my Deployment Tool, make sure you download the latest bits, I have set the Compiling Version to the most current 2.x .NET Framework Version so it doesn’t choose 3.0 automatically.
Cheers,
Andreas
December 18th, 2006 — ASP.NET
Version 1.9 adds a little requested feature to my ASP.NET Deployment Tool. Whenever you hit Deploy Local a file called compilerlog.txt will be created now in the Application Folder which holds the compiler output.
So if you got lots of warnings and errors popping up it’s easier to investigate them by looking into compilerlog.txt. Of course using Visual Studio is still best for investigation but it appeared that many people do small fixes without firing up VS once again.
“Bin” is checked by default now: It only copies the content of the bin directory when you hit Copy to FTP.
Short overview for people who don’t know it yet:
An avanced and robust Deployment Tool for precompiling your ASP.NET Websites! Pre-Compilation gives your site a performance boost and secures it.
Precompile and deploy your Website: Specific Error Panel, FTP Support, Deploy to Network, Merge Assemblies, easy to use.
Download it here: ASP.NET Deployment Tool v1.9 (I didn’t update the version number on that page yet, don’t mind it, it’s v1.9)
Edit: I set the background color of the Toolstrip to a static color as many people use black for their desktops 
December 15th, 2006 — Microsoft, Personal
I wanted to do this a long time ago already, now, finally, I finished redoing it. Hope you like it
ASP.NET AJAX RC1 has been released, the latest release before the fully supported final version
And Visual Studio 2005 SP1 Final is out now: VS 2005 SP1 Final
Enjoy 