Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. null string returned for domain and username (Windows auth)

null string returned for domain and username (Windows auth)

Scheduled Pinned Locked Moved ASP.NET
csharpsysadminwindows-adminsecurity
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anarayan
    wrote on last edited by
    #1

    I'm trying to capture the username (and domain) of the user accessing the web application (web server on the same domain for starters). I have modifed the IIS settings to use Windows authentication and added stuff to web.config and use the following code below to capture this information - and it works as long as the web server is the localhost i.e it works only if the web app is accessed via a browser on the web server. Otherwise it returns a null string, what do I need to do? (currently buidling on .NET 2.0) Snippet of code in VB.NET (objGenericIdentity.Name contains null string when web app is accessed outside of web server): Dim formsAuthTicket As FormsAuthenticationTicket Dim httpCook As HttpCookie Dim objGenericIdentity As GenericIdentity Dim objMyAppPrincipal As securityPrincipal Dim strRoles As String() httpCook = Context.Request.Cookies.Get("authCookie") formsAuthTicket = FormsAuthentication.Decrypt(httpCook.Value) objGenericIdentity = New GenericIdentity(formsAuthTicket.Name) strRoles = formsAuthTicket.UserData.Split("|") objMyAppPrincipal = New securityPrincipal(objGenericIdentity, strRoles) HttpContext.Current.User = objMyAppPrincipal web.config contains this: authentication mode="Windows" identity impersonate="true" (I'm not using anything related to formsauthentication in the web.config file, do I need to?). And finally, what would I need to do to get this info when web app is accessed from a different domain? arvind

    P 1 Reply Last reply
    0
    • A anarayan

      I'm trying to capture the username (and domain) of the user accessing the web application (web server on the same domain for starters). I have modifed the IIS settings to use Windows authentication and added stuff to web.config and use the following code below to capture this information - and it works as long as the web server is the localhost i.e it works only if the web app is accessed via a browser on the web server. Otherwise it returns a null string, what do I need to do? (currently buidling on .NET 2.0) Snippet of code in VB.NET (objGenericIdentity.Name contains null string when web app is accessed outside of web server): Dim formsAuthTicket As FormsAuthenticationTicket Dim httpCook As HttpCookie Dim objGenericIdentity As GenericIdentity Dim objMyAppPrincipal As securityPrincipal Dim strRoles As String() httpCook = Context.Request.Cookies.Get("authCookie") formsAuthTicket = FormsAuthentication.Decrypt(httpCook.Value) objGenericIdentity = New GenericIdentity(formsAuthTicket.Name) strRoles = formsAuthTicket.UserData.Split("|") objMyAppPrincipal = New securityPrincipal(objGenericIdentity, strRoles) HttpContext.Current.User = objMyAppPrincipal web.config contains this: authentication mode="Windows" identity impersonate="true" (I'm not using anything related to formsauthentication in the web.config file, do I need to?). And finally, what would I need to do to get this info when web app is accessed from a different domain? arvind

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      I don't know what are you doing with FormsauthenticationTicket with Windows authentication. Have you looked ms article: http://msdn.microsoft.com/en-us/library/ff647405.aspx[^]

      Parwej Ahamad ahamad.parwej@gmail.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups