Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6666931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:52:49+00:00 2026-05-26T02:52:49+00:00

The following posts show how to setup the web.config for a site using Mixed

  • 0

The following posts show how to setup the web.config for a site using Mixed Mode Authentication. IIS7 Mixed Mode Authentication and How to allow mixed-mode authentication in IIS 7.0.

I’ve got my site setup and working locally (on my developer machine). However, when I run it locally on the server I get 401.2 – Login failed due to server configuration error.

Anyone know how I’m supposed to configure the server, Default Web Site, and My Site?

Edit: Here are the settings in my web.config, including the loginUrl from the Forms authentication node.

    <location path="~/Account/WinLogin.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
        <allow users="*"/>
      </authorization>
    </system.web>
    <system.webServer>
      <security>
        <authentication>
          <anonymousAuthentication enabled="false"/>
          <windowsAuthentication enabled="true"/>
        </authentication>
      </security>
    </system.webServer>
  </location>
  <system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/WinLogin.aspx" timeout="60"/>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:52:49+00:00Added an answer on May 26, 2026 at 2:52 am

    Let’s start with server roles configuration (this is under server manager, roles, IIS)

    You’re gonna want to make sure that the windows auth and anonymous auth sections are enabled/installed, and also the forms auth (which presumably you already have). After those are installed/configured, you’ll need to define the following stuff:

    In your Web.Config you’re going to want to have the following sections defined:

    <configuration>
      <system.web>
      <authentication mode="Forms">
          <forms cookieless="UseDeviceProfile" defaultUrl="~/Default.aspx" enableCrossAppRedirects="true" loginUrl="~/WindowsLogin.aspx" name=".ASPXAUTH" path="/" protection="All" requireSSL="false" slidingExpiration="true" timeout="10080"/>
        </authentication>
        <authorization>
            <deny users="?"/>
        </authorization>
      </system.web>
      <location path="Login.aspx">
          <system.web>
              <authorization>
                  <allow users="?"/>
              </authorization>
          </system.web>
          <system.webServer>
              <security>
                  <authentication>
                      <anonymousAuthentication enabled="true"/>
                      <windowsAuthentication enabled="false"/>
                  </authentication>
              </security>
          </system.webServer>
      </location>
      <location path="WindowsLogin.aspx">
          <system.web>
              <authorization>
                  <deny users="?"/>
                  <allow users="*"/>
              </authorization>
          </system.web>
          <system.webServer>
              <security>
                  <authentication>
                      <anonymousAuthentication enabled="false"/>
                      <windowsAuthentication enabled="true"/>
                  </authentication>
              </security>
          </system.webServer>
      </location>
    </configuration>
    

    Then you’ll need two files:

    Login.aspx (this does forms auth)
    WindowsLogin.aspx (this does Windows auth)
    

    LOGIN does forms, right, so that’s just bog standard ASP.NET forms auth
    It’s WindowsLogin that does the magic (and here’s that file)

    using System;
    using System.Web;
    using System.Web.Security;
    using App_Code.Biz;
    
    public partial class WindowsLogin : System.Web.UI.Page {
        protected string UserIsInRoles = string.Empty;
        private static readonly BAL _mBAL = new BAL();
        protected void Page_Load(object sender, EventArgs e) {
            string redirectUrl = Request["returnurl"] ?? "~/default.aspx";
            string username = Request.ServerVariables["LOGON_USER"];
            try {
                if ( Roles.GetRolesForUser( username ).Length < 1 )
                    Roles.AddUserToRole( username, Global.defaultRole );
                int status;
                _mBAL.aspnet_Membership_CreateUser( username, out status );
            } catch ( Exception ex ) {
                ErrHandler.WriteXML( ex );
            }
    
            /* Test to see if the user is in any roles */
            if ( Roles.GetRolesForUser( username ).Length < 1 ) {
                UserIsInRoles = "<br />" + username + "You are not in any rules. This must be your first visit to our site!<br /> Adding you to the " + Global.defaultRole + " role now!";
    
            } else {
                UserIsInRoles = "You are in the following roles: ";
                string[] roles = Roles.GetRolesForUser( username );
                foreach ( string role in roles )
                    UserIsInRoles += role + ", ";
                UserIsInRoles = UserIsInRoles.Remove( UserIsInRoles.Length - 2 ) + "!";
    
                if ( Login( username, String.Join( ",", roles ) ) )
                    Response.Redirect( redirectUrl );
            }
    
            //we shouldn't get here, so if we do, redirect back to a page they can use.
            if ( Page.IsPostBack ) {
                if ( Response.StatusCode == 401 )
                    Response.Redirect( "~/Login.aspx" );
    
            }
        }
    
        private bool Login(string strUser, string strRole) {
            if ( strRole != null ) {
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                   1,                            // version
                   strUser,                      // user name
                   DateTime.Now,                 // create time
                   DateTime.Now.AddYears(1),     // expire time
                   false,                        // persistent
                   strRole );                     // user data
                string strEncryptedTicket = FormsAuthentication.Encrypt( ticket );
                HttpCookie cookie = new HttpCookie( FormsAuthentication.FormsCookieName, strEncryptedTicket );
                Context.Response.Cookies.Add( cookie );
                return true;
            }
            return false;
        }
    }
    

    After all this, you might get a config error for section locked at a parent level. Lock is either by default (overrideModeDefault="Deny") or set explicitly by a location tag … and if so, then the fastest way to fix that is to open C:\Windows\System32\inetsrv\config\applicationHost.config and edit the following block:

    <configSections>
      <sectionGroup name="system.webServer">
        <sectionGroup name="security">
          <sectionGroup name="authentication">
            <section name="anonymousAuthentication" overrideModeDefault="Allow">
            <section name="windowsAuthentication" overrideModeDefault="Allow">
          </sectionGroup>
        </sectionGroup>
      </sectionGroup>
    </configSections>
    

    Also see the chat log: https://chat.stackoverflow.com/rooms/5/conversation/configuring-iis7-and-mixed-mode-authentication-in-asp-net

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a .xml file using the following code into the App_Data/posts.
Ive got the following code. $params = array('defType' => 'dismax', 'qf' => 'threads.title posts.body
I have the following route in my Rails3 project: match /blog/:permalink => posts#show, :as
Given the following resource definition: map.resources :posts, :except => [:show] map.post '/:year/:month/:slug, :controller =>
I have the following code in views/posts/show.html.erb : <span><%= @post.time_ago_in_words(Time.now) %></span><br /> And I
I have the following code in views/posts/show.html.erb : <span><%= @post.time_ago_in_words(Time.now) %></span><br /> And I
The following view shows a single post and its comments: views/posts/show.html.erb: <h2>posts show</h2> <span>Title:
I'm trying to implement routing such as the following: posts/535434/This-is-a-post-title posts/tagged/tags+here // Matches {controller}/{action}/{id}
I have the following tables: posts (post_id, content, etc) comments (comment_id, post_id, content, etc)
I'm following the tutorial here http://applicake.com/posts/54-integrating-facebook-connect-with-rails-applications to set up facebook connect. It almost worked,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.