how to give access to different user for different pages in asp.net with c#
-
how to give acess to different users for different pages (ie when user login based on his permissions he should be able to access his pages) usin asp.net with c#
-
how to give acess to different users for different pages (ie when user login based on his permissions he should be able to access his pages) usin asp.net with c#
You could use an atrribute to check the status of the user and redirect accordingly. Here is some simplistic pseudo code:
[AttributeUsage(AttributeTargets.All)]
public sealed class UserStatus : Attribute
{
public UserStatus()
{
if (!UserShouldBeHere)
{
HttpContext.Current.Response.Redirect("SomewhereElse.aspx");
}
}
}At the top of each page you want to check this on decorate the class with:
[UserStatus]
public partial class MyAccount : Page
... code continues -
You could use an atrribute to check the status of the user and redirect accordingly. Here is some simplistic pseudo code:
[AttributeUsage(AttributeTargets.All)]
public sealed class UserStatus : Attribute
{
public UserStatus()
{
if (!UserShouldBeHere)
{
HttpContext.Current.Response.Redirect("SomewhereElse.aspx");
}
}
}At the top of each page you want to check this on decorate the class with:
[UserStatus]
public partial class MyAccount : Page
... code continuesUse.. [PrincipalPermission(SecurityAction.Demand,Name=@"kovairindia\palash",Unrestricted=false)] public partial class Test : System.Web.UI.Page Only the user palash of domain Kovairindia will access this page. If Other one say rahul of Kovairindia domain will get System.Security.SecurityException exception. N.B:You can also give a permission to a Role for your page.
-
Use.. [PrincipalPermission(SecurityAction.Demand,Name=@"kovairindia\palash",Unrestricted=false)] public partial class Test : System.Web.UI.Page Only the user palash of domain Kovairindia will access this page. If Other one say rahul of Kovairindia domain will get System.Security.SecurityException exception. N.B:You can also give a permission to a Role for your page.
Thanks, but I know what I meant. You should add this as a separate answer as it is equally as valid and should be able to be marked on it's own. (Not everyone uses principals, roles, etc, to model security).
-
how to give acess to different users for different pages (ie when user login based on his permissions he should be able to access his pages) usin asp.net with c#
Use.. [PrincipalPermission(SecurityAction.Demand,Name=@"kovairindia\palash",Unrestricted=false)] public partial class Test : System.Web.UI.Page Only the user palash of domain Kovairindia will access this page. If Other one say rahul of Kovairindia domain will get System.Security.SecurityException exception. N.B:You can also give a permission to a Role for your page.
-
Thanks, but I know what I meant. You should add this as a separate answer as it is equally as valid and should be able to be marked on it's own. (Not everyone uses principals, roles, etc, to model security).
Sorry some mistake was there i did not want to post the message to you.. Thanks.
-
Sorry some mistake was there i did not want to post the message to you.. Thanks.
the code which you have send where we have to write the code.and can you give small example for this...
-
the code which you have send where we have to write the code.and can you give small example for this...
Put this below attribute in the top of your Page Code behind and Name Parameter is the permitted user for this page.... [PrincipalPermission(SecurityAction.Demand,Name=@"kovairindia\palash",Unrestricted=false)] Thanks