Howto know if we are in Forms or Windows authentication mode ?

W

WT

Hello,

I tryed to fix a variable with the current authentication mode,
I tryed to use Request.LogonUserIdentity AuthenticationType for this but
when I traced with this code
if (Request.LogonUserIdentity != null)
{
sb.AppendFormat("Request.LogonUserIdentity AuthenticationType: {0}<br />",
Request.LogonUserIdentity.AuthenticationType);
.....

I get nothing in my stringbuilder ???
Is it normal ?

Should I read web.config ?

Thanks for help

CS
 
S

Steven Cheng[MSFT]

Hi WT,

As for the Requeste.IsAuthenticated or Request.AuthenticationType, they're
just the same like the
HttpContext.Current.User.Identity.AuthenticationType(IsAuthenticated ).
They actually represent the authentication type performed by the IIS web
server, such as "NTML" or "Negotiate" ..... rather than the authenticatio
setting of ASP.NET <authentication mode/>.

for your scenario, if you want to check the ASP.NET application's current
authentication mode, you can consider the following means:

1. Load the <authentication mode> setting from application's web.config
file. You can use the WebConfigurationManager class to load applicationo
configuration settings. Also, for performance consideration, you can load
this setting into a class static property at application's startup time(or
at the first time the property is requested) so as to avoid multiple
accessing to the web.config file.

2. You can check the Context.User.Identity's type, for windows
authentication, it is of "WindowsIdentity" type while for
FormsAuthentication, it could be a FormsIdentity or GenericIdentity type.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top