Amazon Web Service play

Thought I would share the helper I wrote for the amazon service to do this, in case anyone else is trying something like this with other services.



Firstly : This solution uses an ActiveX control , so it is targetted at Intranet Applications for SOEs where IE is the standard browser.I am sure there are other activex file uploaders out there that provide similar (probably better) functionality but I knew how this one worked from previous work I had done with it in Domino using a java servlet to receive the files.
Basically in this solution I re-coded the servlet as a Httpmodule that read the request inputstream and processed the data coming from the activex control. The activex control thinks it is talking to a Domino Server, so the code is based around getting the functionality out of the control while tricking it into thinking it is being used with a Domino Backend. In fact the backend is the .net application which stores the uploaded files into the sql database.
The setup is as usually for my solutions. Just create a new sql database on your sql server/msde and run the DBSetup.sql code against it. Then edit the web.config so the connection string matches your database. Once that is done compile and run. The cab file that contains the activex control is in the project.
The inotes ActiveX control provides the following features:

But if connect to the server via a webdav client connection then you get the webdav experience. Which allows you to create , edit, delete , copy , move , rename lock and unlock files and create, rename and delete folders.
To setup the server you need to do the following steps and also I recommend visiting http://www.zorched.net/category/webdav/ for lots of helps on configuring webdav for .net
As this is a webdav server you will also need to adjust the IIS setting for the website so that it knows how to handles the additional HTTP methods that webdav supports (LOCK, UNLOCK,PROPFIND,MKCOL etc ). Basically because we want .net to intercept all the calls (because we are redirecting all queries to our database not the filesystem) we need to adjust the application extension mapping so all extensions on all VERBs map to the asp IIS handler.
To do this you need to open the application properties of your website from the IIS console and then click the configure button. You then need to remove all of the application extensions and then create a new one for all extensions (.*) for all verbs that executes the .net isapi handler.

A good article explaining the ins-and-outs of this is available here
Once you have completed this setup you should be able to see the webdav server through a webdav connection, and therefore be able to add files and away you go..
I have to give credit to another project for helping me out with this one. The database and database interface stuff was all me, but a lot of the webdav implementation code I got from the webdav server project on sourceforge . If you are looking at developing your own webdav server or extending this code I totally recommend you check out that project. There project uses alot of events and delegates, where as I went with a single interface handler to simplify the code.
If you need any help, or want to add feedback then please do so. Microsoft office and windows have a number of wonderful webdav quirks, which you may need to get around depending on your environment and setup. A good place to start for a list of these is here
So good luck..
Labels: Code
Labels: Code




I work for an organisation that provides IT services to many different and separate organisations. Some of these organisations use MS Exchange and some use IBM Domino for mail infrastructure. I have recently had to write an “inbox aware” .net application that can read and process inbox data, but I needed to do this independently of the underlying mail infrastructure, as it needed to run for all organisations.
I thought about simply using POP3 for this, but this has some limitations.

If you are using a Domino Server then you will need to set the MailBoxType to “Domino” and set the other keys to match the domino server,mail database location,domino userid and password.
If you are using Domino you will also need to copy the (dotNetDataViewer.xml) agent ( Found in the HojuRetriever.nsf database in the Domino Folder of the solution ) into the mail database you will be accessing. The agent needs to run with at least Designer access.

You will then need to grant access to those SQL elements so that you can access them from your .net solution.
The solution file contains a single aspx page that holds a standard gridview and code that does all of the logic. The data is accessed from the database via DataClass. I have created an Interface called IpagingFilterDataSource that matches what is required if you want to write your own class to do the datahandling. This will obviously be required if you are going to extend this in anyway.
int GetDataSize();
int GetDataSize(string FilterField, string FilterVal);
int GetDataSize(string FilterField, DateTime SearchDateStart, DateTime SearchDateEnd);
DataSet GetPage(int Pagesize, int CurrPage, string SortCol, string SortDirection);
DataSet GetPage(int Pagesize, int CurrPage, string SortCol, string SortDirection, string FilterField, string FilterVal);
DataSet GetPage(int Pagesize, int CurrPage, string SortCol, string SortDirection, string FilterField, DateTime SearchDateStart, DateTime SearchDateEnd);
In this solution I put together a class MyCustomSQLPageFilterDataSource which supports the IpagingFilterDataSource and retrieves data from the customers table of the test database via a stored proc called up_Customers_list.
In the page_load event in the default.aspx.cs file there is a line
MyCustomSQLPageFilterDataSource MyDataSource = new MyCustomSQLPageFilterDataSource("SQLServer", "CustomerTestDatabaseName", "Uid", "passwd");
You will need to change this to suit your setup based on the database that you created and the userid and passwd for it.
The solution provides a page with a gridview that supports the following features:

Probably one of the most popular controls that are talked about on web forums and available from third parties are file upload controls. I have found however there is a lack of information and code for people who want to manage those files once they get to the server.
Since I have recently been doing a lot of work with secure workflow in .Net I have needed to use this functionality, so I have created a sample project showing what I have done. The sample project performs the following functions:
The zipped C# vs2005 solution can be downloaded here .
You will need to create a new SQL Database and run the sql code in the DBSetup Folder of the Project to create the required database tables and stored procs. You may also need to setup the security for these SQL elements depending on how you have your test environment setup. You will then need to adjust the AttachmentDatabase connection string in the web.config to match your settings.
I have used Typed Datasets through a Data Layer. I have included all of the DataSets and Data Link layer in the Web Project. Usually I would separate these out into their own projects, but for this sample I haven’t done that.
Some screen shots of it in action are below.
A record with various types of files attached.
Adding more files to an existing record.
A blank record.
By using this system you can allow a specific group of users to manage access to the .net application themselves, as it supports AD group membership then the Access Control is very easy to use.
A couple of screen shots of the system in action are below.
Access Control List
Roles Tab
Searching Active Directory
Then set this to false. Otherwise set it to true to allow uses to update it.Labels: C#, Code, RoleProviders

There are a couple of steps to get it working.
You need to create a new empty database on your SQL server and run the SQL code file that is in the DatabaseSetup folder of the solution this will:
You will then need to grant access to those SQL elements so that you can access them from your .net solution.
The solution file contains a single aspx page that holds a standard gridview and code that does all of the logic. The data is accessed from the database via DataClass. I have created an Interface called IpagingFilterDataSource that matches what is required if you want to write your own class to do the datahandling. This will obviously be required if you are going to extend this in anyway.
public interface IPagingFilterDataSource
{
int GetDataSize();
int GetDataSize(string FilterField, string FilterVal);
DataSet GetPage(int Pagesize, int CurrPage, string SortCol, string SortDirection);
DataSet GetPage(int Pagesize, int CurrPage, string SortCol, string SortDirection, string FilterField, string FilterVal);
}
In this solution I put together a class MyCustomSQLPageFilterDataSource which supports the IpagingFilterDataSource and retrieves data from the customers table of the test database via a stored proc called up_Customers_list.
In the page_load event in the default.aspx.cs file there is a line
MyCustomSQLPageFilterDataSource MyDataSource = new MyCustomSQLPageFilterDataSource("SQLServer", "CustomerTestDatabaseName", "Uid", "passwd");
You will need to change this to suit your setup based on the database that you created and the userid and passwd for it.
The solution provides a page with a gridview that supports the following features:
Here are some additional screen shots of it in action:
Drag and drop in action
Right-click on column header and filter
After Filter Applied
After adjustment of pagesize to 5
Add new class file in this folder called ADSQLRoleProvider.cs
Paste the following code into the class code file and save it.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;
using System.Web;
using System.Security.Principal;
/// <summary>
/// Summary description for ADSQLRoleProvider
/// </summary>
public class ADSQLRoleProvider : System.Web.Security.SqlRoleProvider{
public ADSQLRoleProvider(){}
#region ADLookup & Support Methods
private string[] getusersADgroups(IIdentity User)
{
//HttpContext.Current.User;
WindowsIdentity Wident = (WindowsIdentity)User;
List<string> groups = new List<string>();
IdentityReferenceCollection UGroups = Wident.Groups;
foreach (IdentityReference Grp in UGroups)
{
NTAccount acc = (NTAccount)Grp.Translate(typeof(NTAccount));
groups.Add(acc.Value);
}
return groups.ToArray();
}
private string[] GetRolesForGroup(string groupname)
{
return base.GetRolesForUser(groupname);
}
#endregion
#region Extended SQLRoleProvider Methods
public override bool IsUserInRole(string username, string roleName)
{
if (base.IsUserInRole(username,roleName))
{
return true;
}
else
{
string[] Ugrps = getusersADgroups(HttpContext.Current.User.Identity);
string[] GroupsRoles;
foreach (string g in Ugrps)
{
GroupsRoles = GetRolesForGroup(g);
foreach (string grole in GroupsRoles)
{
if (grole == roleName)
{
return true;
}
}
}
}
return false;
}
public override string[] GetRolesForUser(string username)
{
System.Collections.Generic.List<string> roleList = new List<string>();
string[] ActualUserRoles = base.GetRolesForUser(username);
//Only do the next check if the username matches the current web user and the users roles are empty
if ((ActualUserRoles.Length == 0) && (username.ToLower() == HttpContext.Current.User.Identity.Name.ToLower()))
{
string[] Ugrps = getusersADgroups(HttpContext.Current.User.Identity);
string[] GroupsRoles;
foreach (string g in Ugrps)
{
GroupsRoles = GetRolesForGroup(g);
foreach (string grole in GroupsRoles)
{
if (!(roleList.Exists(delegate(string s) { return s == grole; })))
{
roleList.Add(grole);
}
}
}
return roleList.ToArray();
}
else
{
return ActualUserRoles;
}
}
#endregion
}
Open the web.config file and make sure that the original connection string for the Roleprovider database is correct.
Change the role provider section in the web.config to
Compile the website to make sure you don’t get errors.
You have now update the application to use a custom sqlroleprovider that will first check for roles of a user, and if it doesn’t find any it will then check for any roles belonging to any Active Directory groups that user is a member of.
To test that this is working remove yourself from the role by running the stored proc aspnet_UsersInRoles_RemoveUsersFromRoles
For my example above this is
EXEC aspnet_UsersInRoles_RemoveUsersFromRoles 'SQLProviderTest', 'MYDOM\User1', 'Admin'
Re-run the application to make sure that you are not in any roles.
Now add a domain group that you are a member of to the Admin role. For my example the user MYDOM\User1 is a member of MYDOM\IT_Apps group so I will add that one with the Stored proc command
EXEC aspnet_UsersInRoles_AddUsersToRoles 'SQLProviderTest', ' MYDOM\IT_Apps', 'Admin', 8
If you run the application again you will see that you are in the role.
In up and coming blogging I will talk about how to build the user-front end to this, that allows users to search, select and assign roles to AD users and groups. This will allow you to build easy use managed applications with role based security. Some screen shots of what I am talking about are below:

Labels: C#, Code, RoleProviders
I have been working on two areas of e-mail lately with .net. These are: