Configuring FormsAuthentication from code

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Configuring FormsAuthentication from code

    I have an asp.net application that has more then one login page. Different logon pages are used depending on how the customers have configured the application. We are making use of the FormsAuthentication module to do most of our authentication.

    I wish to be able to control the value of “loginUrl” from code, I know I can set in it the Web.Config file, however I do not what our customers to have to edit the setting in Web.Config whenever they change the configuration of our software.

    I could have a “fake” login.aspx page that redirects to the true one, however that will slow down logging onto the system.

    My ideal solution would be to configure FormsAuthentication from the Application_Start event in Global.aspx, any ideals on how to do this?

    I think this is a more general problem, as a ISV, I do not like settings that effects the correctness of my application being in a file that is so easy for the user to mess up! The logic of my application should be compiled into my application.

    Ian Ringrose
    Ringi at bigfoot dot com

    ringi Guest

  2. Similar Questions and Discussions

    1. FormsAuthentication
      Hi, i am using forms authentication in an ASP.NET project I am setting the Forms authentication cookie by using:...
    2. BUG With FormsAuthentication
      The authentication cookie with custom user is not available or the user data is gone after a redirect. In other words all the examples on the net on...
    3. FormsAuthentication with Machine Name
      I had licked this problem once and it resurfaced and won't go away. When I browse to a site with my machine name FormsAuthetication appears to...
    4. formsAuthentication without configuring in web.config
      Hi, I have a web site that uses normal windows authentication. I have a web service on the site that i want to configure Forms Authentication for,...
    5. FormsAuthentication - Changes in .Net Framework 1.1!?
      I am not sure what is causing this problem but I ran into it before. I did not spend time trying to solve it since we are still working in 1.0...
  3. #2

    Default RE: Configuring FormsAuthentication from code

    Hi Ian,

    You cannot do this. The loginUrl is set when the application domain is
    loaded. If you were to change that programmatically, you would need to
    reload the app domain for it to take effect, and that would cause everyone
    accessing the application to lose Session variables and their
    authentication. Even if you could do it, it would be a very bad practice.

    I'm not quite sure what you specific situation is, but it might be worth
    mentioning that the default loginUrl is default.aspx. Therefore, if you
    don't set a loginUrl, default.aspx will be the loginUrl. You may be able
    to simply change which page is named default.aspx based upon configuration
    of your application. Once again, I'm not certain what you are doing and
    what issues you are encountering, so I hope that helps.

    Jim Cheshire [MSFT]
    MCP+I, MCSE, MCSD, MCDBA
    Microsoft Developer Support
    [email]jamesche@online.microsoft.com[/email]

    This post is provided "AS-IS" with no warranties and confers no rights.

    --------------------
    >Thread-Topic: Configuring FormsAuthentication from code
    >thread-index: AcRovEAodb3ET9akQ4ivMEhYPUgAKA==
    >X-WBNR-Posting-Host: 212.44.26.106
    >From: "=?Utf-8?B?cmluZ2k=?=" <ringi@discussions.microsoft.com>
    >Subject: Configuring FormsAuthentication from code
    >Date: Tue, 13 Jul 2004 02:32:01 -0700
    >Lines: 13
    >Message-ID: <78353FFA-F2BB-43B8-8768-107B1A25FCB5@microsoft.com>
    >MIME-Version: 1.0
    >Content-Type: text/plain;
    > charset="Utf-8"
    >Content-Transfer-Encoding: 8bit
    >X-Newsreader: Microsoft CDO for Windows 2000
    >Content-Class: urn:content-classes:message
    >Importance: normal
    >Priority: normal
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    >Newsgroups: microsoft.public.dotnet.framework.aspnet.security
    >NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 127.0.0.1
    >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFT NGXA03.phx.gbl
    >Xref: cpmsftngxa06.phx.gbl
    microsoft.public.dotnet.framework.aspnet.security: 10759
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.security
    >
    >I have an asp.net application that has more then one login page.
    Different logon pages are used depending on how the customers have
    configured the application. We are making use of the FormsAuthentication
    module to do most of our authentication.
    >
    >I wish to be able to control the value of “loginUrl” from code, I
    know I can set in it the Web.Config file, however I do not what our
    customers to have to edit the setting in Web.Config whenever they change
    the configuration of our software.
    >
    >I could have a “fake” login.aspx page that redirects to the true one,
    however that will slow down logging onto the system.
    >
    >My ideal solution would be to configure FormsAuthentication from the
    Application_Start event in Global.aspx, any ideals on how to do this?
    >
    >I think this is a more general problem, as a ISV, I do not like settings
    that effects the correctness of my application being in a file that is so
    easy for the user to mess up! The logic of my application should be
    compiled into my application.
    >
    >Ian Ringrose
    >Ringi at bigfoot dot com
    >
    >
    Jim Cheshire [MSFT] Guest

  4. #3

    Default Re: Configuring FormsAuthentication from code

    Hi Jim,

    Thanks for your response,

    My specific situation is that we ship a web browser based application to our
    customers. Each customer installs iis on their own server. Depending how the
    customer is going to use the application they put it in a different "mode"
    at installation time. Different "modes" need different logon pages.

    When the customer sets the 'mode' that the application will run in, they
    should only have to change the configuration in ONE place, e.g. one line in
    the web.config file. However due to the fact that I can find no way to
    control FormsAuthentication form software, I have to tell then to ALSO
    change to set-up of FormsAuthentication in web.config.

    I can not just rename the logon pages, when the "mode" is change, as the
    installer for the application set up each logon page differently in iis.

    I do not like sealed boxes, that I can not control from my code!

    Ian Ringrose

    Ringi at bigfoot dot com

    "Jim Cheshire [MSFT]" <jamesche@online.microsoft.com> wrote in message
    news:tkthCnOaEHA.3316@cpmsftngxa06.phx.gbl...
    > Hi Ian,
    >
    > You cannot do this. The loginUrl is set when the application domain is
    > loaded. If you were to change that programmatically, you would need to
    > reload the app domain for it to take effect, and that would cause everyone
    > accessing the application to lose Session variables and their
    > authentication. Even if you could do it, it would be a very bad practice.
    >
    > I'm not quite sure what you specific situation is, but it might be worth
    > mentioning that the default loginUrl is default.aspx. Therefore, if you
    > don't set a loginUrl, default.aspx will be the loginUrl. You may be able
    > to simply change which page is named default.aspx based upon configuration
    > of your application. Once again, I'm not certain what you are doing and
    > what issues you are encountering, so I hope that helps.
    >
    > Jim Cheshire [MSFT]
    > MCP+I, MCSE, MCSD, MCDBA
    > Microsoft Developer Support
    > [email]jamesche@online.microsoft.com[/email]
    >
    > This post is provided "AS-IS" with no warranties and confers no rights.
    >

    Ian Ringrose Guest

  5. #4

    Default Re: Configuring FormsAuthentication from code


    I'm afraid you're stuck with it....You're going to have to change the way
    that you approach this. In the logon page you have programmatic control,
    but only after you've athenticated (however you do that).

    You're better off routing into one "mode" or another after you've logged in.
    It all depends on what exactly you're attempting to do. If you are trying
    to make sure a customer only has access to certain bits of your software,
    you may need to include an encrypted file or registry setting in your setup
    that include flags that set the "mode"...

    P

    "ringi" <ringi@discussions.microsoft.com> wrote in message
    news:F516F97A-1D98-4368-A6C2-BD695C7C71F5@microsoft.com...
    > Hi Jim,
    >
    > Thanks for your response,
    >
    > My specific situation is that we ship a web browser based application to
    our customers. Each customer installs iis on their own server. Depending
    how the customer is going to use the application they put it in a different
    "mode" at installation time. Different "modes" need different logon pages.
    >
    > When the customer sets the 'mode' that the application will run in, they
    should only have to change the configuration in ONE place, e.g. one line in
    the web.config file. However due to the fact that I can find no way to
    control FormsAuthentication form software, I have to tell then to ALSO
    change to set-up of FormsAuthentication in web.config.
    >
    > I can not just rename the logon pages, when the "mode" is change, as the
    installer for the application set up each logon page differently in iis.
    >
    > I do not like sealed boxes, that I can not control from my code!
    >
    > Ian Ringrose
    > Ringi at bigfoot dot com
    >
    >
    > "Jim Cheshire [MSFT]" wrote:
    >
    > > Hi Ian,
    > >
    > > You cannot do this. The loginUrl is set when the application domain is
    > > loaded. If you were to change that programmatically, you would need to
    > > reload the app domain for it to take effect, and that would cause
    everyone
    > > accessing the application to lose Session variables and their
    > > authentication. Even if you could do it, it would be a very bad
    practice.
    > >
    > > I'm not quite sure what you specific situation is, but it might be worth
    > > mentioning that the default loginUrl is default.aspx. Therefore, if you
    > > don't set a loginUrl, default.aspx will be the loginUrl. You may be
    able
    > > to simply change which page is named default.aspx based upon
    configuration
    > > of your application. Once again, I'm not certain what you are doing and
    > > what issues you are encountering, so I hope that helps.
    > >
    > > Jim Cheshire [MSFT]
    > > MCP+I, MCSE, MCSD, MCDBA
    > > Microsoft Developer Support
    > > [email]jamesche@online.microsoft.com[/email]
    > >
    > > This post is provided "AS-IS" with no warranties and confers no rights.

    Paul Mason Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139