null string returned for domain and username (Windows auth)
-
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
-
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
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