i have a button on a page, so when it is clicked it will check the user and allow him the access to admin page. what i want is if he is not the one how can i redirect the user to error.aspx. When the user is ABC i can go to admin page but when i change the
user to bc in web config it says accesss is denied (thats ok). but i want to redirect it to error.aspx. This webconfig is local to the Admin folder. Admin page is in Admin folder names as default.aspx
Description:
An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the
Web server's administrator for additional assistance.
Public Sub Application_AuthorizeRequest(ByVal sender As Object, ByVal e As EventArgs)
If (sender.Request.Path.ToUpper().EndsWith("LOGIN.ASPX") And sender.Request.IsAuthenticated) Then
sender.Response.Redirect("~/Unauthorized.aspx")
End If
End Sub
1. Only allow admin to login into your admin folder. If another user logs in, instead of sending him to page and then redirecting him to error , directly redirect him to error page.
2. In the page_Init event check the user, if he is the right one, continue if not redirect him to error page.
NOTE : If error page is not in the same folder try using absolute path instead of relative path. Ex:- If your site abc.com then use http://www.abc.com/errors/errorpage.aspx . if you are on locathost then give path according to that.
Hope it helps you.
Mark the post as Answer if it helped you so that others dont waste time looking for solution
Arvind Kumar
The Problem is when i set my admin page as a start up page and then when i load it if the local webconfig file contains the user it will display the admin page else it will display error. what i want is if the user is not in local config instead of displaying
error it should navigate to anothe page. there r only 10 users out of many who r given acces to this page and they r specified in local webconfig that is in admin folder of project.
muhammadazee...
Member
4 Points
165 Posts
Redirect a User to an Eror Page if not present in Webconfig?
Jan 03, 2013 07:29 PM|LINK
i have a button on a page, so when it is clicked it will check the user and allow him the access to admin page. what i want is if he is not the one how can i redirect the user to error.aspx. When the user is ABC i can go to admin page but when i change the user to bc in web config it says accesss is denied (thats ok). but i want to redirect it to error.aspx. This webconfig is local to the Admin folder. Admin page is in Admin folder names as default.aspx
Web.Config
</appSettings>
<connectionStrings/>
<system.web>
<authorization>
<allow users="ABC"/>
<deny users="?, *"/>
</authorization>
</system.web>
C# Code
protected void btnAdminPage_Click(object sender, EventArgse)
{
Response.Redirect("~/Admin/Default.aspx");
}
niksv
Contributor
5925 Points
1115 Posts
Re: Redirect a User to an Eror Page if not present in Webconfig?
Jan 03, 2013 08:16 PM|LINK
Write custom errors block in config and add error condition for http 401 status code.
http://msdn.microsoft.com/en-us/library/h0hfz6fc(v=vs.71).aspx
muhammadazee...
Member
4 Points
165 Posts
Re: Redirect a User to an Eror Page if not present in Webconfig?
Jan 03, 2013 08:58 PM|LINK
The error i get is
Server Error in '/' Application.
Access is denied.
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.
oned_gk
All-Star
31764 Points
6492 Posts
Re: Redirect a User to an Eror Page if not present in Webconfig?
Jan 04, 2013 02:53 AM|LINK
Try this in global.asax
Public Sub Application_AuthorizeRequest(ByVal sender As Object, ByVal e As EventArgs) If (sender.Request.Path.ToUpper().EndsWith("LOGIN.ASPX") And sender.Request.IsAuthenticated) Then sender.Response.Redirect("~/Unauthorized.aspx") End If End Subnefester0000
Member
207 Points
92 Posts
Re: Redirect a User to an Eror Page if not present in Webconfig?
Jan 04, 2013 06:01 AM|LINK
Hi,
I think you can do it two ways.
1. Only allow admin to login into your admin folder. If another user logs in, instead of sending him to page and then redirecting him to error , directly redirect him to error page.
2. In the page_Init event check the user, if he is the right one, continue if not redirect him to error page.
NOTE : If error page is not in the same folder try using absolute path instead of relative path. Ex:- If your site abc.com then use http://www.abc.com/errors/errorpage.aspx . if you are on locathost then give path according to that.
Hope it helps you.
Arvind Kumar
rimagandhi
Participant
1589 Points
512 Posts
Re: Redirect a User to an Eror Page if not present in Webconfig?
Jan 04, 2013 06:14 AM|LINK
<configuration>
<system.web>
<customErrors defaultRedirect="SiteErrorPage.aspx" mode="RemoteOnly">
<error statusCode="403" redirect="RestrictedAccess.aspx" />
<error statusCode="404" redirect="pagenotFound.aspx" />
</customErrors>
<system.web>
</configuration>
Regards
Rima Gandhi.
Software Developer.
muhammadazee...
Member
4 Points
165 Posts
Re: Redirect a User to an Eror Page if not present in Webconfig?
Jan 04, 2013 07:17 PM|LINK
The Problem is when i set my admin page as a start up page and then when i load it if the local webconfig file contains the user it will display the admin page else it will display error. what i want is if the user is not in local config instead of displaying error it should navigate to anothe page. there r only 10 users out of many who r given acces to this page and they r specified in local webconfig that is in admin folder of project.
Thanks