by David Kiff
23. December 2006 04:39
To add a header row to a CSV file I needed to append to the beginning of the text file, this however is not possible, instead I had to create a new file and write the original files contents to it after the header has been written:
StreamReader reader = new StreamReader(File.Open("Original.csv", FileMode.Open, FileAccess.Read));
StreamWriter writer = new StreamWriter(File.Create("Newfile.csv"));
writer.WriteLine("StudentID, Username, Forename, Surname"); //Write header row.
writer.WriteLine(reader.ReadToEnd()); //Write original file to the new one.
writer.Flush();
writer.Close();
reader.Close();
8a071195-d329-4df6-ba0e-45c09677598f|0|.0
Tags:
by David Kiff
16. December 2006 07:28
My Final Year Project requires Active Directory Authentication, ASP.NET has a very simple GUI to set this up although I have used LDAP to create finer grained code- more customisable :D. Here is the method I have used:
public bool IsAuthenticated(string domain, string username, string pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result) { return false; }
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch
{
throw
}
return true;
}
If you want to create a simpler AD login we can use the ASP.NET Login control with Memberships. Example memberships code for the web.config file:
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear/>
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ActiveDirectory" connectionUsername="userName" connectionPassword="password" attributeMapUsername="sAMAccountName" enableSearchMethods="true" requiresUniqueEmail="true"/>
</providers>
</membership>
The Login Control can utilize the membership:
<asp:Login ID="LoginControl" runat="server"
EnableTheming="true"
DisplayRememberMe="true"
FailureText="Login attempt has failed.">
</asp:Login>
To me it seems more beneficial to use the first option, the membership way is easier although you require administration rights for the connection.
8a42b6f3-a6f4-4012-8b68-b09a341b3ec6|0|.0
Tags:
by David Kiff
16. December 2006 07:28
My Final Year Project requires Active Directory Authentication, ASP.NET has a very simple GUI to set this up although I have used LDAP to create finer grained code- more customisable :D. Here is the method I have used:
public bool IsAuthenticated(string domain, string username, string pwd)
{
string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);
try
{
// Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result) { return false; }
// Update the new path to the user in the directory
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch
{
throw
}
return true;
}
If you want to create a simpler AD login we can use the ASP.NET Login control with Memberships. Example memberships code for the web.config file:
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear/>
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ActiveDirectory" connectionUsername="userName" connectionPassword="password" attributeMapUsername="sAMAccountName" enableSearchMethods="true" requiresUniqueEmail="true"/>
</providers>
</membership>
The Login Control can utilize the membership:
<asp:Login ID="LoginControl" runat="server"
EnableTheming="true"
DisplayRememberMe="true"
FailureText="Login attempt has failed.">
</asp:Login>
To me it seems more beneficial to use the first option, the membership way is easier although you require administration rights for the connection.
by David Kiff
14. December 2006 04:27
DavidKiff.co.uk now has Live RSS feeds!

9d025753-a842-4388-bd37-6fdc3897436b|0|.0
Tags: