翻譯|使用教程|編輯:況魚杰|2019-12-27 11:25:16.460|閱讀 334 次
概述:本文將會介紹有關如何部署能夠在Microsoft Azure中接收用戶鎖通知的Web應用程序的分步指南。Webhooks使Web應用程序可以實時訂閱UserLock中發生的關鍵訪問事件。本文分為上下兩部分,此為上文。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
UserLock是您的Windows網絡守門人,它可以輕松實現有效的Windows和Active Directory網絡用戶訪問控制策略,并嚴格執行。
本文將會介紹有關如何部署能夠在Microsoft Azure中接收用戶鎖通知的Web應用程序的分步指南。Webhooks使Web應用程序可以實時訂閱UserLock中發生的關鍵訪問事件。本文分為上下兩部分,此為上文。(點擊此處可以查看下文)
會話事件(如登錄,注銷,鎖定,解鎖,拒絕登錄等)作為JSON消息發送到Web應用程序。然后可以根據特定的訪問事件構建自定義工作流。結合UserLock API,它還允許為特定用戶配置文件動態創建永久或臨時限制,以響應特定事件。
先決條件
安裝Visual Studio 2017:
ASP.NET和Web開發
Azure開發

創建UserLockWebHook MVC Web應用程序
在Visual Studio中,通過選擇File(文件)>New(新建)>Project(項目)來創建一個項目。
在New Project(新建項目)對話框中,選擇Visual C#>Web>ASP.NET Web應用程序(.NET Framework)。

選擇MVC模板
選擇MVC模板,并確保將身份驗證設置為No Authentication(無身份驗證)。

更新所有NuGet軟件包并安裝NewtonSoft.Json軟件包
打開工具->NuGet數據包管理器->管理該解決方案的NuGet軟件包。
打開更新標簽,選中Select all packages(選擇所有軟件包)復選框,然后單擊更新按鈕。
打開瀏覽選項卡,在搜索字段中輸入Newtonsoft.Json并安裝軟件包。該軟件包將用于反序列化UserLock發送的通知。
在模型文件夾中創建以下類
這些類還將在反序列化過程中使用。(下載UserLock可嘗試操作)
public class UserLockServer
{
public string Id { get; set; }
public string FQDN { get; set; }
public string DisplayName { get; set; }
}
public class UserlockNotification
{
public UserLockServer Userlock { get; set; }
public int EventType { get; set; }
public DateTime EventTime { get; set; }
public string UserAccount { get; set; }
public string UserDomain { get; set; }
public string UserFullName { get; set; }
public string ComputerName { get; set; }
public int ComputerSession { get; set; }
public string ClientName { get; set; }
public string ClientAddress { get; set; }
public string SessionId { get; set; }
public int SubSessionId { get; set; }
public int LogonInfo { get; set; }
public int SessionType { get; set; }
public string ServerAddress { get; set; }
public int TimeZoneShift { get; set; }
public string Param1 { get; set; }
public string Param2 { get; set; }
public string Param3 { get; set; }
public string Param4 { get; set; }
public string Param5 { get; set; }
public string Param6 { get; set; }
}更新HomeController
用以下內容替換HomeController類:
public class HomeController : Controller
{
private static List _notifications = new List();
private static List _userLockIds = new List();
public ActionResult Index()
{
Response.AddHeader("Refresh", "3");
ReadUserlockIds();
return View(_notifications);
}
private void ReadUserlockIds()
{
string ids = ConfigurationManager.AppSettings["UserlockIds"];
_userLockIds = ids.Split(new char[] { ';' }).ToList();
}
[HttpPost]
public ActionResult Notify()
{
try
{
string data = GetPostData(Request.InputStream);
UserlockNotification ul = JObject.Parse(data).ToObject();
// Is the notification sender valid?
// Uncomment the following lines to add a security check
// between the webhook application and UserLock service
// if (!_userLockIds.Contains(ul.Userlock.Id))
// return new HttpStatusCodeResult(HttpStatusCode.OK);
// Truncate Userlock Id to avoid displaying sensitive information
ul.Userlock.Id = ul.Userlock.Id.Substring(1,8);
_notifications.Add(ul);
}
catch (Exception ex)
{
}
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
private static string GetPostData(Stream inputStream)
{
string data = null;
StreamReader reader = new StreamReader(inputStream);
try
{
reader.BaseStream.Position = 0;
data = reader.ReadToEnd();
}
finally
{
reader.BaseStream.Position = 0;
}
return data;
}
public ActionResult About()
{
return View();
}
public ActionResult Contact()
{
return View();
}
public ActionResult GoToWebsite()
{
return Redirect("//www.isdecisions.com");
}
}要修復丟失的using語句,請右鍵單擊每個錯誤,然后選擇適當的操作。這些可以在快速操作和重構子菜單中找到。
使用Index方法中的Refresh標頭可以自動刷新主頁,以便按塊顯示傳入的通知。Notify方法將UserLock通知反序列化為UserLockNotification實例。為了方便起見,選擇在HomeController中添加Notify方法。您當然可以決定在另一個控制器(mycontroller / mymethod)中創建其他方法。
安全檢查
控制UserLock ID可確保您避免從無效來源接收通知。因此,可以在web.config中定義一個GUID列表,以聲明白名單的UserLock ID,并確保所有收到的通知均來自受信任的來源。
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="UserlockIds" value="{your_userlock_guid1};{your_userlock_guid2};" />
</appSettings>注意:如果您已經部署了UserLock備份服務器,請不要忘記將UserLock備份服務器ID添加到此列表中。
然后,您可以在Notify方法中取消注釋行。這樣,僅處理聲明的UserLock服務器發送的通知。
// Is the notification sender valid? // Uncomment the following lines to add a security check // between the webhook application and UserLock service if (!_userLockIds.Contains(ul.Userlock.Id)) return new HttpStatusCodeResult(HttpStatusCode.OK);
=========================================
想要了解或購買UserLock正版版權,請
更多精彩內容,歡迎關注下方的微信公眾號,獲取更多產品咨詢

本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自: