473,732 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forms authentication in a subfolder problem, please help

Hi,

I've created a little site for my sports club. In the root folder there are
pages that are viewable by every anonymous user but at a certain subfolder
my administration pages should be protected by forms authentication.

When I create forms authentication at root level it works but when I move my
code up to the subfolder I get this error:

Server Error in '/TestProjects/FormsAuthentica tionTestingArea ' Application.
----------------------------------------------------------------------------
----

Configuration Error
Description: An error occurred during the processing of a configuration file
required to service this request. Please review the specific error details
below and modify your configuration file appropriately.

Parser Error Message: It is an error to use a section registered as
allowDefinition ='MachineToAppl ication' beyond application level. This error
can be caused by a virtual directory not being configured as an application
in IIS.

Source Error:
Line 12: />
Line 13:
Line 14: <authenticati on mode="Forms">
Line 15: <forms loginUrl="login new.aspx"/>
Line 16: </authentication>
Source File:
c:\inetpub\wwwr oot\TestProject s\FormsAuthenti cationTestingAr ea\administrati o
npages\web.conf ig Line: 14
----------------------------------------------------------------------------
----
Version Information: Microsoft .NET Framework Version:1.1.432 2.573; ASP.NET
Version:1.1.432 2.573

This is the code that I use:

root level
----------

web.config

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>

<system.web>

<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to enable ASPX debugging. Otherwise,
setting this value to
false will improve runtime performance of this application.
Set compilation debug="true" to insert debugging symbols (.pdb
information)
into the compiled page. Because this creates a larger file that
executes
more slowly, you should set this value to true only when debugging
and to
false at all other times. For more information, refer to the
documentation about
debugging ASP.NET files.
-->
<compilation
defaultLanguage ="c#"
debug="true"
/>

<!-- CUSTOM ERROR MESSAGES
Set customErrors mode="On" or "RemoteOnly " to enable custom error
messages, "Off" to disable.
Add <error> tags for each of the errors you want to handle.

"On" Always display custom (friendly) messages.
"Off" Always display detailed ASP.NET error information.
"RemoteOnly " Display custom (friendly) messages only to users not
running
on the local Web server. This setting is recommended for security
purposes, so
that you do not display application detail information to remote
clients.
-->
<customErrors
mode="Off"
/>

<!-- AUTHENTICATION
This section sets the authentication policies of the application.
Possible modes are "Windows",
"Forms", "Passport" and "None"

"None" No authentication is performed.
"Windows" IIS performs authentication (Basic, Digest, or
Integrated Windows) according to
its settings for the application. Anonymous access must be
disabled in IIS.
"Forms" You provide a custom form (Web page) for users to enter
their credentials, and then
you authenticate them in your application. A user credential
token is stored in a cookie.
"Passport" Authentication is performed via a centralized
authentication service provided
by Microsoft that offers a single logon and core profile services
for member sites.
-->
<authenticati on mode="Forms">
<!-- <forms loginUrl="login .aspx"/> -->
</authentication>

<!-- AUTHORIZATION
This section sets the authorization policies of the application.
You can allow or deny access
to application resources by user or role. Wildcards: "*" mean
everyone, "?" means anonymous
(unauthenticate d) users.
-->

<authorizatio n>
<allow users="*"/>
<!-- <deny users="?"/>-->
<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>

<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page
within an application.
Set trace enabled="true" to enable application trace logging. If
pageOutput="tru e", the
trace information will be displayed at the bottom of each page.
Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your
web application
root.
-->
<trace
enabled="false"
requestLimit="1 0"
pageOutput="fal se"
traceMode="Sort ByTime"
localOnly="true "
/>

<!-- SESSION STATE SETTINGS
By default ASP.NET uses cookies to identify which requests belong
to a particular session.
If cookies are not available, a session can be tracked by adding a
session identifier to the URL.
To disable cookies, set sessionState cookieless="tru e".
-->
<sessionState
mode="InProc"
stateConnection String="tcpip=1 27.0.0.1:42424"
sqlConnectionSt ring="data
source=127.0.0. 1;Trusted_Conne ction=yes"
cookieless="fal se"
timeout="20"
/>

<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalizatio n
requestEncoding ="utf-8"
responseEncodin g="utf-8"
/>

</system.web>

</configuration>

For the pages here they just contain some user controls with text and
sometimes read out some xml documents.

------------------------------------------------------------------

administrationp ages subfolder:
-----------------------------------

web.config

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>

<system.web>
<compilation
defaultLanguage ="c#"
debug="true"
/>

<customErrors
mode="Off"
/>

<authenticati on mode="Forms">
<forms loginUrl="login new.aspx"/>
</authentication>

<authorizatio n>
<allow users="*" /> <!--Allow all users -->
<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
<deny users="?"/>
</authorization>

<trace
enabled="false"
requestLimit="1 0"
pageOutput="fal se"
traceMode="Sort ByTime"
localOnly="true "
/>

<sessionState
mode="InProc"
stateConnection String="tcpip=1 27.0.0.1:42424"
sqlConnectionSt ring="data
source=127.0.0. 1;Trusted_Conne ction=yes"
cookieless="fal se"
timeout="20"
/>

<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalizatio n
requestEncoding ="utf-8"
responseEncodin g="utf-8"
/>

</system.web>

</configuration>
newtestform.asp x

<%@ Page language="c#" Codebehind="new testform.aspx.c s"
AutoEventWireup ="false"
Inherits="Forms AuthenticationT estingArea.admi nistrationpages .newtestform" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>newtestf orm</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "FlowLayout ">
<form id="Form1" method="post" runat="server">
<P>
<asp:Label id="LabelMessag e" runat="server"> </asp:Label></P>
<P>
<asp:Button id="ButtonSigno ut" runat="server"
Text="Signout"> </asp:Button></P>
<P>&nbsp;</P>
</form>
</body>
</HTML>
and code behind:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace FormsAuthentica tionTestingArea .administration pages
{
/// <summary>
/// Summary description for newtestform.
/// </summary>
public class newtestform : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l LabelMessage;
protected System.Web.UI.W ebControls.Butt on ButtonSignout;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Display the username
LabelMessage.Te xt = "Hello " + Context.User.Id entity.Name;
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.ButtonSign out.Click += new
System.EventHan dler(this.Butto nSignout_Click) ;
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void ButtonSignout_C lick(object sender, System.EventArg s e)
{
// Signout and redirect to login.aspx
System.Web.Secu rity.FormsAuthe ntication.SignO ut();
Response.Redire ct(Request.UrlR eferrer.ToStrin g());
}
}
}
loginnew.aspx

<%@ Page language="c#" Codebehind="log innew.aspx.cs" AutoEventWireup ="false"
Inherits="Forms AuthenticationT estingArea.admi nistrationpages .loginnew" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>loginnew </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "FlowLayout ">
<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBoxUser Name"
runat="server"> </asp:TextBox></P>
<P>
<asp:TextBox id="TextBoxPass word" runat="server"
TextMode="Passw ord"></asp:TextBox></P>
<P>
<asp:CheckBox id="CheckBoxPer sistent" runat="server"
Text="Persisten t"></asp:CheckBox>&n bsp;
<asp:Button id="ButtonLogin " runat="server"
Text="Login"></asp:Button></P>
<P>
<asp:Label id="LabelMessag e" runat="server" Font-Bold="True"
ForeColor="Red" ></asp:Label></P>
</form>
</body>
</HTML>

and code behind:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace FormsAuthentica tionTestingArea .administration pages
{
/// <summary>
/// Summary description for loginnew.
/// </summary>
public class loginnew : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Text Box TextBoxUserName ;
protected System.Web.UI.W ebControls.Text Box TextBoxPassword ;
protected System.Web.UI.W ebControls.Chec kBox CheckBoxPersist ent;
protected System.Web.UI.W ebControls.Butt on ButtonLogin;
protected System.Web.UI.W ebControls.Labe l LabelMessage;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.ButtonLogi n.Click += new
System.EventHan dler(this.Butto nLogin_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void ButtonLogin_Cli ck(object sender, System.EventArg s e)
{
// Validate username and password text boxes
if (TextBoxUserNam e.Text == string.Empty || TextBoxPassword .Text
== string.Empty)
{
LabelMessage.Te xt = "Username and Password cannot be empty";
return;
}

// Authenticate the user
bool CookieValue = false;
if ((TextBoxUserNa me.Text == "Kris") && (TextBoxPasswor d.Text ==
"bla"))
{
if (CheckBoxPersis tent.Checked)
{
CookieValue = true;
}
else
{
CookieValue = false;
}
// If valid, redirect to protected resource

System.Web.Secu rity.FormsAuthe ntication.Redir ectFromLoginPag e(TextBoxUserNa m
e.Text,CookieVa lue);
}
else
{
// If invalid, display an error page
LabelMessage.Te xt = "Invalid credentials, please try again";
TextBoxUserName .Text = string.Empty;
TextBoxPassword .Text = string.Empty;
}
}
}
}
Nov 17 '05 #1
3 4868
"Kris van der Mast" <kr************ *@skynet.be> wrote in message
news:eu******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder
my administration pages should be protected by forms authentication.

When I create forms authentication at root level it works but when I move my code up to the subfolder I get this error:

Server Error in '/TestProjects/FormsAuthentica tionTestingArea ' Application. -------------------------------------------------------------------------- -- ----

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details
below and modify your configuration file appropriately.

Parser Error Message: It is an error to use a section registered as
allowDefinition ='MachineToAppl ication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Source Error:
Line 12: />
Line 13:
Line 14: <authenticati on mode="Forms">
Line 15: <forms loginUrl="login new.aspx"/>
Line 16: </authentication>
Source File:
c:\inetpub\wwwr oot\TestProject s\FormsAuthenti cationTestingAr ea\administrati o npages\web.conf ig Line: 14

This error usually means what it says. Is your subdirectory configured as an
application in IIS?
--
John
Nov 17 '05 #2

"John Saunders" <john.saunder s at surfcontrol.com > wrote in message
news:ef******** ******@TK2MSFTN GP11.phx.gbl...
"Kris van der Mast" <kr************ *@skynet.be> wrote in message
news:eu******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I've created a little site for my sports club. In the root folder there are
pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be protected by forms authentication.

When I create forms authentication at root level it works but when I move my
code up to the subfolder I get this error:

Server Error in '/TestProjects/FormsAuthentica tionTestingArea ' Application.

--------------------------------------------------------------------------
--
----

Configuration Error
Description: An error occurred during the processing of a configuration

file
required to service this request. Please review the specific error

details below and modify your configuration file appropriately.

Parser Error Message: It is an error to use a section registered as
allowDefinition ='MachineToAppl ication' beyond application level. This

error
can be caused by a virtual directory not being configured as an

application
in IIS.

Source Error:
Line 12: />
Line 13:
Line 14: <authenticati on mode="Forms">
Line 15: <forms loginUrl="login new.aspx"/>
Line 16: </authentication>
Source File:

c:\inetpub\wwwr oot\TestProject s\FormsAuthenti cationTestingAr ea\administrati o
npages\web.conf ig Line: 14

This error usually means what it says. Is your subdirectory configured as

an application in IIS?


This wasn't necessary. The application blew because I had left the
authentication in the web.config of the subfolder. Removing this part (and
some others like the one of sessionstate) solved the problem.

Grz, Kris.
Nov 17 '05 #3
"Kris van der Mast" <kr************ *@skynet.be> wrote in message
news:#q******** ******@tk2msftn gp13.phx.gbl...

"John Saunders" <john.saunder s at surfcontrol.com > wrote in message
news:ef******** ******@TK2MSFTN GP11.phx.gbl...
"Kris van der Mast" <kr************ *@skynet.be> wrote in message
news:eu******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I've created a little site for my sports club. In the root folder there
are
pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be protected by forms authentication.

When I create forms authentication at root level it works but when I move
my
code up to the subfolder I get this error:

Server Error in '/TestProjects/FormsAuthentica tionTestingArea ' Application.


--------------------------------------------------------------------------
--
----

Configuration Error
Description: An error occurred during the processing of a
configuration file
required to service this request. Please review the specific error

details below and modify your configuration file appropriately.

Parser Error Message: It is an error to use a section registered as
allowDefinition ='MachineToAppl ication' beyond application level. This

error
can be caused by a virtual directory not being configured as an

application
in IIS.

Source Error:
Line 12: />
Line 13:
Line 14: <authenticati on mode="Forms">
Line 15: <forms loginUrl="login new.aspx"/>
Line 16: </authentication>
Source File:

c:\inetpub\wwwr oot\TestProject s\FormsAuthenti cationTestingAr ea\administrati o npages\web.conf ig Line: 14

This error usually means what it says. Is your subdirectory configured

as an
application in IIS?


This wasn't necessary. The application blew because I had left the
authentication in the web.config of the subfolder.


That's what I was getting at. Your subfolder was not configured as an
application, but the web.config in the subfolder used something which could
only be used at machine or application level.
--
John
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4833
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms Authentication set up and it worked just fine. Then I realized that I needed to have some pages unsecure. I then created 2 directories. One named Secure and the other named Public. I placed my web.config file in my
10
3607
by: See Sharp | last post by:
Hello all, I have a set of admin pages which are put in a subfolder called admin inside my application folder. I want to limit access to these admin pages. How can I do this? In Linux, I can password protect the directory, so that whenever a page within the admin subfolder is accessed for the first time, an authentication window pops up asking for username-password. How can I implement the same
2
2513
by: Eric | last post by:
I am trying to build an app where the stuff in the root directory is open to all, but anything under the Restricted directory requires you to login and I want to use Forms to do it. I'm having trouble getting the web.config to work properly. First I tried to have a second web.config in the sub directory with authentication and authorization set to forms, but it blew up. Next, I tried to modify the root web.config in the following manner...
12
1618
by: Brett Robichaud | last post by:
Is anyone familiar with this error? I have this running just fine on my local machine but when I pushed it out to our development server I get this error. I have no idea what it is saying. Any clues? -Brett- Server Error in '/' Application. ---------------------------------------------------------------------------- ----
4
5643
by: 23s | last post by:
I had this problem in the past, after a server reformat it went away, and now after another server reformat it's back again - no clue what's doing it. Here's the flow: Website root is public, no SSL no forms auth. One of the subfolders in the public area is the root of a "protected" area; SSL is required from this subfolder on forward and a web.config in the subfolder specifies forms authentication. From the public area, I provide a...
0
919
by: Matt | last post by:
Ok, second issue of the day. I have a site I am trying to protect using forms based security My main section is public and is configured fo ranonymous access, i.e. in the web.config file <authentication mode="Forms"/> <authorization> <allow users="*"/> </authorization>
4
1725
by: WebBuilder451 | last post by:
I have an app that will direct to the login on any unauthorized access. It will redirect back to the calling page when authenticated. Now here is the problem. I'm allowing for user registration via a link on the lgin page, but my registrstion page is re-directing me back to login.aspx. I've enabled session state to in proc to prevent multi logins with the same user. Would this cause a problem? here is my web.config sections that i've...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.