Professional Web Applications Themes

using System.Net.NetworkCredential class - ASP.NET

I am using NUnitASP and I have run into problem "faking" user credentials. In my ASP.Net/C# application, I have turned off anonymous access to the web app and I allowing Windows groups to handle the permissions to the app. Things are working perfectly, i.e. only user groups that are allowed can log into the app and see what they are supposed to, when the users enter their credentials through IE. It is when I try to enter the credentials programmatically with NUnitASP that I cannot set the credentials. In most cases, using System.Net.CredentialCache.DefaultCredentials would be fine and this works as ...

  1. #1

    Default using System.Net.NetworkCredential class

    I am using NUnitASP and I have run into problem "faking" user
    credentials. In my ASP.Net/C# application, I have turned off
    anonymous access to the web app and I allowing Windows groups to
    handle the permissions to the app. Things are working perfectly, i.e.
    only user groups that are allowed can log into the app and see what
    they are supposed to, when the users enter their credentials through
    IE.

    It is when I try to enter the credentials programmatically with
    NUnitASP that I cannot set the credentials. In most cases, using
    System.Net.CredentialCache.DefaultCredentials would be fine and this
    works as expected. However, I want to test other roles besides my own
    in the app and this is where I need to use the
    System.Net.NetworkCredential class.

    For some reason I do not understand, I cannot pass a username,
    password and domain to this class and have these values detected as
    valid credentials. Has anyone used NUnitASP? If so, can you please
    share some sample code showing how this works? If you have not used
    NUnitASP, but are familiar with the System.Net.NetworkCredential
    class, again I could use some coaching on how to use this class.
    Thank you in advance for your help.

    Carlton
    Carlton858 Guest

  2. #2

    Default Re: using System.Net.NetworkCredential class

    Can you post a sample of the NetworkCredential code you are using?

    --
    Eric Marvets
    Principal Consultant

    the bang project

    <shameless self promotion>

    Email [email]salesbangproject.com[/email] for Information on Our Architecture and
    Mentoring Services

    </shameless self promotion>

    "Carlton858" <cnett858hotmail.com> wrote in message
    news:5e7cb398.0405171542.2cd7a299posting.google.c om...
    > I am using NUnitASP and I have run into problem "faking" user
    > credentials. In my ASP.Net/C# application, I have turned off
    > anonymous access to the web app and I allowing Windows groups to
    > handle the permissions to the app. Things are working perfectly, i.e.
    > only user groups that are allowed can log into the app and see what
    > they are supposed to, when the users enter their credentials through
    > IE.
    >
    > It is when I try to enter the credentials programmatically with
    > NUnitASP that I cannot set the credentials. In most cases, using
    > System.Net.CredentialCache.DefaultCredentials would be fine and this
    > works as expected. However, I want to test other roles besides my own
    > in the app and this is where I need to use the
    > System.Net.NetworkCredential class.
    >
    > For some reason I do not understand, I cannot pass a username,
    > password and domain to this class and have these values detected as
    > valid credentials. Has anyone used NUnitASP? If so, can you please
    > share some sample code showing how this works? If you have not used
    > NUnitASP, but are familiar with the System.Net.NetworkCredential
    > class, again I could use some coaching on how to use this class.
    > Thank you in advance for your help.
    >
    > Carlton

    Eric Marvets Guest

  3. #3

    Default Re: using System.Net.NetworkCredential class

    Here is some sample code.

    CredentialCache myCache = new CredentialCache();

    myCache.Add(new Uri("http://cnettleton.mydomain.com/"), "Basic",
    new NetworkCredential("mydomain\\so_user_test",
    "myPassword"));

    Browser.Credentials = myCache;
    Browser.GetPage("http://cnettleton/blog/web/AddArticle.aspx");


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Carlton Nettleton Guest

  4. #4

    Default Re: using System.Net.NetworkCredential class

    >
    > Can you post a sample of the NetworkCredential code you are using?
    >
    CredentialCache myCache = new CredentialCache();
    myCache.Add(new Uri("http://cnettleton.mydomain.com/"), "Basic",
    new NetworkCredential("mydomain\\so_user_test", "myPassword"));

    Browser.Credentials = myCache;
    Browser.GetPage("http://cnettleton/blog/web/AddArticle.aspx");

    Carlton
    Carlton858 Guest

  5. #5

    Default Re: using System.Net.NetworkCredential class

    Pass in the domain, user, and password in seperate fields. The constructor
    has an overloaded version to take the domain as a string seperate from the
    user as a string.

    --
    Eric Marvets
    Principal Consultant

    the bang project

    <shameless self promotion>

    Email [email]salesbangproject.com[/email] for Information on Our Architecture and
    Mentoring Services

    </shameless self promotion>

    "Carlton Nettleton" <cnett858hotmail.com> wrote in message
    news:uAyH5AbQEHA.556TK2MSFTNGP10.phx.gbl...
    > Here is some sample code.
    >
    > CredentialCache myCache = new CredentialCache();
    >
    > myCache.Add(new Uri("http://cnettleton.mydomain.com/"), "Basic",
    > new NetworkCredential("mydomain\\so_user_test",
    > "myPassword"));
    >
    > Browser.Credentials = myCache;
    > Browser.GetPage("http://cnettleton/blog/web/AddArticle.aspx");
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Eric Marvets Guest

  6. #6

    Default Re: using System.Net.NetworkCredential class

    You mean something like this:

    CredentialCache myCache = new CredentialCache();
    NetworkCredential myCredential = new NetworkCredential();
    myCredential.Domain = "myDomain";
    myCredential.UserName = "myDomain\\so_user_test";
    myCredential.Password = "myPassword";

    myCache.Add(new Uri("http://cnettleton.myDomain.com/"), "Basic",
    myCredential);

    Browser.Credentials = myCache;
    Browser.GetPage(DefaultPage);

    If so, that does not work. It returns an HTTP 401/"you are not
    authorized to view this page" error.



    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Carlton Nettleton Guest

  7. #7

    Default using System.Net.NetworkCredential class

    I have use domain and user separated by pipe character ("|"):

    Code:
    CredentialCache myCache = new CredentialCache();
    myCache.Add(new Uri("http://cnettleton.mydomain.com/"), "Basic",
    new NetworkCredential("mydomain|so_user_test", "myPassword"));
    It works for me.
    adgr2d2 is offline Junior Member
    Join Date
    Feb 2012
    Location
    United States
    Posts
    1

  8. #8

    Default Re: using System.Net.NetworkCredential class

    In most cases, using
    System.Net.CredentialCache.DefaultCredentials would be fine and this
    works as expected. However, I want to test other roles besides my own
    in the app and this is where I need to use the
    System.Net.NetworkCredential class.
    kolleen.koby is offline Banned
    Join Date
    Mar 2012
    Location
    NY
    Posts
    10

Similar Threads

  1. HierarchicalDataSourceControl Class and System.StackOverflowExcept
    By Francis Reed in forum ASP.NET Building Controls
    Replies: 5
    Last Post: July 18th, 10:22 PM
  2. Extract NetworkCredential from WindowsIdentity
    By Web Developer in forum ASP.NET Security
    Replies: 1
    Last Post: December 15th, 05:51 PM
  3. Replies: 0
    Last Post: November 10th, 09:33 PM
  4. Class 'System.Web.UI.WebControls.DataGridItem' cannot be indexed
    By MS in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: May 23rd, 02:19 AM
  5. Two Web Services using same NetworkCredential?
    By wgo in forum ASP.NET Security
    Replies: 0
    Last Post: October 14th, 01:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139