Click here to Skip to main content
15,881,812 members
Articles / Web Development / ASP.NET
Tip/Trick

Windows Authentication on Intranet Website using AD and Windows Server 2012 (or Higher)

Rate me:
Please Sign up or sign in to vote.
4.83/5 (5 votes)
21 Oct 2014CPOL1 min read 18.7K   11   2
How to implement Windows authentication on an Intranet website using WS2012

Introduction

I have spent hours and hours getting my intranet website working using Windows authentication, but I just couldn't get it to work. All I got was the error message "You do not have permission to view this directory or page".

I had added an AD connectionstring to the web.config, added a membership provider section and tried all options including configuring an AD connectionUsername and Password, but it still didn't work.

Eventually, I found the solution and it's oh so simple!!

Background

Windows Server 2012 and higher, by default, are extremely secure. Everything you need on the server you have to install, activate or configure.

One thing you do not have to configure (if you are working on an Intranet site and everything is available within one domain) is your connection to the AD (Active Directory) server. So we don't need the membership provider section nor the AD connectionstring in the web.config!

But then, why is it that I was still unauthorized!

Well, it turns out all that's left to do is grant access to the installation path of your website to the "Authenticated Users" group and then you're good to go!

Using the Code

In your web.config, within the <system.web> tag, you need to add the following:

XML
<system.web>
    ...
    <authentication mode="Windows">
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    ...
</system.web>

On the server, find the installation path of you web application (e.g. C:\inetpub\wwwroot\YourApp).

Go to the properties of that folder --> security tab and add the local "Authenticated Users" group.

Finally, grant the "Authenticated Users" group right to Read & execute, List folder contents and Read.

For example:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Centric Netherlands
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
andremulder 197922-Oct-14 0:01
andremulder 197922-Oct-14 0:01 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun21-Oct-14 23:41
Humayun Kabir Mamun21-Oct-14 23:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.