簡體   English   中英

如何使用asp.net/C#在網頁上顯示Windows身份驗證?

[英]How to display Windows Authentication on webpage with asp.net/C#?

在這里輸入圖像描述我是編程的新手,因此對該注釋的任何幫助將不勝感激。 這是我使用Windows身份驗證來驗證用戶的問題,並且我想在我的網頁上顯示該用戶名。 例如:每當他們來到我的網頁時,“嗨,蒂米”。

我添加了system.directoryservices.accountmanagement,但是老實說,如果我只是沒有正確地使用UserPrincipal.DisplayName,則不確定這是否是正確的路徑。 承諾只是我嘗試過的其他一些想法。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Person_Search.aspx.cs" Inherits="Workwithme.WebPages.Person_Search" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Person Search</title>
    <link rel="stylesheet" type="text/css" href="/Styles/StyleSheet.css" />
</head>
<body>
    <header>
        <img src="/Images/NGSC.gif" style="max-width: 100%; height: 250px; background-repeat: no-repeat; margin: auto; display: block;" />

            <h1 style="text-align:center;color:white; width: 100%;">Search For A Person <br /> Phone Directory</h1>
        </header>
          <div id="navigation" style="text-align:center;">
                    <a href="Person_Search.aspx">Person Search</a>  
                    <a href="Person_Update.aspx">Personal Update</a>
            </div>
    <br />
    <div>
        <form id="form1" runat="server" style="background-color:#112e51; color:white;" >     
            <br />
            <h3>UserPrincipal.DisplayName</h3>

            <%--<asp:LoginName id="LoginName1" runat="server" 
               FormatString ="Welcome,{0}" />
            <h3>{{User.DisplayName}}</h3> --%>  

對於Windows身份驗證,請確保您的IIS設置正確。它應在瀏覽器中顯示Windows身份驗證對話框(IE除外,其中可能啟用了集成Windows身份驗證)。 現在,既然你有

創建一個名為ASPNETWinAuth的ASP.NET Web應用程序。 默認情況下,將顯示WebForm1.aspx文件。 在WebForm1.aspx的HTML視圖中,將現有代碼替換為以下示例代碼:

<%=User.Identity.Name%>

單擊開始,指向程序,指向管理工具,然后單擊Internet信息服務。 Internet信息服務MMC出現。 展開“計算機”,然后展開一個使用Windows身份驗證的網站。 單擊ASPNETWinAuth網站應用程序。 在“操作”菜單上,單擊“屬性”。 在“屬性”中,單擊“目錄安全性”選項卡。 在“匿名訪問和身份驗證控制”下,單擊“編輯”。 在“身份驗證方法”中,單擊以選擇“集成Windows身份驗證”。 單擊以清除所有其他復選框。

在為集成Windows身份驗證配置IIS網站之后,必須配置ASP.NET應用程序以識別經過身份驗證的用戶。 為此,您必須更改Web.config文件。 在Web.config文件中,找到標簽,然后將mode屬性設置為Windows,如以下示例所示:單擊“確定”。 在屬性中,單擊確定。 現在已將ASPNETWinAuth Web應用程序配置為接受有效的用戶帳戶。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM