I want to control user authentication in asp.net.
Assume that; there is two web from like StackOverflow.aspx and Default.aspx.
I want to get authenticated roles with below code:
public List<Roles> GetAuthenticatedRolesByModuleName(string moduleName)
{
//below I wrote psedeu code
var roles = "Select * From SiteRoles Where ModuleName = "Admin";
//...
}
//This function returns a result set which includes roles authentication for `moduleName` parameter.
And I will control it with current role which logon to the system.
I want to this in base page in asp.net.
In order to do it I make a BasePage.cs
which inherits from System.Web.UI.Page
.
I want to write GetAuthenticatedRolesByModuleName
function into BasePage.cs
and when user enters StackOverflow.aspx
I want to call the function from BasePage.cs
.
StackOverflow.aspx
have pageload event and I think I have to control role in Init()
.
I googled and find some sources such as: ASP.net "BasePage" class ideas but I did not understand clearly.
I want to get roles from base page function (moduleName is stack-overflow --> GetAuthenticatedRolesByModuleName(stack-overflow)
) and control with current role.
If the user is not authenticated, I will redirect it to the Default.aspx
.
Response.Redirect("Default.aspx");
How can I do it? Can you tell me a way to implement it?