powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Непонятно
1 сообщений из 1, страница 1 из 1
Непонятно
    #33819933
Аноним
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Добрый день
Сделал авторизацию в каталоги по ролям с помощью webconfig, однако один раз получилось с помощью роли "admin" зайти в каталог роли "manager" (ручками прописал каталог и страницу). В следующие разы правда сразу выносило на страницу логина.
Может кто знает в чем дело?

webconfig роли "admin"

<configuration>
<system.web>
<authorization>
<allow roles="admin" />
<deny users="*" />
</authorization>
</system.web>
</configuration>

webconfig роли "manager"

<configuration>
<system.web>
<authorization>
<allow roles="manager" />
<deny users="*" />
</authorization>
</system.web>
</configuration>


Global.asax


<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Security.Principal" %>

<script language="C#" runat="server">
void Application_AuthenticateRequest (Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;

if (app.Request.IsAuthenticated &&
app.User.Identity is FormsIdentity) {
FormsIdentity identity = (FormsIdentity) app.User.Identity;

// Find out what role (if any) the user belongs to
string role = GetUserRole (identity.Name);

// Create a GenericPrincipal containing the role name
// and assign it to the current request
if (role != null)
app.Context.User = new GenericPrincipal (identity,
new string[] { role });
}
}

string GetUserRole (string name)
{
SqlConnection connection = new SqlConnection
("server=localhost;database=weblogin;uid=sa;pwd=");

try {
connection.Open ();

StringBuilder builder = new StringBuilder ();
builder.Append ("select role from users " +
"where username = \'");
builder.Append (name);
builder.Append ("\'");

SqlCommand command = new SqlCommand (builder.ToString (),
connection);

object role = command.ExecuteScalar ();

if (role is DBNull)
return null;

return (string) role;
}
catch (SqlException) {
return null;
}
finally {
connection.Close ();
}
}
</script>
...
Рейтинг: 0 / 0
1 сообщений из 1, страница 1 из 1
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Непонятно
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]