我创建了一个 NuGet 包,并且能够在另一个 .NET 解决方案中成功安装它。但我无法从其他 .NET 解决方案中添加对 NuGet 包的引用。
例如,NuGet 包有一个类,其命名空间类似于MyCorp.SecurityApi. 我目前无法在其他 .NET 解决方案中为该命名空间添加 using 指令。例如,using MyCorp.SecurityApi指令返回此编译错误:
找不到类型或命名空间“MyCorp”
知道问题可能是什么或如何调试吗?
我创建了一个Web Api 2应用程序,该应用程序仅在公司网络上使用。我已经阅读了有关Web API中Windows身份验证的信息,因此这似乎是有可能的。但是我需要找出正确的实现方法。我在Web.config中包含了以下xml:
<system.web>
<authentication mode="Windows" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
我似乎还记得旧式Webforms应用程序中的某种类型的事件挂钩。像BeginRequest()这样的东西,可以在呈现页面之前进行安全检查。我在我的一个控制器方法中将以下代码行作为第一行,但返回的值似乎只是一个空对象,没有任何有意义的信息:
var identity = HttpContext.Current.User.Identity as WindowsIdentity;
Run Code Online (Sandbox Code Playgroud)
Web API 2是否支持Windows身份验证?我错过了一步吗?如果我提交了Postman的一般测试要求,Windows身份验证应该可以工作吗?我也尝试了这段代码,但是得到了一个类似的空对象:
var x = RequestContext.Principal;
Run Code Online (Sandbox Code Playgroud)
我隐约记得一个IIS设置,例如“启用集成安全性”。您能否指定确切的设置?如果我在IIS Express上运行应用程序,是否可以完成此任务?
更新
我遵循了以下答案之一中提到的IIS Express的步骤,但是我在原始帖子中提供的代码示例仍然没有得到填充的用户对象。我还更新了applicationhost.config文件以关闭匿名身份验证:
<anonymousAuthentication enabled="false" userName="" />
Run Code Online (Sandbox Code Playgroud)
更新后,我通过邮递员重新提交了测试请求,但出现以下错误:
<h3>HTTP Error 401.2 - Unauthorized</h3>
<h4>You are not authorized to view this page due to invalid authentication headers.</h4>
</div>
<div class="content-container">
<fieldset>
<h4>Most likely causes:</h4>
<ul>
<li>No authentication protocol (including anonymous) is selected in IIS.</li>
<li>Only integrated authentication is enabled, and a client browser was used that …Run Code Online (Sandbox Code Playgroud) .net c# windows-authentication asp.net-web-api asp.net-web-api2
localhost/swagger 正在按预期加载,但 remoteserver/swagger 出现问题。我可以保存生成的 swagger 文档的离线副本吗?在尝试调试远程问题时,我可以将 zip 文件发送给几个用户。
我正在使用Swashbuckle记录我的Web API 2.2 API。当我加载Swagger页面时,uri会显示一个版本占位符变量,而不是实际版本。例如:
/api/v{version}/authentication
Run Code Online (Sandbox Code Playgroud)
代替:
/api/v2/authentication
Run Code Online (Sandbox Code Playgroud)
如何配置我的应用程序或Swashbuckle以显示版本号而不是版本变量?
根据以下代码,我在主题行中收到错误消息:
var myReport = new List<Tuple<Guid, string, int>>();
myReport.Add(new Tuple<Guid, string, int>(domainId, domainName, domainCount));
Run Code Online (Sandbox Code Playgroud)
domainId、domainName 和 domainCount 都具有预期的数据类型。知道什么可能导致此错误吗?
我正在开发一个 Web API 2 应用程序,并且正在实施请求验证。我已经包含了一个验证检查,如下所示:
if (string.IsNullOrEmpty(userCredentials.UserName))
return BadRequest("UserCredentials.UserName is required");
Run Code Online (Sandbox Code Playgroud)
按预期返回 400 响应代码,但提供的消息似乎未包含在返回给客户端的响应中。我在实施中是否遗漏了某些内容,或者是否需要采用特殊方式来处理客户端收到的响应?
更新
BadRequest 消息返回给 Postman,但是当我通过控制台应用程序使用 C# 调用它时,我无法找到验证消息。这是我在控制台应用程序中使用的代码:
static async Task<User> Authenticate(string domain, string userName, string password)
{
using (var client = GetHttpClient())
{
var encoding = Encoding.GetEncoding("iso-8859-1");
var userName64 = Convert.ToBase64String(encoding.GetBytes(userName));
var password64 = Convert.ToBase64String(encoding.GetBytes(password));
var credentials = new { DomainName = domain, UserName = userName64 /*, Password = password64*/ };
var response = await client.PostAsJsonAsync("api/v1/auth", credentials);
var user = await response.Content.ReadAsAsync<User>();
return user;
//return response.Content.ReadAsAsync<User>();
} …Run Code Online (Sandbox Code Playgroud) 我需要确定两个数据库之间的数据模型差异:DB1和DB2.我需要一种方法来识别丢失/额外的数据库对象和命名差异.是否有为此目的推荐的sproc或免费工具?
我有下面的代码可以从 Active Directory 中检索组。当我只为MY_GROUP_NAME(在下面注释掉)运行代码时,输出符合预期。
当我从 AD 中运行完整的一组组时,最终的数据集是不正确的。一个具体的例子是,我最终在列表中得到了多个具有相同组名但 ParentGroupGuid 不同的 adGroup。这是一个无效的场景。这个问题似乎与Parallel.ForEach()调用下面的递归方法有关。
知道问题可能是什么以及如何解决吗?
private ConcurrentBag<Core.Models.ADGroup> adGroups;
public async Task<List<Core.Models.ADGroup>> GetADGroupsFromADAsync(string domainName)
{
return await Task.Run(async() =>
{
var domainId = await new DomainRepository().GetDomainId(domainName);
using (var context = new PrincipalContext(ContextType.Domain, domainName))
{
var ps = new PrincipalSearcher(new GroupPrincipal(context));
Parallel.ForEach(
ps.FindAll().ToList(),
//ps.FindAll().Where(x => x.Name == "MY_GROUP_NAME").ToList(),
new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount },
async (group, loopState) =>
{
await GetGroupsRecursive((Guid)domainId, null, (GroupPrincipal)group);
});
}
//return group list
return adGroups.ToList();
}); …Run Code Online (Sandbox Code Playgroud) 我在SO上发现了以下评论:
"同样使用async await模式和更新版本的.Net将使效率更接近NodeJS和Nginx等事件驱动架构的效率"
我继承了一个Web API应用程序,基本上所有层中的所有方法都利用了async/await模式.以上关于async/await性能的评论非常引人注目.在Web API应用程序中的所有层的所有方法上实现async/await是否合适?是否有任何情况我应该避免等待/异步或小心不要过度使用它?
.net ×8
c# ×8
swagger ×2
async-await ×1
database ×1
nuget ×1
sql-server ×1
swashbuckle ×1
t-sql ×1