我需要使用C#以编程方式查找用户名.具体来说,我想让系统/网络用户连接到当前进程.我正在编写一个使用Windows集成安全性的Web应用程序.
我刚刚将我的应用程序从Visual Studio 2012升级到Visual Studio 2013.我的Windows身份验证不再起作用了.它给了我以下错误.
HTTP Error 401.2 - Unauthorized
You are not authorized to view this page due to invalid authentication headers.
Run Code Online (Sandbox Code Playgroud)
在visual studio中,可以选择从网站属性本身进行身份验证.所以我禁用了匿名访问并启用了Windows身份验证,但是它要求我输入用户名和密码,如下面的弹出窗口所示.即使我在这里提供域凭据.它仍然一次又一次地给我这个弹出窗口.
Web配置:
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
<identity impersonate="false" />
<trace enabled="true" />
Run Code Online (Sandbox Code Playgroud)
IIS Express aspnetConfig:
<authentication>
<anonymousAuthentication enabled="false" userName="" />
<basicAuthentication enabled="false" />
<clientCertificateMappingAuthentication enabled="false" />
<digestAuthentication enabled="false" />
<iisClientCertificateMappingAuthentication enabled="false">
</iisClientCertificateMappingAuthentication>
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>
</authentication>
<authorization>
<add accessType="Allow" users="*" />
</authorization>
<location path="Path"> …
Run Code Online (Sandbox Code Playgroud) 我有一个运行Windows身份验证的WebAPI 2 REST服务.它与网站分开托管,因此我使用ASP.NET CORS NuGet包启用了CORS.我的客户端站点正在使用AngularJS.
到目前为止,这是我经历过的:
我被困的地方 - 我的Angular预检电话不包括凭据.根据这个答案,这是设计,因为OPTIONS请求被设计为匿名.但是,Windows身份验证使用401停止请求.
我已经尝试将[AllowAnonymous]属性放在我的MessageHandler上.在我的开发计算机上,它可以工作 - OPTIONS动词不需要身份验证,但其他动词可以.但是,当我构建并部署到测试服务器时,我将继续在我的OPTIONS请求中获得401.
使用Windows身份验证时,是否可以在我的MessageHandler上应用[AllowAnonymous]?如果是的话,有关如何做的任何指导?或者这是一个错误的兔子洞,我应该看一个不同的方法?
更新:我能够通过在IIS中的站点上设置Windows身份验证和匿名身份验证来使其工作.这导致一切都允许匿名,所以我添加了一个全局的Authorize过滤器,同时保留了MessageHandler上的AllowAnonymous.
然而,这感觉就像一个黑客...我一直都明白只应该使用一种身份验证方法(不混合).如果有人有更好的方法,我会很感激听到它.
我正在ASP .NET 5,MVC 6中构建一个Intranet应用程序.我想知道如何启用Windows身份验证.默认项目模板仅支持单个用户帐户.
我希望能够使用jdbc和Windows身份验证连接到SQL Server.我在互联网上看到一些答案说我应该将以下属性添加到连接字符串:
integratedSecurity=true;
Run Code Online (Sandbox Code Playgroud)
并且还添加
sqljdbc_auth.dll
Run Code Online (Sandbox Code Playgroud)
到java路径.
但据我所知,只有在我从Windows机器上连接时才适用.当我在Linux机器上尝试这个时,我得到:
java.sql.SQLException: This driver is not configured for integrated authentication
Run Code Online (Sandbox Code Playgroud)
我的问题是我如何从Linux机器上做到这一点.
谢谢
我的目标是以安全的方式使用JDBC/Hibernate对数据库进行身份验证,而无需以纯文本形式存储密码.代码示例赞赏.我已经在使用华夫饼干对用户进行身份验证,因此如果有某种方法可以使用从用户那里获得的凭证,并将其转发给数据库,那就太好了.
两个问题:
我找到了一些有关在此线程中连接到SQL Server的有用信息.但是,我期待Tomcat将在默认帐户下运行,例如本地系统或其他东西.据我所知,该帐户不能用于对数据库进行Windows身份验证.
我的解决方案:
我最终使用上述线程中提到的方法.它不是将Tomcat服务作为本地系统运行,而是以用户身份运行.该用户有权访问数据库.我的hibernate配置文件配置如下:
<property name="hibernate.connection.url">
jdbc:sqlserver://system:port;databaseName=myDb;integratedSecurity=true;
</property>
Run Code Online (Sandbox Code Playgroud)
对那些提供回复的人
我感谢大家的帮助,我将尝试一些线程中提到的技术.我对某些响应的问题是它们需要对称加密,这需要一个密钥.保持密钥的秘密几乎与将密码以纯文本格式存储完全相同.
我试图在我的ASP.NET MVC2应用程序中实现Windows身份验证.我遵循了官方文档建议的所有步骤:
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
Run Code Online (Sandbox Code Playgroud)
我已经指定了NTLM身份验证.到现在为止还挺好.一切正常.我想检查登录我的数据库的用户.我想从我的表中获取角色,然后使用自定义属性管理授权.
我不想使用会员和角色提供者.
我已经有我的表用户/角色,因为他们已经被用于互联网应用程序(这是内联网应用程序).
在我的Internet App中,我有一个用户输入数据的表单.表单将发布到控制器,该控制器将检查所有内容并使用登录用户的用户(和角色)创建cookie.
在我的global.asax中,我捕获了AuthenticateRequest事件,在那里我读取了cookie并创建了一个自定义主体,我在整个应用程序中使用它来检查授权.
如何使用Windows身份验证实现此功能?
我在网站上收到错误,我使用Windows身份验证.
奇怪的事情:
这是我在日志邮件中得到的:
来源:System.DirectoryServices
消息:服务器无法运行.
跟踪:
在System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)
在System.DirectoryServices.DirectoryEntry.Bind()
在System.DirectoryServices.DirectoryEntry.get_AdsObject()
在System.DirectoryServices.DirectorySearcher.FindAll(布尔findMoreThanOne)
在的System.DirectoryServices
.DirectorySearcher.FindOne ()在Smarthouse.Labs.DataAccess.UserListManager.SaveUser(String windowsUserName)
这是我实现DirectorySearch的方式:
private void SaveUser(string windowsUserName)
{
string[] domainAndUser = windowsUserName.Split('\\');
string domain = domainAndUser[0];
string username = domainAndUser[1];
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
DirectorySearcher search = new DirectorySearcher(entry);
try
{
// Bind to the native AdsObject to force authentication.
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
search.PropertiesToLoad.Add("sn");
search.PropertiesToLoad.Add("givenName");
search.PropertiesToLoad.Add("mail");
SearchResult result = search.FindOne();
if (result == null)
{
throw new Exception("No …
Run Code Online (Sandbox Code Playgroud) asp.net directoryservices active-directory windows-authentication
我有一个ASP.NET MVC网站,它使用Windows身份验证来控制访问.我希望有一个specflow selenium测试,通过尝试以非授权用户身份访问该站点来检查配置是否正确.
由于我们使用域帐户来控制访问权限,因此没有用户名/密码登录屏幕.浏览器会自动将当前用户的凭据传递给站点.
因此,对于我的Selenium测试,我需要能够以特定用户身份运行Internet Explorer.
我发现了一些关于Windows模拟的文章,我可以在运行测试期间切换到我的测试用户(使用http://support.microsoft.com/kb/306158中的代码).然而,如果我然后创建一个InternetExplorerDriver它使用我的凭据而不是测试用户启动Internet Explorer(尽管这个问题和答案表明它应该工作https://sqa.stackexchange.com/questions/2277/using-selenium-webdriver- with-windows-authentication).
我也可以明确地启动Internet Explorer进程作为我的测试用户,但是我看不到将InternetExplorerDriver绑定到已经运行的Internet Explorer进程的方法,所以这可能是一个死胡同.
我的代码基本上来自上面的MSDN页面.在调试器中,我可以看到WindowsIdentity.GetCurrent().Name在测试的所有步骤中都是"testUser".
namespace MyProject.Specs
{
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using TechTalk.SpecFlow;
[Binding]
public class AuthorisationSteps
{
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;
private static WindowsImpersonationContext impersonationContext;
private static IWebDriver driver;
[BeforeScenario]
public static void impersonateUser()
{
if (!impersonateValidUser("testUser", "testDomain", "password"))
{
throw new Exception();
}
driver = new InternetExplorerDriver();
}
[AfterScenario] …
Run Code Online (Sandbox Code Playgroud) asp.net-mvc selenium windows-authentication specflow selenium-webdriver
我正在尝试在我的ASP.NET应用程序中使用Windows身份验证.每当我尝试查看应用程序时,它都会将我发送到登录页面.如何在不通过浏览器手动登录的情况下使其工作?
<system.web>
<authentication mode="Windows"></authentication>
<anonymousIdentification enabled="false"/>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
<customErrors mode="Off"></customErrors>
<identity impersonate="true"></identity>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime />
</system.web>
Run Code Online (Sandbox Code Playgroud)
Most likely causes:
No authentication protocol (including anonymous) is selected in IIS.
Only integrated authentication is enabled, and a client browser was used that does not support integrated authentication.
Integrated authentication is enabled and the request was sent through a proxy that changed the authentication headers before they reach the Web server. …
Run Code Online (Sandbox Code Playgroud) asp.net ×3
c# ×3
asp.net-mvc ×2
iis-express ×2
java ×2
.net ×1
angularjs ×1
asp.net-core ×1
cors ×1
hibernate ×1
identity ×1
iis ×1
jdbc ×1
selenium ×1
specflow ×1
sql ×1
sql-server ×1