시나리오 : 웹용 Visual Studio Express 2012가 있습니다. 아무도 인증되지 않으면 내 웹 사이트의 로그 아웃 기능을 테스트하고 있습니다 (게스트 모드, 말하자면).HttpContext.Current.User.Identity .: ID가 로컬 웹 로그인과 웹 로그인을 연결합니다.
site.master.cs 코드
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
TopBox.Text = "Welcome " + HttpContext.Current.User.Identity.Name;
RegisterLabel.Visible = false;
Menu1.Visible = true;
Menu2.Visible = false;
}
else
{
TopBox.Text = "Welcome, Guest.";
RegisterLabel.Visible = true;
Menu1.Visible = false;
Menu2.Visible = true;
}
}
site.master 코드
<script type="text/javascript">
var t;
window.onload = resetTimer;
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;
function logout() {
try {
document.execCommand("ClearAuthenticationCache");
window.location.href = window.location.protocol.replace(/\:/g, '') + "://" + window.location.host + "Account/Login.aspx";
}
catch (e) { }
}
function resetTimer() {
window.clearTimeout(t);
t = window.setTimeout(logout, 900000);
}
</script>
<퍼센트 - 프레임 워크 스크립트 - %> <퍼센트 - 사이트 스크립트 - %> <% ---- %>
</Scripts>
</asp:ScriptManager>
<header>
<div class="content-wrapper">
<p style="float: left">
<br />
</p>
<br />
<asp:Label ID="RegisterLabel" runat="server" Text="Register">
<a style="font-size:small; color:white; align-content:center" href="Account/Register.aspx" >
Not Registered? Sign Up
</a>
</asp:Label>
<br />
<div>
<p>
<a class="MasterMenu" style="color: #A90000; font-size: larger" runat="server" href="~/">Following High School Football</a>
</p>
<p>
<asp:Label ID="TopBox" Font-Size="Small" Text="" runat="server" TextMode="SingleLine"></asp:Label>
</p>
<asp:Menu ID="Menu2" class="dropmenu" runat="server" Style="margin-left: 25%; margin-right: 25%; font-size: 12px;"
BackColor="Transparent"
StaticDisplayLevels="2" StaticHoverStyle-BackColor="ForestGreen" StaticMenuItemStyle-HorizontalPadding="1px"
StaticMenuItemStyle-ItemSpacing="1px" StaticMenuItemStyle-Width="100%" Font-Size="Large"
StaticMenuItemStyle-BackColor="DarkGreen" StaticMenuItemStyle-Height="40px">
<Items>
<asp:MenuItem NavigateUrl="Account/Login.aspx" Text="Login" Value="Login"></asp:MenuItem>
<asp:MenuItem NavigateUrl="Account/Register.aspx" Text="Register" Value="Register"></asp:MenuItem>
<asp:MenuItem NavigateUrl="Account/Recovery.aspx" Text="Password" Value="Recovery"></asp:MenuItem>
</Items>
</asp:Menu>
<asp:Menu ID="Menu1" class="dropmenu" runat="server" Style="margin-left: 25%; margin-right: 25%; font-size: 12px;"
BackColor="Transparent"
StaticDisplayLevels="2" StaticHoverStyle-BackColor="ForestGreen" StaticMenuItemStyle-HorizontalPadding="1px"
StaticMenuItemStyle-ItemSpacing="1px" StaticMenuItemStyle-Width="100%" Font-Size="Large"
StaticMenuItemStyle-BackColor="DarkGreen" StaticMenuItemStyle-Height="40px">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home" Value="Home"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Records.aspx" Text="Records" Value="Records"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Pickem.aspx" Text="Pick Em" Value="Pick Em"></asp:MenuItem>
<asp:MenuItem NavigateUrl="#" Text="Favorites" Value="Favorites"></asp:MenuItem>
<asp:MenuItem NavigateUrl="Account/Logoff.aspx" Text="Logoff" Value="Logoff"></asp:MenuItem>
</Items>
</asp:Menu>
</div>
</div>
</header>
<div id="body">
<asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
<section class="content-wrapper main-content clear-fix">
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
</section>
</div>
<footer style="position: absolute; bottom: -240px; width: 98%; left: 136px; height: 63px;">
<div class="content-wrapper">
<div class="float-right">
<br />
<br />
<p>© <%: DateTime.Now.Year %> - FHSF </p>
</div>
</div>
</footer>
</form>
의 Web.config
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5"/>
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<anonymousIdentification enabled="true"></anonymousIdentification>
<profile defaultProvider="DefaultProfileProvider" enabled="true">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="SqlServicesConnection" applicationName="/"/>
</providers>
<properties>
<add name="UserDetailID" type="int" />
</properties>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="SqlServicesConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="SqlServicesConnection" applicationName="/"/>
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="SqlServicesConnection"/>
</providers>
</sessionState>
</system.web>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0"/>
</parameters>
</defaultConnectionFactory>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0"/>
</dependentAssembly>
<dependantAssembly>
<assemblyIdentity name='EntityFramework' culture="neutral" PublicKeyToken="b77a5c561934e089" />
<bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0"/>
</dependantAssembly>
</assemblyBinding>
</runtime>
</configuration>
결과 : 내 의도가 아닌 경우 내 Windows 로그인이 인증 된 사용자로 표시됩니다. 나는 응용 프로그램 내에서만 인증 된 사용자를 결정할 수 있기를 원합니다. 이것을 어떻게 성취합니까? 로 작동합니다
대부분 사이트에서 Windows 인증을 사용 중이므로 결과 요청이 자동으로 인증됩니다. [편집] web.config의 해당 부분을 표시하여 다른 사람이 귀하의 질문에 답변 할 수 있도록 도와주십시오. –
Alexei의 제안에 따라 web.config 코드가 추가되었습니다. – MDDeVane
손님에게 Default.aspx 페이지로 이동하여 로그인 할 수있는 권한을 부여하고 싶습니다. aspx. 다른 웹 페이지에 액세스하는 메뉴를 숨겨서이 작업을 수행 할 수는 있지만 URL의 하위 도메인에 입력하는 것을 막지는 못합니다. – MDDeVane