473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

asp.net problem


Hi

I have an asp.net 2.0 project and am experiencing a problem.

In the project, I am trying to make use of Membership.

I have one Role, called "Basic User" and two users - "admin" and "test".

"admin" is a member of the Role but "test" is not.

I have only a few pages in the project at the moment: -

.. SecurePage.aspx - The page I want only authenticated users that are
members of the Role to use.

.. Login.aspx - Login page

.. Unauthorized.aspx - Informs user that they cannot view the secure page
because of a lack of permissions

SecurePage.aspx just contains a ChangePassword control.

Unauthorized.aspx has some text and a LoginStatus control.

So in the SecurePage.aspx, I have this code to handle this: -

Protected Sub form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

If User.Identity.IsAuthenticated = False Then
Server.Transfer("login.aspx")
End If

If Roles.IsUserInRole("Basic User") = False Then
Server.Transfer("unauthorized.aspx")
End If

End Sub

If I go to the SecurePage and am not authenticated, it transfers me to
login.aspx.

If I then login with the user "admin", which is in the Role "Basic User", it
works ok.

If I first login with "test", which is NOT in the Role, then I am transfered
to the "unauthorized.aspx" page.

Upto this point, this is fine.

However, if I click "Logout" on the LoginStatus control on the
"unauthorized" page it refreshes and changes to display "Login".

So, if I then click "Login", I am taken back to the login page. The URL in
the address bar at this point is: -

http://localhost:1489/Lesson09/login...uthorized.aspx

If I then login with using "admin" - which is a member of the Role - this is
where I get a problem.

Instead of being taken to the SecurePage.aspx as expected, I get taken back
to the "unauthorized.aspx" page.

This is obviously wrong.

Now, I know that this should work but does anybody know why it is not
working?

Is there some settings or something I need to change on my PC? Am I missing
a step or not doing something?

I've checked the obvious things - like that the user was actually in the
Role etc.

However, I just cannot get this to work.

I am new to ASP.Net and so I don't really know where to start to look for
what the problem is?

I have gone through re-doing the project twice now and I still get the same
problem.

For info, I am using: -

- Visual Studio .Net 2005 (Professional) (up to date)
- Latest .Net installed
- Windows XP Pro
- Internet Explorer 6 (version 6.0.2900.2180.xpsp_sp2_gdr.050301-1519) SP2

This project is actually from a training video from learnvisualstudio.net
(available also via www.asp.net). It is Lesson 09 on ASP basics. On the
video, this project works fine, but it does not on my PC.

I would very much appreciate any help or advice on this problem.

Thanks in advance.

Kind regards
Darren Brook
email: da*********@btconnect.com


Nov 2 '06 #1
2 2463
You'll have to do a bit of testing then to determine if the ReturnUrl
parameter is to a spot you want. In the login code, usually what I do is
check to ensure that 1) there is a returnUrl parameter so if not I can
redirect them to a better default spot. 2) if it does exist it doesn't
equal a page that is innappropriate for them to be redirected to (which is
your case). It sounds as if the Logout page is being protected by the login
system. This probably isn't the best way to do it since it causes exactly
this sort of problem. If you have only particular directories secured by
authentication, that can make it a lot easier to show files such as the
logout.aspx without having this login problem (and lets you show the message
that they have successfully logged out). You actually shouldn't have to
bother with any code in the securepage.aspx identifying whether the user is
logged in or not. Create a directory to place your secure pages. Then,
create a web.config for that directory and put the following:

<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</configuration>

This will tell the application that only authenticated users are allowed in
this directory. The deny ? users means anonymous and the allow * users means
authenticated. You could also deny/allow certain roles as well here.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"MS News Public" <br*****@btinternet.comwrote in message
news:Ob**************@TK2MSFTNGP02.phx.gbl...
>
Hi

I have an asp.net 2.0 project and am experiencing a problem.

In the project, I am trying to make use of Membership.

I have one Role, called "Basic User" and two users - "admin" and "test".

"admin" is a member of the Role but "test" is not.

I have only a few pages in the project at the moment: -

. SecurePage.aspx - The page I want only authenticated users that are
members of the Role to use.

. Login.aspx - Login page

. Unauthorized.aspx - Informs user that they cannot view the secure page
because of a lack of permissions

SecurePage.aspx just contains a ChangePassword control.

Unauthorized.aspx has some text and a LoginStatus control.

So in the SecurePage.aspx, I have this code to handle this: -

Protected Sub form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

If User.Identity.IsAuthenticated = False Then
Server.Transfer("login.aspx")
End If

If Roles.IsUserInRole("Basic User") = False Then
Server.Transfer("unauthorized.aspx")
End If

End Sub

If I go to the SecurePage and am not authenticated, it transfers me to
login.aspx.

If I then login with the user "admin", which is in the Role "Basic User",
it works ok.

If I first login with "test", which is NOT in the Role, then I am
transfered to the "unauthorized.aspx" page.

Upto this point, this is fine.

However, if I click "Logout" on the LoginStatus control on the
"unauthorized" page it refreshes and changes to display "Login".

So, if I then click "Login", I am taken back to the login page. The URL
in the address bar at this point is: -

http://localhost:1489/Lesson09/login...uthorized.aspx

If I then login with using "admin" - which is a member of the Role - this
is where I get a problem.

Instead of being taken to the SecurePage.aspx as expected, I get taken
back to the "unauthorized.aspx" page.

This is obviously wrong.

Now, I know that this should work but does anybody know why it is not
working?

Is there some settings or something I need to change on my PC? Am I
missing a step or not doing something?

I've checked the obvious things - like that the user was actually in the
Role etc.

However, I just cannot get this to work.

I am new to ASP.Net and so I don't really know where to start to look for
what the problem is?

I have gone through re-doing the project twice now and I still get the
same problem.

For info, I am using: -

- Visual Studio .Net 2005 (Professional) (up to date)
- Latest .Net installed
- Windows XP Pro
- Internet Explorer 6 (version 6.0.2900.2180.xpsp_sp2_gdr.050301-1519) SP2

This project is actually from a training video from learnvisualstudio.net
(available also via www.asp.net). It is Lesson 09 on ASP basics. On the
video, this project works fine, but it does not on my PC.

I would very much appreciate any help or advice on this problem.

Thanks in advance.

Kind regards
Darren Brook
email: da*********@btconnect.com


Nov 2 '06 #2
Thanks for the reply.

Do you know why the project (which you can download from www.asp.net) works
okay in the training video but not on my PC?

I am totally new to asp.net -the "ReturnUrl" in the address bar appears
after I click the LoginStatus control on the unauthorized page, when
LoginStatus displays "Login". When I click on it, it takes me back to the
login page and that's when the "ReturnUrl" appears in the address bar. I've
not set it in any properties or coded it etc.

But the "DestinationUrl" for a successful login on the actual login control
is set to the secure page. I do not understand what is happening, why the
project works in the video but not on my PC, nor how it is "supposed" to
work (which is why I am trying to go through these videos!). It is very
frustrating!

Thanks
Darren
"Mark Fitzpatrick" <ma******@fitzme.comwrote in message
news:OV**************@TK2MSFTNGP02.phx.gbl...
You'll have to do a bit of testing then to determine if the ReturnUrl
parameter is to a spot you want. In the login code, usually what I do is
check to ensure that 1) there is a returnUrl parameter so if not I can
redirect them to a better default spot. 2) if it does exist it doesn't
equal a page that is innappropriate for them to be redirected to (which is
your case). It sounds as if the Logout page is being protected by the
login system. This probably isn't the best way to do it since it causes
exactly this sort of problem. If you have only particular directories
secured by authentication, that can make it a lot easier to show files
such as the logout.aspx without having this login problem (and lets you
show the message that they have successfully logged out). You actually
shouldn't have to bother with any code in the securepage.aspx identifying
whether the user is logged in or not. Create a directory to place your
secure pages. Then, create a web.config for that directory and put the
following:

<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</configuration>

This will tell the application that only authenticated users are allowed
in this directory. The deny ? users means anonymous and the allow * users
means authenticated. You could also deny/allow certain roles as well here.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"MS News Public" <br*****@btinternet.comwrote in message
news:Ob**************@TK2MSFTNGP02.phx.gbl...
>>
Hi

I have an asp.net 2.0 project and am experiencing a problem.

In the project, I am trying to make use of Membership.

I have one Role, called "Basic User" and two users - "admin" and "test".

"admin" is a member of the Role but "test" is not.

I have only a few pages in the project at the moment: -

. SecurePage.aspx - The page I want only authenticated users that are
members of the Role to use.

. Login.aspx - Login page

. Unauthorized.aspx - Informs user that they cannot view the secure page
because of a lack of permissions

SecurePage.aspx just contains a ChangePassword control.

Unauthorized.aspx has some text and a LoginStatus control.

So in the SecurePage.aspx, I have this code to handle this: -

Protected Sub form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs)

If User.Identity.IsAuthenticated = False Then
Server.Transfer("login.aspx")
End If

If Roles.IsUserInRole("Basic User") = False Then
Server.Transfer("unauthorized.aspx")
End If

End Sub

If I go to the SecurePage and am not authenticated, it transfers me to
login.aspx.

If I then login with the user "admin", which is in the Role "Basic User",
it works ok.

If I first login with "test", which is NOT in the Role, then I am
transfered to the "unauthorized.aspx" page.

Upto this point, this is fine.

However, if I click "Logout" on the LoginStatus control on the
"unauthorized" page it refreshes and changes to display "Login".

So, if I then click "Login", I am taken back to the login page. The URL
in the address bar at this point is: -

http://localhost:1489/Lesson09/login...uthorized.aspx

If I then login with using "admin" - which is a member of the Role - this
is where I get a problem.

Instead of being taken to the SecurePage.aspx as expected, I get taken
back to the "unauthorized.aspx" page.

This is obviously wrong.

Now, I know that this should work but does anybody know why it is not
working?

Is there some settings or something I need to change on my PC? Am I
missing a step or not doing something?

I've checked the obvious things - like that the user was actually in the
Role etc.

However, I just cannot get this to work.

I am new to ASP.Net and so I don't really know where to start to look for
what the problem is?

I have gone through re-doing the project twice now and I still get the
same problem.

For info, I am using: -

- Visual Studio .Net 2005 (Professional) (up to date)
- Latest .Net installed
- Windows XP Pro
- Internet Explorer 6 (version 6.0.2900.2180.xpsp_sp2_gdr.050301-1519)
SP2

This project is actually from a training video from learnvisualstudio.net
(available also via www.asp.net). It is Lesson 09 on ASP basics. On the
video, this project works fine, but it does not on my PC.

I would very much appreciate any help or advice on this problem.

Thanks in advance.

Kind regards
Darren Brook
email: da*********@btconnect.com



Nov 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: =?Utf-8?B?am8uZWw=?= | last post by:
Hello All, I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM). On some devices the IM will not start. The IM appears in the IM-List but when it is selected from the...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.