GVKun编程网logo

asp.net – 带有Windows身份验证的User.Identity.Name(.net身份验证有哪些)

7

本文将带您了解关于asp.net–带有Windows身份验证的User.Identity.Name的新内容,同时我们还将为您解释.net身份验证有哪些的相关知识,另外,我们还将为您提供关于.net–W

本文将带您了解关于asp.net – 带有Windows身份验证的User.Identity.Name的新内容,同时我们还将为您解释.net身份验证有哪些的相关知识,另外,我们还将为您提供关于.net – Windows身份验证的简单索赔转换和缓存、ASP.NET / IIS安全性(Windows身份验证)、asp.net – HttpContext.Current.User为空,即使Windows身份验证已打开、asp.net – IIS7中的SQL Server和Windows身份验证的实用信息。

本文目录一览:

asp.net – 带有Windows身份验证的User.Identity.Name(.net身份验证有哪些)

asp.net – 带有Windows身份验证的User.Identity.Name(.net身份验证有哪些)

我的标题中有一个非常简单的局部视图叫做AccountInfoPanel.
它只有一行:
Welcome: @HttpContext.Current.User.Identity.Name

在我的Web.Config我有

<authentication mode="Windows" />

但身份名称始终为空.
如果我通过VS 2012调试,并打破索引操作,我看到它是空的.

如果我通过启用Windows身份验证和匿名身份验证的IIS运行它,我会遇到挑战.
所以我尝试插入我的帐户或test1和test2帐户.
它回来说:

HTTP错误401.1 – 未经授权
您无权使用您提供的凭据查看此目录或页面.

我也尝试将Impersonation设置为true并从挑战中获得相同的响应.
有谁知道如何设置它?

如果所有设置都必须在IIS中完成,那么如何在Visual Studio中调试代码?

另一个问题.我的老板似乎认为你甚至不需要登录框. IE会知道你是谁.并且您可以使用其他帐户在IE中“运行”.

解决方法

检查我的清单上的一个可能的问题

http://netpl.blogspot.com/2012/06/iis-75-integrated-security-with-no.html

简而言之:

首先,确保为站点关闭匿名身份验证:

其次,在Interner Explorer中启用集成安全性(选项/高级并选中“启用集成Windows身份验证”选项).

第三步,将您的网站添加到“本地Intranet”区域,并至少选择“选项/安全设置/本地Intranet /自定义级别”下的“仅在Intranet区域中自动登录”选项.

第四,确保用户和应用程序服务器位于同一个域中.

.net – Windows身份验证的简单索赔转换和缓存

.net – Windows身份验证的简单索赔转换和缓存

在过去几天,我一直在阅读Windows身份基础,以及它如何良好和灵活,并且正确地构建到.net 4.5中。尽管过了几十个apis,博客帖子,how-to的等等,我不能为我的生活一个简单的实现工作。

我只使用Windows身份验证,我可以得到委托人并查看它附带的声明(这是每个例子似乎都结束的地方)。然而,我想将它们转化为有用的声明,并缓存结果,以便转换不会在每个请求上发生。

在我的web.config我有:

<configSections>
    <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection,System.IdentityModel,Version=4.0.0.0,Culture=neutral,PublicKeyToken=B77A5C561934E089" />
    <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection,System.IdentityModel.Services,PublicKeyToken=B77A5C561934E089" />
  </configSections>

  <system.identityModel>
    <identityConfiguration>
      <claimsAuthenticationManager type="SecurityProj.MyClaimsTransformationModule,SecurityProj" />
      <claimsAuthorizationManager type="SecurityProj.MyClaimsAuthorizationManager,SecurityProj" />
    </identityConfiguration>
  </system.identityModel>

但是,身份验证管理器永远不会被调用。我可以让它做的工作的唯一方法是添加:

protected void Application_PostAuthenticateRequest()
{
    ClaimsPrincipal currentPrincipal = ClaimsPrincipal.Current;
    ClaimsTransformationModule customClaimsTransformer = new MyClaimsTransformationModule();
    ClaimsPrincipal tranformedClaimsPrincipal = customClaimsTransformer.Authenticate(string.Empty,currentPrincipal);
    HttpContext.Current.User = tranformedClaimsPrincipal;
}

到我的global.asax.cs文件。它工作在第一个请求,但后来我得到“安全句柄已经关闭”错误之后,不知道是什么导致它。显然,这不是正确的做法,有谁知道最好还是简单的工作做法呢?这只是为了Windows身份验证,我不需要任何比这更复杂的东西。

对于缓存,我试图使用:

SessionSecurityToken token = FederatedAuthentication.SessionAuthenticationModule
            .CreateSessionSecurityToken(
            currentPrincipal,"Security test",System.DateTime.UtcNow,System.DateTime.UtcNow.AddHours(1),true);

        if (FederatedAuthentication.SessionAuthenticationModule != null &&
            FederatedAuthentication.SessionAuthenticationModule.ContainsSessionTokenCookie(HttpContext.Current.Request.Cookies))
        {
            return;
        }
        FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(token);

但我也不确定这一点,转型问题需要先修好。

任何帮助将不胜感激。谢谢你只需要调用查找/转换和一个cookie集。

我现在有一切工作,这是我如何去做的:

在这个页面上:http://msdn.microsoft.com/en-us/library/ee517293.aspx是一个关键段落:

If you want to make your RP application claims-aware,but you do not have an STS (for example,the RP uses Forms authentication or Windows integrated authentication),you can use the ClaimsPrincipalHttpModule. This module sits in your application’s HTTP pipeline and intercepts authentication information. It generates a IClaimsPrincipal for each user based on that user’s username,group memberships,and other authentication information. ClaimsPrincipalHttpModule must be inserted at the end of the <httpModules> pipeline,which is the first element in the <modules> section of <system.webServer> on IIS 7.

和这个页面:

http://leastprivilege.com/2012/04/04/identity-in-net-4-5part-2-claims-transformation-in-asp-net-beta-1/

给你全班现在将该类添加到web.config中:

<modules>
  <add name="ClaimsTransformationHttpModule" type="TestSecurity.ClaimsTransformationHttpModule" />
</modules>

现在它将调用转换,我可以删除global.asax中的后验证方法。

在认证方法中,我称之为设置cookie:

private void CreateSession(ClaimsPrincipal transformedPrincipal)
{
    SessionSecurityToken sessionSecurityToken = new SessionSecurityToken(transformedPrincipal,TimeSpan.FromHours(8));
    FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(sessionSecurityToken);
}

来自之前的模块已经设置为查看它,并跳过验证(如果存在)。

最后是我不断得到的安全处理错误。我不完全确定原因,但是我发现如果我修改了被传递给Authenticate的主体,然后返回它(这在msdn上显示),那么错误将显示在所有后续请求中。但是,如果我创建并返回一个新的委托人,那么它不会发生。这也可以用于删除您不需要的声明。

List<Claim> newClaims = new List<Claim>();

var keeper = ((ClaimsIdentity)incomingPrincipal.Identity).Claims.First(c =>
    c.Type == ClaimTypes.Name);
newClaims.Add(keeper);

ClaimsIdentity ci = new ClaimsIdentity(newClaims,"Negotiate");

return new ClaimsPrincipal(ci);

所以现在我可以windows验证,引入自定义的声明,并让他们用cookie缓存。希望这有助于其他任何人试图做同样的事情,如果我没有做正确的事情请让我知道。

ASP.NET / IIS安全性(Windows身份验证)

ASP.NET / IIS安全性(Windows身份验证)

这可能会成为一个doozie.

我正在开发一个ASP.NET应用程序,放在我们公司的Intranet站点上.我已经提交了有关安全性的规范,并且不知道如何做到这一点.

第一部分:应用程序是使用Windows身份验证.这部分似乎很容易;我在管理工具中打开了IIS,右键单击了我的网站节点,属性并选中了“集成Windows身份验证”.但是,我不知道我将如何管理哪些人可以访问我的网站.我认为应该在数据库级别处理这个问题.这是q#1

第二部分 – 我必须为以下场景实现一个过程:用户’Jane’可以登录我们的网络,但没有我的应用程序的权限.用户’Bob’确实有权使用我的应用程序. Bob需要能够坐在Jane的计算机上(在她的网络帐户下),但能够将他的凭据输入我的应用程序并使用它(即使Jane已登录到本地计算机和网络).这是q#2

任何帮助,总体方向或建议将不胜感激.中奖彩票号码将更受欢迎.

谢谢,

贾森

解决方法

您正在寻找ASP.NET中的Windows身份验证和授权

> How To Use Windows Auth in ASP.NET
> Authentication/Authorization Explained
> How To Implement Windows Auth in ASP.NET

第2部分……你是对的,这很难.您需要推出自己的自定义安全提供程序.
您将拥有一个登录页面,然后自行检查Active Directory.从MSDN

ASP.NET also supports custom solutions for using Windows authentication,which bypasses IIS authentication. For example,you can write a custom ISAPI filter that checks the user’s credentials against Active Directory. With this approach you must manually create a WindowsPrincipal object.

asp.net – HttpContext.Current.User为空,即使Windows身份验证已打开

asp.net – HttpContext.Current.User为空,即使Windows身份验证已打开

在Windows Server 2008中的IIS7中,我有一个虚拟目录,具有匿名访问权限和Windows身份验证.在我的web.config中,我有:
<authentication mode="Windows"/>
<authorization>
            <allow roles="MYGROUP"/>
            <deny users="*"/>
</authorization>

<system.webServer>
    <!-- IIS7 security settings -->
    <security>
        <authorization>
                <add accesstype="Deny" users="*"/>
                <add accesstype="Allow" roles="MYGROUP"/>
        </authorization>
    </security>
</system.webServer>

然而当我从IE访问default.aspx并在Global.asax.vb Application_AuthenticateRequest()中设置一个断点时,我得到一个null HttpContext.Current.User,我希望自己的身份.几乎就像匿名访问一样?

我可以如何解决这个问题?一切似乎都在IIS6中运行.

解决方法

将应用程序池移回古典的答案只是拖延问题.

而是将应用程序池单独放置,并将您的验证检查从Application_AuthenticateRequest()移动到管道中的下一个函数:

Application_AuthorizeRequest(object sender,EventArgs e)

到那时,集成的应用程序池已经完成了Windows身份验证,允许您不从HttpContext.Current.User接收null.

可以在标题Runtime Fidelity(向下))找到流水线here(由CarlosAg提供的链接).

管道的可视化可以在asp website message lifecycle page找到.在控制器部分检查两个绿色框“认证过滤器”和“授权过滤器”.这些是你正在搞乱的地方.

asp.net – IIS7中的SQL Server和Windows身份验证

asp.net – IIS7中的SQL Server和Windows身份验证

我正在尝试使用sql Server和 Windows身份验证在Vista(IIS7)上运行ASP.NET网站.无论我做什么,当我连接到数据库时,我得到例外:
    sqlException was unhandled
    Login Failed for user 'MyDomain\MachineName$'.

我应用的设置似乎并不重要,我无法让IIS7通过我的Windows登录凭据.

额外细节:

> sql Server和本地计算机都在ActiveDirectory上
> Vista Enterprise,IIS7
> sql Server 2005
>禁用匿名身份验证,启用Windows身份验证
>假冒开/关没有区别
>所有身份(NetworkService,LocalSystem等)给出相同的结果
>经典和集成管道提供相同的结果

救命!

解决方法

正确配置后,模拟开启/关​​闭会产生重大影响.您想要的是“约束委派”,您需要为它配置IIS和ASP:

> How To: Use Protocol Transition and Constrained Delegation in ASP.NET 2.0
> Configure ASP.NET Impersonation Authentication (IIS 7)
> Configuring Servers for Delegation

今天的关于asp.net – 带有Windows身份验证的User.Identity.Name.net身份验证有哪些的分享已经结束,谢谢您的关注,如果想了解更多关于.net – Windows身份验证的简单索赔转换和缓存、ASP.NET / IIS安全性(Windows身份验证)、asp.net – HttpContext.Current.User为空,即使Windows身份验证已打开、asp.net – IIS7中的SQL Server和Windows身份验证的相关知识,请在本站进行查询。

本文标签: