home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / doc / windowsauth.aspx < prev    next >
Encoding:
Text File  |  2000-06-06  |  2.1 KB  |  48 lines

  1. <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%>
  2.  
  3. <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
  4.  
  5. <h4>Windows-based Authentication</h4>
  6. When the ASP+ Windows authentication mode is used, ASP+ attaches a <b>WindowsPrincipal</b> object to the current request.  This object is used by URL authorization when doing authorization and can be used programatically by the application to determine if a requesting identity is in a given role.
  7.  
  8. <div class="code"><xmp>
  9. if( User.IsInRole("Administrators") )
  10. {
  11.     DisplayPrivilegedContent();
  12. }
  13. </xmp></div>
  14.  
  15. With the WindowPrincipal class, roles are determined by NT group membership.  Applications that wish to determine their own roles can do so by handling the <b>WindowsAuthentication_OnAuthenticate</b> event in their global.asax file and attaching their own class that implements <b>System.Security.Principal.IPrincipal</b> to the request, as shown in the following example.
  16. <div class="code"><xmp>
  17. // create a class that implements IPrincipal
  18. public class MyPrincipal : IPrincipal
  19. {
  20.     // implement application-defined role mappings
  21. }
  22.  
  23. // in a global.asax file
  24. public void WindowsAuthentication_OnAuthenticate(Object Source, WindowsAuthenticationEvent e)      
  25. {
  26.     // attach a new application defined class that implements IPrincipal to
  27.     // the request
  28.     // Note that since IIS has already performed authentication, we use the provided
  29.     // identity
  30.     e.User = new MyPrincipal(e.Identity);
  31. }
  32. </xmp></div>
  33.  
  34.  
  35. <p>
  36. The following sample shows how to access the name of authenticated used, which is available in as <b>User.Identity.Name</b>.  Programmers familiar with ASP should note that this value is also still available as the AUTH_USER server variable.
  37. <p>
  38.  
  39. <Acme:SourceRef 
  40.   RunSample="/quickstart/aspplus/samples/security/WindowsAuth/windowsauth.aspx" 
  41.   ViewSource="/quickstart/aspplus/samples/security/windowsauth.src"
  42.   Icon="/quickstart/aspplus/images/windowsauth.gif"
  43.   Caption="Windows Authentication"
  44.   runat="server" />
  45.  
  46. <p>
  47.  
  48. <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->