Click here to Skip to main content
15,895,423 members
Home / Discussions / C#
   

C#

 
Questionfull text search Pin
annie_bel4-Nov-10 3:31
annie_bel4-Nov-10 3:31 
AnswerRe: full text search Pin
JohnLBevan4-Nov-10 3:53
professionalJohnLBevan4-Nov-10 3:53 
AnswerRe: full text search Pin
Adam R Harris4-Nov-10 4:53
Adam R Harris4-Nov-10 4:53 
QuestionImpersonation using C# Pin
JohnLBevan4-Nov-10 1:45
professionalJohnLBevan4-Nov-10 1:45 
AnswerRe: Impersonation using C# Pin
Adam R Harris4-Nov-10 4:49
Adam R Harris4-Nov-10 4:49 
AnswerRe: Impersonation using C# Pin
Manfred Rudolf Bihy4-Nov-10 5:06
professionalManfred Rudolf Bihy4-Nov-10 5:06 
GeneralRe: Impersonation using C# Pin
JohnLBevan9-Nov-10 5:43
professionalJohnLBevan9-Nov-10 5:43 
GeneralRe: Impersonation using C# Pin
Manfred Rudolf Bihy12-Nov-10 2:07
professionalManfred Rudolf Bihy12-Nov-10 2:07 
Hi JB,

thanks for sharing your class with us.
I have some issues with your design though:

1. In the constructor I would not call Impersonate(...) straight away.
There are two reasons for this:
a.) Code in a constructor that will likely cause an exception
is a real pain in the a**e.
b.) Let the user of your library decide when Impersonation starts
and ends.

Store user account and domain in instance variables. Password should not be stored in
the class (as you have already done) but could be retrieved via GetPassword() (see 2.).
I would make an additional overload Impersonate() a public function and add another function
like Revert() that will call context.Undo() and set context = null. bool IsImpersonating()
would be nifty (context != null) too.

2. Move the function GetPassword to a separate class that implements an interface say
IStringPasswordProvider. Have a property that allows the user of your library to inject
an instance of his or her own implementation of IPasswordProvider.

public interface IStringPasswordProvider
{
    String GetPassword(String account);
    String GetPassword(String account, String domain);
}

public class DefaultPasswordProvider : IStringPasswordProvider
{
    string GetPassword(string account)
    {
        string[] accountSplit = SplitAccount(account);
        return GetPassword(accountSplit[0], accountSplit[1]); 
    }
    string GetPassword(string domain, string user)
    {
        string pass = string.Empty;
        pass = "todo"; //todo:add code here to return the password for the given user from the secure store.
        return pass;
    }
}

A password provider might read passwords from a DB or may be the app.config (web.config) file.

Please let me know what you think of these changes.

Best Regards

Manfred
QuestionServer based on AsyncCallback not running as expected Pin
Tichaona J4-Nov-10 1:08
Tichaona J4-Nov-10 1:08 
AnswerRe: Server based on AsyncCallback not running as expected Pin
jschell4-Nov-10 8:32
jschell4-Nov-10 8:32 
QuestionGot a working ICMP listener; but how does it work? Pin
nebbukadnezzar4-Nov-10 0:28
nebbukadnezzar4-Nov-10 0:28 
QuestionRetrieve Value from TextBox Which is created in the code behind Pin
HatakeKaKaShi3-Nov-10 22:54
HatakeKaKaShi3-Nov-10 22:54 
AnswerRe: Retrieve Value from TextBox Which is created in the code behind Pin
John Gathogo4-Nov-10 1:00
John Gathogo4-Nov-10 1:00 
AnswerRe: Retrieve Value from TextBox Which is created in the code behind Pin
alrosan4-Nov-10 8:05
alrosan4-Nov-10 8:05 
Questionhow to find toolstrip button on a form by name Pin
Tridip Bhattacharjee3-Nov-10 21:27
professionalTridip Bhattacharjee3-Nov-10 21:27 
AnswerRe: how to find toolstrip button on a form by name [modified] Pin
Eddy Vluggen3-Nov-10 22:30
professionalEddy Vluggen3-Nov-10 22:30 
AnswerRe: how to find toolstrip button on a form by name Pin
_Erik_4-Nov-10 5:47
_Erik_4-Nov-10 5:47 
QuestionAdd Custom Utility Toolbar To VS2010 Pin
Kevin Marois3-Nov-10 12:52
professionalKevin Marois3-Nov-10 12:52 
AnswerRe: Add Custom Utility Toolbar To VS2010 Pin
Henry Minute3-Nov-10 12:56
Henry Minute3-Nov-10 12:56 
Questiondebugging mode behaves differently than final build Pin
kruegs353-Nov-10 6:02
kruegs353-Nov-10 6:02 
AnswerRe: debugging mode behaves differently than final build Pin
_Erik_3-Nov-10 6:14
_Erik_3-Nov-10 6:14 
GeneralRe: debugging mode behaves differently than final build Pin
kruegs353-Nov-10 6:41
kruegs353-Nov-10 6:41 
GeneralRe: debugging mode behaves differently than final build Pin
_Erik_3-Nov-10 6:49
_Erik_3-Nov-10 6:49 
AnswerRe: debugging mode behaves differently than final build Pin
Eddy Vluggen3-Nov-10 22:35
professionalEddy Vluggen3-Nov-10 22:35 
QuestionHow to set pixel into bitmap with Pixel format of Format8bppIndexed ? [modified] Pin
Yanshof3-Nov-10 4:14
Yanshof3-Nov-10 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.