Question

2 Login pages for forms based authentication

Asked by: mrichmon

Is there a way to have two different login pages for forms based authentication?  (ASP.NET 2.0 C#)

I had custom built authentication that works, but would like to move to forms based authentication if possible.

The one catch I am having is that I need two different login pages.  There are two different kinds of credentials, one is standard combination of username/password, and the other is a combination of a different set of 3 fields.  There is no way to combine these two logins.

When you login using the username/password, you would get one role.  When you login using the other combination of fields you get another role.

So right now I manually test on each page if you are authenticated, and if not, depending on where you are trying to get to, depends on which login page you are sent to.  Ideally instead of testing on each page, I could use the allow roles in the web.config, but to do so I would need forms based authentication.

I don't think separate applications would work as there are pages that both roles share.

Any ideas?
Can this be done with forms based authentication or do I need to continue to use my custom method.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-01-01 at 14:09:14ID22107735
Tags

login

,

authentication

,

pages

Topic

Programming for ASP.NET

Participating Experts
2
Points
500
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Web.Config
    What is the effect of having both <allow users="*" /> and <deny users="?" /> in authentication tag of web.config? Is there a way to set a default redirect in web.config? I.e. "MyPage.aspx" instead of default.aspx . Thanks
  2. Assign user roles in web.config
    I'm using Forms Authentication, a very basic site, just a handful of users so I'm storing credentials in web.config. I need to make a few users "admins", that is, assign their username to a role. I can't seem to figure out how to do this in web.config, if there is...
  3. web.config
    I have a web.config in my main folder / How do i edit this web.config to perform <authentication mode="Forms> for subdirectory /private and authorization to deny users=? What do i add in main / web.config
  4. logging into ASP.net using web.config/users with differ…
    The Title of this question is not very good. Here is what i am trying to do: I want to password protect the entire site with a generic login; except for one page i want to protect with an admin login. I have read all over the internet trying to accomplish this, but i am ne...
  5. Membership, roles and mixed authentication in ASP.NET …
    Hello all - I'm either making this too complicated ... or it IS too complicated! I have a web app that has been used internally only, so I've been using Windows authentication. Now, it is going to be used externally as well -- and there are some added featur...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: DabasPosted on 2007-01-01 at 14:15:06ID: 18225096

Hi mrichmon,
What about creating a subfolder for one of the types of roles, and redirecting your user to the (different) login form there?
The subfolder can have its own web.config to override the applicable settings in its parent web.config.

This way you can still have both roles sharing the relevant pages that are needed by both.

Dabas

 

by: amit_gPosted on 2007-01-01 at 18:12:51ID: 18225741

It should be possible. In fact everything is already built in except the 2 different login pages. You could have any number of login pages and ASP.Net won't care about it as long as each page in itself sets the auth cookie and role. Obviously the user has to get to those 2 pages using 2 different URLs as ASP.Net won't have a way to know which one to use. For auto logout/redirect feature, you could have a cookie (your own independent of login) that us written after the login is done (from either page) indicating what page was used and when the user is logged out and goes to the site again, both login pages could read that cookie to determine which one should be used.

 

by: mrichmonPosted on 2007-01-01 at 22:33:59ID: 18226307

Dabas,

No that doesn't work.  You can't override forms authentication settings in subfolders without making them separate applications.  It is called a machine to application setting.  PS one set is in a separate subfolder - but the same role needs to access the ones in that folder, plus one page that is outside the folder.

amit_g,

Can you provide code for that?  As far as I can tell what you are describing is what I already have - a custom built solution - not a solution using the forms based authentication that comes with .NET

My custom method does use aspects/functions of forms based authentication, such as creating a forms identity.  It is very similar, but not the same as this article I found while trying to find the answer to if this can be done:
http://www.codeproject.com/aspnet/formsroleauth.asp

But that is really how to do roles in .NET 1.1, when I already have that.  I am looking for how to do this using the built in Forms Authentication and Roles Provider in .NET 2.0

Otherwise, if I can't find out that it can be done, then I would use the home built system I already have working.

 

by: amit_gPosted on 2007-01-01 at 23:36:44ID: 18226455

I was talking about .NET 2.0. Assuming you are using VS2005, this is wizard driven. The wizard takes care of single login page and would make everything work without much problem. This is called membership and roles in the 2.0. Once you get that working, you just have to add second login page and modify a little bit in that page. Everything would work without much coding except the part where you would want to show the correct login page to already logged in user. For that you will have to write a custom cookie in successful login and read that cookie in default login page to see if you need to redirect the user to the other one.

As you might have already guessed, the code is not as little or simple to be posted here but the process is not difficult. Here is an article (out of so many) that would guide you to create single page form based authenticated membership and roles in .Net 2.0. The article is pretty simple to follow. Create a new test site/application following that article and make it work for you with single login page. After that make a copy of the login page to second login page and in that make few changes (like setting different role). The wizard would take care of the first login page in the web.config but for the second login page you will have to add the entry manually. Find the entry for the default login page and copy that over for the second login page.

Keep posting the problems you face.

 

by: mrichmonPosted on 2007-01-02 at 08:48:09ID: 18228845

amit_g,

I am using VS2005, but do not use wizards as I prefer to write the code that will run on my sites.

You mention an article but show no link.

>>the first login page in the web.config but for the second login page you will have to add the entry manually
Have you even tried what you are suggesting??  I am not a newbie and have tried this and it does not allow a second login page defined in the web.config.

 

by: amit_gPosted on 2007-01-02 at 09:33:37ID: 18229244

Sorry about the missing link.

http://aspnet.4guysfromrolla.com/articles/120705-1.aspx

I am with you when you say, you want to write your own code. It is always better but to start, you could create a new application and see what code VS generates and then write/copy-paste from that.

The web.config doesn't allow second login page. There will only be one login page for the ASP.Net. What I meant by that is that you will have to allow all users to access the second page otherwise the .Net would redirect to the login page and the user would never be able to use the second login page. Something like this

  <location path="AlternateLogin.aspx">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>
  </location>

Yes, I have one application with 2 different login pages. There is one difference though. I don't assign different roles to the users from different login pages rather it is assigned based on membership.

 

by: mrichmonPosted on 2007-01-02 at 11:05:55ID: 18229941

I had previously read that whole series.  It really doesn't do what I am looking for.

By the way: As far as we can tell <allow users="?" /> doesn't trigger login.  Only <deny users="?" /> would trigger login.

>>There is one difference though. I don't assign different roles to the users from different login pages rather it is assigned based on membership.
Yes that is part of the key problem.  I can create a page that is not automatic, but users have a link - works only so/so because if you try to access a protected page you are only directed to the one login page defined in the web.config.  But I want you to be directed based on the path being accessed, to the correct login page.  Basically the effect of if you were allowed to add a section in a child web.config.  

However, roles assigned are based on the login page used.  I realize this is unique and that in general, you would lookup roles based on a person, but in this case the only people stored are the ones using the username/password combination.  Everyone else is not stored as a user.  Therefore, everyone else who properly authenticates needs a pre-defined "default" role (and each has a unique Id as the username, so I can't just create a default user and assign roles to that).

I realize it is a non-standard situation.  Basically I was able to get a plain forms authentication working, but could not then get the roles to work with it.

 

by: DabasPosted on 2007-01-02 at 11:17:33ID: 18230046

Just an idea that might help.

Can you have just the one login page, for both types of roles.
Have separate <div> or other container for each role.
In Page_Load, depending on the role of the user you can make one of the <div> visible, while making the other one hidden.

Dabas

 

by: mrichmonPosted on 2007-01-02 at 13:03:44ID: 18230936

Dabas,

I thought of that but couldn't figure out how it would work - and don't think it can.  How would I know which div to make visible?  You don't know what role a person will be in until they successfully authenticate.  - It could be NO roles if they are a random web surfer that hits the page and doesn't know any of the credentials of either kind.

 

by: DabasPosted on 2007-01-02 at 13:11:18ID: 18230992

mrichmon > "depending on where you are trying to get to, depends on which login page you are sent to."


Can't you put this type of reasoning to create a querystring that you pass to the Login.aspx?


 

by: mrichmonPosted on 2007-01-02 at 13:30:00ID: 18231151

No.  I can't add fields to the querystring of every page that might be accessed.  So unless you know of a way to have .NET dynamically redirect to different pages - or the same page with a different querystring, no matter which page is actually accessed....

 

by: amit_gPosted on 2007-01-02 at 13:42:14ID: 18231286

>>But I want you to be directed based on the path being accessed, to the correct login page.

This is not possible with built in mechanism or with simple add on to it - or at least I don't know of a way.

I was thinking that you have a need of 2 or more login pages only as 2 or more entry points and once the user is authenticated, you know with one to use (by a persistent cookie) even after the user logs off. Since the .Net would always send an unauthenticated users to the same login page, you could use that cookie to send to the other login page. This would work as long as user has logged in once, you can always show the correct login page.

Have you thought about using ReturnUrl parameter passed to the login page for this purpose?

 

by: mrichmonPosted on 2007-01-02 at 14:28:14ID: 18231720

>>you know with one to use (by a persistent cookie) even after the user logs off
Hard to explain, but based on other situations I have a persistent cookie will not work.

 

by: amit_gPosted on 2007-01-02 at 14:36:23ID: 18231797

I think I get your requirements now. Your needs are different than what I thought based on the question. You need to show different login page based on the different pages/directories within your site. I don't think this is possible using standard feature of ASP.Net.

You could probably use ReturnUrl parameter passed to the login page. This parameter has the page that caused the login page to be invoked. You could use this to redirect to second login page instead of the default login page. You will have to list all possible pages that need to use the second login page but that should work for you.

 

by: mrichmonPosted on 2007-01-02 at 14:52:16ID: 18231953

I think you are correct that the standard features won't work.

I think after spending so much time on this (more before I posted) that I am going to just stick with my custom code for now and not migrate this project to forms based authentication with roles for .NET 2.0

Thanks.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...