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 188233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:58:13+00:00 2026-05-11T15:58:13+00:00

Is there a way to dynamically change the LoginUrl of FormsAuthentication? What I have

  • 0

Is there a way to dynamically change the LoginUrl of FormsAuthentication? What I have is the whole site protected by FormsAuth, but for some pages in a sub folder, I’d like to take the user to different login page, and have FormsAuth handle the ReturnUrl stuff. Is that possible or do I have to write my own redirect code for the sub folder cases?

Here’s an example layout:

   ~/LogOn1.aspx    ~/Protected1.aspx    ~/Protected2.aspx    ~/Subfolder/    ~/Subfolder/LogOn2.aspx    ~/Subfolder/NotProtected.aspx    ~/Subfolder/Protected3.aspx 

So my web.config looks like:

 <forms loginUrl='~/Splash.aspx' ... /> 

All of the Protected*.aspx pages have

 <deny users='?'> 

What I’d like though, is for ~/Subfolder/Protected3.aspx to be redirected to ~/Subfolder/LogOn2.aspx if the user is anonymous.

I did try putting a stripped down version of web.config at ~/Subfolder/web.config:

<?xml version='1.0'?> <configuration>    <system.web>       <authentication mode='Forms'>          <forms loginUrl='~/Subfolder/LogOn.aspx' name='SiteAuth' protection='All' timeout='30' path='/' defaultUrl='~/Subfolder/default.aspx' requireSSL='true' cookieless='UseCookies' enableCrossAppRedirects='false' />       </authentication>       <authorization>          <deny users='?' />       </authorization>    </system.web> </configuration> 

But all that gets me is this error:

It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

I think making the Subfolder dir an application would cause even more problems at this point, but maybe I am wrong. If it was an application, wouldn’t that separate all code in ~/Subfolder from the rest of the parent app?

  • 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. 2026-05-11T15:58:14+00:00Added an answer on May 11, 2026 at 3:58 pm

    The problem you’re having is that the Forms element is only allowed at the application level – you can’t define it in a sub-web.config.

    Unfortunately you also can’t define it using a Location element, and the FormsAuthentication.LoginUrl property is read only.

    Hunting around a bit, it looks like your best bet would be to have some code on your login page that detects where the user has arrived from (i.e. by checking the value of the ‘ReturnUrl’ query string) and redirecting to your other login page if they are from the subdirectory. However I admit that this doesn’t scale well at all if you want custom login pages for multiple sub-directories. 🙁


    In repsonse to your edit – yes, making the sub-folder an application would ‘solve’ this error, but as you point out, you’d then have more problems, as you’d need to move all the relevant binaries, app_code, what have you into that sub-folder as well, so it’s not really a solution.

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

Sidebar

Related Questions

Is there a way to dynamically create a kind of sub-domain that goes between
Is there a way in CSS or JQuery where I can dynamically change the
Is there a way to dynamically change output in Java? For instance, in a
Is there a way to dynamically change a variable value inside a string? What
Is there a way to zoom in and out (dynamically change the font size,
I'm curious if there is a way to dynamically change the session ID from
Is there a way to dynamically change the size of a widget? Can an
Are there any possibilities to dynamically change the static content? I have data in
Is there a way to dynamically determine whether the currently executing task is a
Is there any way to dynamically generate an swf file? Or insert variables after

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.