مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

imanmir5

عضویت از 1393/02/14

ورود کاربر با استفاده از Active Directory

  • دوشنبه 26 آبان 1393
  • 15:39
تشکر میکنم

سلام

چطور میشه در mvc با استفاده از Identity کاربرها رو با استفاده از نام کاربری و کلمه عبور  Active Direcoty وارد سیستم کرد.

باتشکر

پاسخ های این پرسش

تعداد پاسخ ها : 1 پاسخ
کاربر سایت

fdafdfmohammad

عضویت از 1393/01/11

  • چهارشنبه 3 دی 1393
  • 17:46

First step: setting the parameters to use AD:

In your the section of your web.config file, set the following:

<authentication mode="Windows" />

<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
   <providers>
      <clear />
      <add 
          name="AspNetWindowsTokenRoleProvider"
          type="System.Web.Security.WindowsTokenRoleProvider" 
          applicationName="/" />
   </providers>
</roleManager>

Now, you will be able to directly use methods from the System.Web.Security namespace.

If you want to restrict the access to a View to only people members of the "groupName" group of your AD:

You only have to decorate your controller action like that:

[Authorize(Roles = @"DOMAIN\groupName")]
Public ActionResult Index()
{...}

If you want to do treatments based on the AD groups of users:

Use methods such as "IsInRole(rolename)" in your treatments:

if (User.IsInRole("DOMAIN\\groupName"))
{
     // Do what you want
}

EDIT: implementation of the problematic: here you should save the sAMAccountName of the group affected to your task when you create the task. Then when a user wants to mark the task as complete, just check:

if (User.IsInRole("DOMAIN\\" + sAMAccountNameOfTheGroupDedicatedToYourTask))
{
     // Mark as complete
}
کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)