每次运行MSTest时,都会在其中创建一个新的带时间戳的文件夹TestResults.这可能导致许多文件/文件夹占用硬盘空间.
有没有办法配置MSTest来覆盖TestResults文件夹的内容,以便只包含最近运行的结果?
我想使用流行的内存托管策略对WebAPI项目运行测试.
我的测试位于一个单独的项目中.
这是我考试的开始
[TestMethod]
public void TestMethod1()
{
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new {id = RouteParameter.Optional});
HttpServer server = new HttpServer(config);
HttpMessageInvoker client = new HttpMessageInvoker(server)
}
Run Code Online (Sandbox Code Playgroud)
使用HttpServer初始化客户端,建立直接的客户端 - 服务器连接.
除了提供路由配置信息之外,HttpServer如何知道要托管哪个WebAPI项目?
如何同时托管多个WebAPI项目?
似乎HttpServer能够找到WebAPI项目的神奇功能吗?
谢谢
我对使用新的ASP.Net OpenID Connect框架有疑问,同时在身份验证管道中添加新的声明,如下面的代码所示.我不确定幕后会发生多少'魔术'.我认为我的大部分问题都集中在不了解OWIN认证中间件而不是OpenID Connect上.
Q1.我要手动设置HttpContext.Current.User和Thread.CurrentPrincipal自OwinContext.Authentication.User?
Q2.我希望能够像以前一样将对象类型添加到声明中System.IdentityModel.Claims.Claim.新System.Security.Claims.Claim类只接受字符串值?
Q3.我是否需要使用新的SessionSecurityToken包装我ClaimsPrincipal在System.Security.Claims.CurrentPrincipal序列化到一个cookie -我使用的 app.UseCookieAuthentication(new CookieAuthenticationOptions());,但现在肯定在维护期间我添加任何额外的权利要求书,做究竟是什么SecurityTokenValidated事件?
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications()
{
SecurityTokenValidated = (context) =>
{
// retriever caller data from the incoming principal
var UPN = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.Name).Value;
var db = new SOSBIADPEntities();
var user = …Run Code Online (Sandbox Code Playgroud) 我有一个使用Visual Studio 2013的现有ASP.NET MVC应用程序.我遵循了这个演练,但它只关注一个新的绿地项目,同时在项目模板中选择更改身份验证:使用Windows Azure Active Directory开发ASP.NET应用程序
我对使用OWIN和OpenID Connect Katana模块不感兴趣,因为这些组件存在很多问题,所以我等待该技术成熟并解决所有当前问题.
我的目标是了解如何手动将所有组件和配置添加到我现有的ASP.NET MVC应用程序,以在Rick Anderson的文章中实现相同的Azure AD身份验证模型.
在这个例子中,我有一个动态绑定输入和div到相同的属性.但是在改变输入中的文本时,更改不会反映在div元素中.
http://jsfiddle.net/rpuri/Bcps5/
ko.applyBindingsToNode(document.getElementById('input-health'), {
value: vm.status(),
valueUpdate: 'afterkeydown'
});
Run Code Online (Sandbox Code Playgroud)
声明性绑定对我来说不是一个选项,因为我需要绑定到部分视图中的共享元素(ASP.NET MVC).
谢谢
我使用OWIN Middleware在我的ASP.NET MVC应用程序中设置了OpenID Connect身份验证.
正如此Fiddler输出所示,一旦通过Azure OpenID Connect成功登录,浏览器就会不断在我的site.azurewebsites.net和login.windows.net之间来回循环.

我确保以下密钥正确匹配Azure AD信息
<add key="ida:AADInstance" value="https://login.windows.net/{0}" />
<add key="ida:Tenant" value="******.onmicrosoft.com" />
<add key="ida:ClientId" value="*******" />
<add key="ida:PostLogoutRedirectUri" value="*********" />
Run Code Online (Sandbox Code Playgroud)
我的Start.cs代码如下
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
private string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
IAuthorizationService authorizationService = new AuthorizationService();
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
ExpireTimeSpan =TimeSpan.FromMinutes(15)
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = …Run Code Online (Sandbox Code Playgroud) 我的目标是实现Azure Traffic Manager以便我们的网站及其数据库进行故障转移.
为实现这一目标,我在不同的数据中心部署了两个相同的Sql Azure数据库.
该数据库展示了450个表,4000列,约800万条记录,3GB大小并经常写入.
我最初的关注除了效率和成本之外,无论是双向还是单向,都是设置Sql Data Sync所需的时间,架构发展时的维护开销以及同步失败时调试复杂架构.还有一个问题是Sql Data Sync仍处于预览状态.
我关注的是脱离了由Traffic Manager管理的全自动故障转移解决方案.
在我构建的MVC应用程序类型中存在固有的设计缺陷,我相信我不是第一个意识到的.
我有一个MVC 4应用程序,它使用以下列方式引入应用程序的AD Azure身份验证
使用Azure Active Directory开发ASP.NET应用程序
一旦用户经过身份验证并Home.cshtml加载,KnockoutJs就会用于执行JavaScript AJAX POST和GET请求以读取和写入数据.
所以不完全是单页应用程序,而是通过AJAX混合使用身份验证和服务资产以及读/写操作的传统回发.
在AJAX请求期间,身份验证令牌过期,AD无法通过JavaScript刷新令牌.
观察到以下浏览器错误
XMLHttpRequest无法加载https://login.windows.net/xxx.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此不允许原点'xxx'访问.
我已经研究过adal.js和以下帖子,但不确定adal.js是否是我的应用程序类型的解决方案,或者如何最好地将其合并以使其适用于我的应用程序类型.
到目前为止我的理解:
我没有使用AngularJS.
我没有开始通过JavaScript进行身份验证,而我的身份验证不是JavaScript驱动的,无法从adal.js中受益.
身份验证在服务器端完成,后续OAuth2刷新令牌机制需要完整页面回发.
我偶然发现了维托里奥·贝尔托奇(Vittorio Bertocci)的各种相关帖子,但都没有提到这种类型的MVC应用程序设计的特殊性.
asp.net-mvc-4 knockout.js azure-web-sites azure-active-directory adal.js
我想从Azure AD检索用户的组信息。
使用以下Graph API软件包来实现此目的
我能够从Azure Graph API成功检索用户信息。
但是,当我运行此方法以检索用户的组时,Fiddler会显示一个成功的HTTP 200响应,其中包含包含组信息的JSON片段,但是该方法本身不会返回IEnumerable。
IEnumerable<string> groups = user.GetMemberGroupsAsync(false).Result.ToList();
Run Code Online (Sandbox Code Playgroud)
该代码似乎未从此异步请求返回。
当身份验证管道卡住时,最终的体验是空白页。
完整代码
public override ClaimsPrincipal Authenticate(string resourceName, ClaimsPrincipal incomingPrincipal)
{
if (!incomingPrincipal.Identity.IsAuthenticated == true &&
_authorizationService.IdentityRegistered(incomingPrincipal.Identity.Name))
{
return base.Authenticate(resourceName, incomingPrincipal);
}
_authorizationService.AddClaimsToIdentity(((ClaimsIdentity) incomingPrincipal.Identity));
Claim tenantClaim = incomingPrincipal.FindFirst(TenantIdClaim);
if (tenantClaim == null)
{
throw new NotSupportedException("Tenant claim not available, role authentication is not supported");
}
string tenantId = tenantClaim.Value;
string authority = String.Format(CultureInfo.InvariantCulture, _aadInstance, _tenant);
Uri servicePointUri = new Uri("https://graph.windows.net");
ClientCredential clientCredential = new …Run Code Online (Sandbox Code Playgroud) Azure API 管理如何帮助我管理不同版本的 API 并将所选操作从旧版本的 API 重新路由到新版本的 API?
此处显示的代码是我尝试在 ASP.NET Core 2.0 中针对我的 Azure AD 租户执行身份验证。
有趣的部分是我收到身份验证代码后的下一组目标。
我想将经过身份验证的用户的 AD 组放入声明中,并将它们传递给我的基于策略的授权注册。
为了实现这一点,我交换了访问令牌的授权代码。
获得访问令牌后,我使用 Microsoft Graph SDK 来检索经过身份验证的用户的 AD 组。
问题 1:我见过访问令牌存储在缓存中的示例IDistributedCache。为什么这很重要,不执行此步骤有什么风险,究竟是AdalDistributedTokenCache什么?
例如
var cache = new AdalDistributedTokenCache(distributedCache, userId);
var authContext = new AuthenticationContext(ctx.Options.Authority, cache);
Run Code Online (Sandbox Code Playgroud)
我发现访问令牌总是通过
string accessToken = await HttpContext.GetTokenAsync("access_token");
Run Code Online (Sandbox Code Playgroud)
问题 2:检索组后,如果我将这些作为声明添加到 Principal 中,那么我是否可以使用它们来驱动此处所述的授权策略?
问题 3:访问令牌和 id 令牌以及我添加的声明最终会出现在 cookie 中吗?
问题 4:如何强制 Azure AD 将 AD 角色作为声明返回(而不是组,因为我可以通过 Graph 获取这些角色)而不必更改某种清单?
完整代码
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme …Run Code Online (Sandbox Code Playgroud) asp.net-identity azure-active-directory openid-connect azure-ad-graph-api asp.net-core
azure ×4
asp.net-mvc ×3
asp.net ×2
c# ×2
knockout.js ×2
owin ×2
adal.js ×1
adfs ×1
asp.net-core ×1
mstest ×1
oauth-2.0 ×1
openid ×1
sql-server ×1