Membership Security 403 - how to direct to Custom page instead of Login page

J

jobs

Hello.

If my users are logged in, and try to access restricted pages I want
to direct them to a custom 403 page. If they are not logged in, I
would like to continue to direct them to the login page as is
currently happening.

Curently, they always direct to the Login page in both cases, which i
think is confusing.

I have this in the web.config of the directory and the project
webconfig:

<customErrors defaultRedirect="~/ErrorPage.htm">
<error statusCode="403" redirect="~/NoAccess.htm"/>
<error statusCode="404" redirect="~/FileNotFound.htm"/>
</customErrors>

Thanks for any help or information!
 
B

Bjorn Sagbakken

jobs said:
Hello.

If my users are logged in, and try to access restricted pages I want
to direct them to a custom 403 page. If they are not logged in, I
would like to continue to direct them to the login page as is
currently happening.

Curently, they always direct to the Login page in both cases, which i
think is confusing.

I have this in the web.config of the directory and the project
webconfig:

<customErrors defaultRedirect="~/ErrorPage.htm">
<error statusCode="403" redirect="~/NoAccess.htm"/>
<error statusCode="404" redirect="~/FileNotFound.htm"/>
</customErrors>

Thanks for any help or information!

As Peter said, there are many ways.

In my application, I keep the username from the login-form in a session var.
Next, on any form load, I check the username for access rights. If not
granted, the user is redirected to the login form.
This gives me even more options: On some forms I can give readonly right to
certain users, while other users can update the database. In my case I have
a user login table on a SQL server with more than granted access/not granted
access; I have about 10 properties for each user so I can set a lot of
individual settings in each form. It is very flexible and very functional.

Bjorn
 
J

jobs

Thanks for responses.

regarding:
In my application, I keep the username from the login-form in a session var.
Next, on any form load, I check the username for access rights. If not
granted, the user is redirected to the login form.

I believe this is the default behavior of membership security. (that
much is working fine for me with no code)

regarding:
if(! User.IsInRole("whateverspecialRole")
Response.Redirect("yourcustompage.aspx")

It think it is somewhat lacking (in .NET) that you have to code
security conditions. I have some 8 roles.

Also, I think I would to check if even a valid user to redirect to
Login Page as that condition would also be true for anonymous users.

I wonder ... what if I (somehow) test to see if already a valid user
in the Login page and redirect to NoAccess from there? and if a
user, just direct to default page. Not sure if this is possible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top