August 28, 2006
@ 05:09 AM
The Microsoft ATLAS Ajax framework makes heavy use of web services to get data from the server to display on a page via JavaScript. I implemented some ATLAS pages in a web that uses a custom form based authentication method. I'm using the asp.net session state to keep track of the currently logged on user. For the ATLAS web services this didn't work because I got exceptions when accessing the session object.

So for a while I was running with unsecured web service methods, checking the referrer server variable is in no way a secure method. But somehow I ran into the EnableSession property of the WebMethod attribute. By default web methods for performance reasons don't have access to the session state. By setting:
[WebMethod(Description = "method description",EnableSession=true)]      
this changes and I can now access my authentication object to check for the current user.

This should also work for other authentication methods like the ones built into asp.net.


 
Categories: ASP.Net

I using the Windows Indexing Service for the search on of my web sites because most of the content is in flat files. I haven't touched the configuration for years and it works fine (even though the search results are not always what you would expect).
Recently I added two new subdirectories to the site, a normal one and one virtual directory for DasBlog.
I didn't really thing about at the time but realized later that I don't want any of the two new directories to show up in my search results as they are separate sub sites.
For a normal directory, you have to go into Indexing Service node of the Computer Management MMC and find your web site. Add a new directory and set the property to 'Include in Catalog' to No. In the same list
is also an entry for the new virtual directory but there is no delete feature as there is on
directories that you created yourself. Switch to IIS manager and look at the 'Virtual Directory' tab of the properties for the virtual directory. I unticked 'Index this resource' but they directory didn't disappear in Indexing Service. When I created the new virtual directory it inherited the 'Index this resource' property from its parent site and the Indexing directory was created. Changing the property doesn't remove the directory, surely a bug.
How to fix this? I exported the settings for the virtual directory into an XML file, deleted it and then created a new one from that exported file. The indexing service directory is gone.

This was on a 2003 Server, but should be similar on Windows 2000.


 
Categories: IT Pro

For a small project I had to display web pages within a Windows form, no problem, just drag a webBrowser control onto the form set a url. Works fine but it turned out the pages I have to display require basic authentication over SSL. There is no property on the control to set the credentials like there is for the .net WebRequests. There are some people on the net asking about this but I didn't find an easy answer. I went through all the members of the control and in addition to the url property I used before I found the Navigate method, one of the overloads takes an AdditionalHeader parameter. I couldn't exactly remember how the authentication header looked like, so I fired up Wfetch (IIS Resource Kit) to look at them. The header in question is something like:

Authorization: Basic RmlsZVVwbG9hZXVyOjG4NUgkOTNT7UpTeQM=\r\n

the crypted string in the middle is a base64 version of “myusername: mypassword”
the whole code is:

    
     System.Uri uri = new Uri("http://www.mysite.xxx");

     // encode the credentials in Base64
     byte[] authData = System.Text.UnicodeEncoding.UTF8.GetBytes("myusername: mypassword");
            
     // build the whole header
     string authHeader = "Authorization: Basic " + Convert.ToBase64String(authData) + "\r\n";

     // open the page with the extra header
     webBrowser1.Navigate(uri, "", null, authHeader);

 
Categories: ASP.Net

When working on my asp.net projects on the road I never had Visual Studio, so for the first time I had to look into how to compile my projects from the command line.

I started using simple batch files like this one:
%windir\Microsoft.NET\Framework\v1.1.4322\csc.exe /target:library  /debug /reference:TweeNet.Topas.Business\bin\TweeNet.Lib.Core.dll;
TweeNet.Topas.Business\bin\TweeNet.Lib.Data.dll;
TweeNet.Topas.Business\bin\TweeNet.Lib.Web.dll;
TweeNet.Topas.Business\bin\interop.saxfilelib.dll /out:TweeNet.Topas.Business\bin\TweeNet.Topas.Business.dll /resource:TweeNet.Topas.Business\helpers\atom\mediatypes.txt
/recurse:TweeNet.Topas.Business\*.cs
Note that this is all on one line and it compiles all C# source files in a certain directory. A full description of the compiler switches is in the SDK.

I then moved on to use response files which are pretty much the same but a bit cleaner:
/target:library
/out:TweeNet.Topas.UI.Web\bin\TweeNet.Topas.Business.dll
/debug
/nologo
/reference:TweeNet.Topas.UI.Web\bin\TweeNet.Lib.Core.dll
/reference:TweeNet.Topas.UI.Web\bin\TweeNet.Lib.Data.dll
/reference:TweeNet.Topas.UI.Web\bin\TweeNet.Third.Util.dll
/recurse:TweeNet.Topas.Business\*.cs
solutioninfo.cs
put this in a text file 'biz.rsp' and then use it in another batch:
%tndndir\csc.exe @biz.rsp
This assumes I navigated into my working directory or have it in my path. Rather than hardcoding the compiler
here, I use a environment variable %tndndir  pointing to %windir\Microsoft.NET\Framework\vx.x.xxxx\. This way I can easly switch between 1.1 and 2.0 without having to change any of these batch files.

When I moved over version 2.0 of the framework, it all became easier because you can now use your Visual Studio project files as 'make' files.
With MSBuild, the new Microsoft build system you can do somthing like:
%tndndir\msbuild.exe core\TweeNet.Lib.Core.csproj /t:Build /nologo
This means you can use the same project files when at work using Visual Studio and when on the road with just the framework. Of course you need the project file in the first place. If you don't have Visual Studio 2005, they are a bit of a pain to create manually, but you can always get one of the free Express versions to do this for you.

If you are using ASP.Net it's also a good idea after building your project to compile the whole thing including the stuff in the aspx files.
%tndndir\aspnet_compiler.exe -v /topas14/ -p \www\TopasSolution\TweeNet.Topas.UI.Web

For most of my web projects I'm using the old 1.1 web project type. You can do this in Visual Studio 2005 by installing the Visual Studio 2005 Web Application Projects. Back on the road however I don't have Visual Studio and don't need to install the whole lot. Just download the msi file and extract the file 'Microsoft.WebApplication.targets' I'm using the Less MSIérables utility for this. Copy the target file onto your USB drive and use a batch file like this to copy it to the correct location:

mkdir "%ProgramFiles%\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications"
copy Microsoft.WebApplication.targets "%ProgramFiles%\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications\"



 
Categories: Work on the road