ASP.NET Features vs Real Applications

The most important thing to point out whenever I talk about ASP.NET 2.0 data-driven applications is:     "With the SqlDataSource and GridView or   DetailView controls you can         quickly build up tiny applications that just      need to be set up asap.       This has to do nothing with REAL   best practice applications!" Therefore I was pretty happy to read "The Code Spaghetti generation is back" in Pascal Leloup's Blog (Help .NET). Here is my statement:

Cool Tool: Cassini here power toy

[...]The .NET Framework 2.0 comes with a built-in webserver, based on the old Cassini web server. So I wanted to be able to easily set up any directory to have its contents served up on an as-needed basis. The result is an addition to the Windows Explorer right-click menu...[Robert McLaws] Chris Fraizer wrote it thgether in a small app. Here is my version with a few modifications: using System; using System.IO; using System.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; using System.Text; using System.Runtime.InteropServices;   namespace WebServerHere {     class Program     {         static void Main(string[] args)         {             if (args.Length >= 1)             {                 string _path;                   string _command =                     Path.Combine(                     RuntimeEnvironment.GetRuntimeDirectory(),                     "WebDev.WebServer.EXE");                   StringBuilder _commandArgs = new StringBuilder();                   Random _r = new Random();                   string _port = _r.Next(1024, 9000).ToString();                   if (args.Length == 2)                 {                     _port = args[1];                 }                     //grab the original path                 _path = args[0];                   _commandArgs.Append(" /path:\"");                 _commandArgs.Append(_path);                 _commandArgs.Append("\"");                 _commandArgs.Append(" /port:");                 _commandArgs.Append(_port);                 _commandArgs.Append(" /vpath: \"/");                 _commandArgs.Append(_path.Substring(                     _path.LastIndexOf('\\') + 1));                 _commandArgs.Append("\"");                   ProcessStartInfo _info =                     new ProcessStartInfo();                   _info.Arguments = _commandArgs.ToString();                 _info.CreateNoWindow = true;                 _info.FileName = _command;                 _info.UseShellExecute = false;                 _info.WorkingDirectory =                     _command.Substring(0, _command.LastIndexOf('\\'));                     Process.Start(_info);                   using (Control _c = new Control())                 {                     Help.ShowHelp(_c, "http://localhost:" + _port + "/");                 }             }             else             {                 MessageBox.Show("Usage:\n\tWebServerHere.exe <path> [port]",                     "WebServerHere", MessageBoxButtons.OK,                     MessageBoxIcon.Information);             }         }     } } And the Non-Admin installation reg-file: Windows Registry Editor Version 5.00 [HKEY_Current_User\SOFTWARE\Classes\Folder\shell\VS2005 WebServer]@="ASP.NET 2.0 Web Server Here" [HKEY_Current_User\SOFTWARE\Classes\Folder\shell\VS2005 WebServer\command]@="\"%SystemRoot%\\System32\\WebServerHere.exe\" %1"

A week full of community

Monday: I met Andreas Hoffmann (2nd UG Lead of the VfL Usergrop) and Peter Nowak (Head of, a community for .NET related vocational education) at Starbucks in Düsseldorf. Tuesday: Benjamin Mitchell notified me that one of my sessions was voted by the british community and I'll have a session at the Developer Developer Developer Day. Wednesday: I'm in contact with the Student Partners in Wuppertal now (better said Anselm Haselhoff because Marcel Wiktorin is moving and has not replied yet :-)). Thursday: Usergroup meeting in Düsseldorf: Sebastian Weber (Developer Evengelist at Microsoft Germany and member of the VfL-UG) answered all our members questions about SQL Server 2005 and Tuan Nguyen (Lead of and VfL-Member) talked about the Annos project. Great, thanks guys. Friday: I updated the VfL-Site and fixed a few bugs.

Internet Explorer Developer Toolbar Beta

The IE Developer Toolbar provides several features for deeply exploring and understanding Web pages.-- Explore and modify the document object model (DOM) of a web page.-- Locate and select specific elements on a web page through a variety of techniques.-- Selectively disable Internet Explorer settings.-- View HTML object class names, ID's, and details such as link paths, tab index values, and access keys.-- Outline tables, table cells, images, or selected tags.-- Validate HTML, CSS, WAI, and RSS web feed links.-- Display image dimensions, file sizes, path information, and alternate (ALT) text.-- Immediately resize the browser window to 800x600 or a custom size.-- Selectively clear the browser cache and saved cookies. Choose from all objects or those associated with a given domain.-- Choose direct links to W3C specification references, the Internet Explorer team weblog (blog), and other resources.-- Display a fully featured design ruler to help accurately align objects on your pages.

Poland Rocks

It was the second time this year I went to Warsaw (Poland). The Microsoft Technology Summit happend for the first time and was a big success. An amazing event: Two days, about two-thousand attendees, six parallel tracks, four a day. I had about three-hundred listeners in each of my sessions ("Layout and Personalization with ASP.NET 2.0" and "Data-Driven Application with ASP.NET 2.0"). The feedback in the breaks was great. Thanks to everybody at Microsoft Poland especially Artur and Dominika. I met Rafal Lukawiecki Fred Baumhardt and Maciej Pilecki And had an interesting discussion with Yogesh Bhalerao.The audience while i was speaking And the view out of my room in the Meriott.

Don't mess with sharepoint...

Carefully said I do not like that sharepoint "hijacks" the Internet Information Server. When you create a virtual directory it is just not accessable because SharePoint took over IIS. Funny fact: This is the second post how to fix issues with IIS and "extension" that cause issues :-) So i decided to hack a small utility serving my needs: (3.46 KB) Enables to exclude applications from sharepoint services through the directory context menu. Install using the "-install" switch; Uninstall using "-uninstall" switch. Because I'm running my machine under a LUA (Limited User Account) i wrote the tool in a way that you can install and uninstall it without administative rights - the contextmenu will be installed per user! if(args[0]=="-install") {     RegistryKey _rkey = Registry.CurrentUser;     _rkey = _rkey.OpenSubKey("SOFTWARE\\Classes",true);     _rkey = _rkey.CreateSubKey("Folder").CreateSubKey("shell");     _rkey = _rkey.CreateSubKey("Exclude from Sharepoint");     _rkey = _rkey.CreateSubKey("command");     _rkey.SetValue(null, App.Application.ExecutablePath + " \"%1\""); } else if(args[0]=="-uninstall") {     RegistryKey _rkey = Registry.CurrentUser;     _rkey = _rkey.OpenSubKey("SOFTWARE\\Classes\\Folder\\shell",true);     _rkey.DeleteSubKeyTree("Exclude from Sharepoint"); } else { ... }   The Implementation works with the webserver extensions version 4.0 or higher       RegistryKey _rkey = Registry.LocalMachine;     _rkey = _rkey.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\" +         "Web Server Extensions",true);         foreach(string _subKeyName in _rkey.GetSubKeyNames())     {         try         {             int.Parse(_subKeyName.Replace(".",""));             RegistryKey _fpKey = _rkey.OpenSubKey(_subKeyName,true);             _fpDir = (string)_fpKey.GetValue("Location");         }         catch(Exception _ex)         {             string _err = _ex.ToString();             break;         }     }   and uses the stsadm.exe from the shared tools of the server extensions.     System.Diagnostics.Process _p = new System.Diagnostics.Process();     _p.StartInfo.FileName = Path.Combine(_fpDir, "BIN\\stsadm.exe");     _p.StartInfo.Arguments = "-o addpath -url http://localhost/" +         _strProjectName + " -type exclusion";     ...     _p.Start();  

ASP.NET Version Issues

I develop with 1.1 and 2.0 - When VS 2003 creates a web solution it is configured to use the 2.0 runtime. Placeing the following code to the Global.asax's of your 1.1 projects and setting execute permissions on the aspnet_regiis.exe helps much. protected void Application_Start(Object sender, EventArgs e) {       if(System.Environment.Version.Major==2)       {             System.Diagnostics.Process _p = new System.Diagnostics.Process();             _p.StartInfo.FileName = "%WINDIR%\\Microsoft.NET\\Framework\\v1.1.4322\\aspnet_regiis.exe";             _p.StartInfo.Arguments = "-s W3SVC/1/ROOT" + Request.ApplicationPath;             _p.StartInfo.UseShellExecute = false;             _p.StartInfo.RedirectStandardOutput = true;             _p.Start();       } }  

Simply resize an uploaded image

I got an E-Mail from a student this morning asking how to thumbnail an uploaded image. Here is a "quick" solution (there are a few things you can do to increase quality, set JPEG compression factor or keep gif transparency). If you like to dig deeper have a look at one of the articles i wrote for the DotNetPro magazine's #Talk column (dnp0305_Thumbnail.pdf [German])   <%@ Page Language="C#" %>   <script runat="server" Language="C#">       public void UploadFile(object sender, EventArgs e)     {         System.Drawing.Image _img =              System.Drawing.Image.FromStream(             this.InputTypeFile.PostedFile.InputStream);           int _maxWidth = 100;         int _maxHeight = 100;           int _width = _img.Width;         int _height = _img.Height;           string _filename =               System.IO.Path.GetFileName(               this.InputTypeFile.PostedFile.FileName);                     string _uploadPath = System.IO.Path.Combine(             Server.MapPath(".\\upload\\"),             _filename);                 if (_width > _height)         {             width = Math.Abs((int)(height *                         _img.Width /                         _img.Height));             _height = _maxHeight;         }         else         {             _height = Math.Abs((int)(_maxWidth *                         _img.Height /                         _img.Width));             _width = _maxWidth;         }                 System.Drawing.Image _newImg =             _img.GetThumbnailImage(width, height, null, null);            _newImg.Save(_uploadPath);            _img.Dispose();     }   </script> <body>     <form id="form1" runat="server">       <input id="InputTypeFile" type="file" runat="server" />     <asp:Button ID="Submit" OnClick="UploadFile" Text="Upload" />       </form> </body> </html>

RE: httpOnly cookies in ASP.NET 1.1

Scott posted a solution to support httpOnly cookies in ASP.NET 1.1 but pointed out some problems when you run the code on 2.0( Here is a solution: protected void Application_EndRequest(Object sender, EventArgs e) { if(System.Environment.Version.Major<2) { foreach(string cookie in Response.Cookies) { const string HTTPONLY = ";HttpOnly"; string path = Response.Cookies[cookie].Path; if (path.EndsWith(HTTPONLY) == false) { //force HttpOnly to be added to the cookie Response.Cookies[cookie].Path += HTTPONLY; } } } }