具有活动目录组MVC的Windows身份验证

时间:2018-07-12 09:28:41

标签: asp.net-mvc windows-authentication

我为仅在内部使用的Web应用程序实施Windows身份验证。这样,用户无需登录应用程序,而是在登录Windows时已通过身份验证。

我需要根据用户所属的组以及该组对Active Directory的权限,授予用户访问应用程序不同部分的权限。

我能够通过使用以下命令在不同的视图上做到这一点:

[Authorize(Roles = @"Domain\Group")]

我该如何在同一个View上做这些事情,以便根据Active Directory中用户的组权限授予对View的不同部分的访问权限。

<div class="row">
    <div class="col-md-4">
        <h2>User Name: @User.Identity.Name</h2>
        <p>
         Test site with Active Directory
            Only users that belong to Group 1 should see this section
        </p>
        <p></p>
    </div>
    <div class="col-md-4">
        <label>Only users that belong to Group 2 should see this section</label>
    </div>
    <div class="col-md-4">
        <label>Only users that belong to Group 3 should see this section</label>
    </div>

1 个答案:

答案 0 :(得分:1)

您可以在视图中使用C#/ Razor条件语句来根据用户所属的组来更改内容,如下所示:

(base) C:\****>python ****.py
starting our macro refresh - started at....20180712_170741
Traceback (most recent call last):
  File "****.py", line 56, in <module>
    xl.Application.Run("Macro1")
  File "<COMObject <unknown>>", line 14, in Run
  File "C:\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 287, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Cannot run the macro 'Macro1'. The macro may not be available in this workbook or all macros may be disabled.", 'xlmain11.chm', 0, -2146827284), None)

(base) C:\****>python ****.py
starting our macro refresh - started at....20180712_170942
Traceback (most recent call last):
  File "****.py", line 49, in <module>
    writer.save()
  File "C:\Anaconda3\lib\site-packages\pandas\io\excel.py", line 1732, in save
    return self.book.close()
  File "C:\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 311, in close
    self._store_workbook()
  File "C:\Anaconda3\lib\site-packages\xlsxwriter\workbook.py", line 640, in _store_workbook
    allowZip64=self.allow_zip64)
  File "C:\Anaconda3\lib\zipfile.py", line 1090, in __init__
    self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied: '****.xlsm'