Setting LoginUrl at runtime using FormsAuthenticationConfiguration

Last post 03-01-2009 12:05 PM by anas. 7 replies.

Sort Posts:

  • Setting LoginUrl at runtime using FormsAuthenticationConfiguration

    02-28-2009, 3:02 PM

    I am trying to use FormsAuthenticationConfiguration to set my LoginUrl at runtime in my app.  I am testing it as follows

    GLOBAL.ASAX 

    	Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
    
    		' Set the LoginUrl.
    		Dim instance As New FormsAuthenticationConfiguration
    		instance.LoginUrl = "MyNewLogin.aspx"
    
    	End Sub
     and then using  
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim currentLoginUrl As String = FormsAuthentication.LoginUrl
            Response.Write(currentLoginUrl)
        End Sub

     in my Default.aspx.vb page.

     

    The problem is that it is writing out "login.aspx" on the page...

    Does anyone know what I am doing wrong?

    Chase

    Visual Studio 2008
    ASP.NET 3.5 (Visual Basic)
    SQL Server Express

    Check out my blog
  • Re: Setting LoginUrl at runtime using FormsAuthenticationConfiguration

    03-01-2009, 12:38 AM

    oh how quickly one's post can get bumped to the bottom of the page.

    Chase

    Visual Studio 2008
    ASP.NET 3.5 (Visual Basic)
    SQL Server Express

    Check out my blog
  • Re: Setting LoginUrl at runtime using FormsAuthenticationConfiguration

    03-01-2009, 8:58 AM
    • All-Star
      60,710 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,848
    • Moderator

     So you need to change the Login page temporarly ?

    Actually your code doesn't work because you are just creating an instance from the FormsAuthenticationConfiguration class and it will not be linked to the actual configuration.

    Also you can't use the FormsAuthentication.LoginUrl  because it's read only.What are you trying to do ?

    Are you using a different login page for each role ?

     

    Regards,

    Anas Ghanem | Blog

  • Re: Setting LoginUrl at runtime using FormsAuthenticationConfiguration

    03-01-2009, 9:47 AM

    I am in the process of building a content management system.  There is already a Login.aspx page but it is branded with the CMS stuff.  The goal is to also build a login module that the client can use to override my login page with their own theme.

    Select [ID] from [Pages] where [Module] = 'Login'

    if it exists {change the login page}

    Chase

    Visual Studio 2008
    ASP.NET 3.5 (Visual Basic)
    SQL Server Express

    Check out my blog
  • Re: Setting LoginUrl at runtime using FormsAuthenticationConfiguration

    03-01-2009, 9:49 AM
    • All-Star
      60,710 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,848
    • Moderator

     Ok,

    What about keeping your login.aspx page , and in it's page_load method, you check that database table and decide if you need to redirect to the login page that you want.

     

    Regards,

    Anas Ghanem | Blog

  • Re: Setting LoginUrl at runtime using FormsAuthenticationConfiguration

    03-01-2009, 11:49 AM

    Yes, this is definately possible, though I would prefer not making extra trips... I just thought that the FormsAuthenticationConfiguration would work...

    Chase

    Visual Studio 2008
    ASP.NET 3.5 (Visual Basic)
    SQL Server Express

    Check out my blog
  • Re: Setting LoginUrl at runtime using FormsAuthenticationConfiguration

    03-01-2009, 11:55 AM

    also, i think a server.trasfer would work better than a redirect.

    Chase

    Visual Studio 2008
    ASP.NET 3.5 (Visual Basic)
    SQL Server Express

    Check out my blog
  • Re: Setting LoginUrl at runtime using FormsAuthenticationConfiguration

    03-01-2009, 12:05 PM
    Answer
    • All-Star
      60,710 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,848
    • Moderator

    rockinthesixstring:
    also, i think a server.trasfer would work better than a redirect.

    Sure, But it will keep the Login page title.But in your case yes it's better.

    You can also Handle the AuthenticateRequest event in global.asx file and check your client paged and redirect to whatever paeg you want.

     

    Regards,

    Anas Ghanem | Blog

Page 1 of 1 (8 items)