Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Forms Authentication Problem


Message #1 by "Hugh McLaughlin" <hugh@k...> on Sat, 22 Mar 2003 04:34:22
Hello Everyone and thanks for your help in advance.  I am having a 
problem setting up forms authentication for a site I am developing.  The 
main problem comes from the way I am developing the site.  Rather than 
having multiple pages, I have opted for one "Default.aspx" page and the, 
loading controls on the page based on the querystring parameters passed 
to it.  For example, Default.aspx?CP=Welcome loads a control welcome.ascx 
onto the Default.aspx page.  This works fine until I try to modify it to 
forms authentication.  I have set the LoginURL in the web.config file to 
Default.aspx.  The Default.aspx file checks to see if the CP parameter 
has been passed.  If it is blank, the Login.ascx control is loaded, 
otherwise the Login.ascx is loaded.  The problem I am running into is 
that, if I type the Default.aspx?CP=Welcome into the address bar, it goes 
directly to that URL and loads the Welcome.ascx control, whether it is 
authenticated or not.  Since the LoginURL is set to Default.aspx, I 
thought this would handle the problem since it would redirect to the 
default page without the querystring parameters, thus loading the login 
control.  I am stuck as to how to get this working properly.  Any help 
would be greatly appreciated.  Thanks.
Message #2 by "gustavo_portillo@c... on Mon, 24 Mar 2003 10:02:02 -0400
	  		
 have a nice day hugh

 I think that you can solvet your problem with one option of this two.
 
 First: you can create a ssession variable whe the first page of your
proyect have been loaded, for example session("rigth_access")=1 and will
ask in any page if session("right_access") == 1.

 If that true, you run all code in that page, but it is not, you will
redirect to an error page and that page, redirects to the validation page
(1st. page).

  It is very simple.

 Second: you can validate the user in the web.config page of your proyect,
you will insert the followig code in there:

  <authentication mode="Forms">         
 <forms name=".ASPXFORMSAUTH" loginUrl="valida.aspx" />      
</authentication>       <authorization> <deny users="?"/>    
</authorization>
  
  this code send an invalid user to the validation page (vaida.aspx), but 
you will put in valida.aspx this code

 System.Web.Security.FormsAuthentication.RedirectFromLoginPage(
Session("rigth_acces"), True).

  For more info you can go to:
       http://www.microsoft.com/spanish/msdn/comunidad/uni.net/cursovsnet4/
  that match go to the spanish version.

	  		
----------- Mensaje Original --------------
								
De: Hugh McLaughlin [hugh@k...]
Para: ASP.NET [aspx@p...]
Cc: 
Asunto: [aspx] Forms Authentication Problem
Fecha: 22/03/2003 00:20:22
Mensaje:

	  		
	  			Hello Everyone and thanks for your help in advance.  I am having a 
problem setting up forms authentication for a site I am developing.  The 
main problem comes from the way I am developing the site.  Rather than 
having multiple pages, I have opted for one "Default.aspx" page and the, 
loading controls on the page based on the querystring parameters passed 
to it.  For example, Default.aspx?CP=Welcome loads a control welcome.ascx 
onto the Default.aspx page.  This works fine until I try to modify it to 
forms authentication.  I have set the LoginURL in the web.config file to 
Default.aspx.  The Default.aspx file checks to see if the CP parameter 
has been passed.  If it is blank, the Login.ascx control is loaded, 
otherwise the Login.ascx is loaded.  The problem I am running into is 
that, if I type the Default.aspx?CP=Welcome into the address bar, it goes 
directly to that URL and loads the Welcome.ascx control, whether it is 
authenticated or not.  Since the LoginURL is set to Default.aspx, I 
thought this would handle the problem since it would redirect to the 
default page without the querystring parameters, thus loading the login 
control.  I am stuck as to how to get this working properly.  Any help 
would be greatly appreciated.  Thanks.


Message #3 by "Hugh McLaughlin" <hugh@k...> on Mon, 24 Mar 2003 16:31:45
Thanks Gustavo.  I tried the second option, but it does not redirect 
properly to the login in page.
> 	  		
 have a nice day hugh

 I think that you can solvet your problem with one option of this two.
 
 First: you can create a ssession variable whe the first page of your
proyect have been loaded, for example session("rigth_access")=1 and will
ask in any page if session("right_access") == 1.

 If that true, you run all code in that page, but it is not, you will
redirect to an error page and that page, redirects to the validation page
(1st. page).

  It is very simple.

 Second: you can validate the user in the web.config page of your proyect,
you will insert the followig code in there:

  <authentication mode="Forms">         
 <forms name=".ASPXFORMSAUTH" loginUrl="valida.aspx" />      
</authentication>       <authorization> <deny users="?"/>    
</authorization>
  
  this code send an invalid user to the validation page (vaida.aspx), but 
you will put in valida.aspx this code

 System.Web.Security.FormsAuthentication.RedirectFromLoginPage(
Session("rigth_acces"), True).

  For more info you can go to:
       
http://www.microsoft.com/spanish/msdn/comunidad/uni.net/cursovsnet4/
  that match go to the spanish version.

	  		
----------- Mensaje Original --------------
								
De: Hugh McLaughlin [hugh@k...]
Para: ASP.NET [aspx@p...]
Cc: 
Asunto: [aspx] Forms Authentication Problem
Fecha: 22/03/2003 00:20:22
Mensaje:

	  		
	  			Hello Everyone and thanks for your help 
in advance.  I am having a 
problem setting up forms authentication for a site I am developing.  The 
main problem comes from the way I am developing the site.  Rather than 
having multiple pages, I have opted for one "Default.aspx" page and the, 
loading controls on the page based on the querystring parameters passed 
to it.  For example, Default.aspx?CP=Welcome loads a control welcome.ascx 
onto the Default.aspx page.  This works fine until I try to modify it to 
forms authentication.  I have set the LoginURL in the web.config file to 
Default.aspx.  The Default.aspx file checks to see if the CP parameter 
has been passed.  If it is blank, the Login.ascx control is loaded, 
otherwise the Login.ascx is loaded.  The problem I am running into is 
that, if I type the Default.aspx?CP=Welcome into the address bar, it goes 
directly to that URL and loads the Welcome.ascx control, whether it is 
authenticated or not.  Since the LoginURL is set to Default.aspx, I 
thought this would handle the problem since it would redirect to the 
default page without the querystring parameters, thus loading the login 
control.  I am stuck as to how to get this working properly.  Any help 
would be greatly appreciated.  Thanks.



  Return to Index