473,396 Members | 1,907 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,396 software developers and data experts.

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

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!

Jun 24 '07 #1
4 1907
There are a number of different ways to handle this, an easy one would be
something like so:

Page_Load ----

if(! User.IsInRole("whateverspecialRole")
Response.Redirect("yourcustompage.aspx")
This assumes your <location path= element specifies role-based permissions.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"jobs" wrote:
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!

Jun 24 '07 #2
"jobs" <jo**@webdos.comwrote in message
news:11**********************@c77g2000hse.googlegr oups.com...
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
Jun 24 '07 #3
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.

Jun 24 '07 #4
You could certainly do it that way. Another way would be to override
Application_AuthenticateRequest in global.asax and put your test logic there.
Again, it all depends on the particular business logic of your app.

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"jobs" wrote:
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.

Jun 24 '07 #5

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

Similar topics

2
by: John | last post by:
Hi I was working fine with create user wizard and the default membership provider. I have now customised the membership provider as per attached web.config. The create user wizard picks up the...
3
by: ad | last post by:
I have create a custom membership provider. The common usage of custom membership is set it as default Membership Provider win web.config, and use login controls with it. How can I use custom...
9
by: Paul Keegstra | last post by:
Hi, I am currently working on an asp.net 2.0 web site that is a replacement of a classic asp web site. The current web site uses a Commerce Server 2002 database for storing user information. ...
2
by: John | last post by:
OK, I read and read again information on using the logon control, 'custom providers' but none are really helping me out with creating a provider to go against my database to validate the users...
3
by: Dabbler | last post by:
I need to have users login using the ASP.NET sqlprovider but then would like to direct them to a page based on some info in a separate table. Is there code to generate the strange userid field in...
3
by: jason | last post by:
I've been playing around with new (for 2.0) membershp functionality. I was able to build a simple login form that secures a directory on a project I built locally on my development desktop. ...
4
by: =?Utf-8?B?Q2hyaXMgQ2Fw?= | last post by:
I have been having some trouble with implementing a custom Membership Provider. We have a custom data store and business logic that pulls user information. I need some level of functionality...
3
by: dm3281 | last post by:
Hello -- I need to write an ASP.NET 2.0 application for our clients to use to login and verify file transmissions. Each client will need their own logon, in addition to a way to assign each...
1
by: Jeff | last post by:
Hey ASP.NET 2.0 At work my boss have given me the task of developing a new website. Users will be able to register at the website and gain exclusive access to some information etc... Some...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.