我使用此代码根据xUnit 测试项目中的环境加载设置:
public class TestSettings
{
public string AzureConnectionString { get; }
public TestSettings(ITestOutputHelper output)
{
string envVariable = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
output.WriteLine($"env: '{envVariable}'");
IConfigurationRoot config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{envVariable}.json", optional: true)
.Build();
AzureConnectionString = config.GetConnectionString("AzureStorage");
}
}
Run Code Online (Sandbox Code Playgroud)
但无论我做什么,我都会感到envVariable空虚。我在哪里可以设置ASPNETCORE_ENVIRONMENT测试项目(VS2017)?
致 ASP.NET Core 工具团队
请使测试项目设置适用于环境。谢谢。
我试图在我的ASP.NET Core 2.0 Web应用程序中使用此示例RazorViewEngineEmailTemplates从View创建一个html电子邮件正文.但是当我运行它并且我的控制器获得ajax请求时,我收到此错误:
无法从根提供程序解析范围服务Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.IViewBufferScope
它可能来自解析RazorViewToStringRenderer类中的依赖项,但我不知道如何解决这个问题.
尝试了多个 OIDC 身份验证库后,我的 Angular 应用程序仍然没有成功。我总是收到此错误:
从源“ https://192.168.3.2:4200 ”访问“https://{tenant}.b2clogin.com/{tenant-GUID}/v2.0/.well-known/openid-configuration”处的 XMLHttpRequest已已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。
有没有办法设置CORS?
有任何想法吗?
这是我与ASP.NET Core 1.1 Url Rewrite中间件一起使用以从www重定向的核心。到非www:
var options = new RewriteOptions()
.AddRedirect("^(www\\.)(.*)$", "$2");
app.UseRewriter(options);
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它不起作用。我知道正则表达式是正确的。怎么了
这是完整的Configure功能:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseRequestLocalization(new RequestLocalizationOptions() { DefaultRequestCulture = new RequestCulture("ru-ru") });
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
// URL Rewriting
var options = new RewriteOptions()
//.AddRedirect(@"^(https?:\/\/)(www\.)(.*)$", "$1$3");
.AddRedirect("^(www\\.)(.*)$", "$2");
app.UseRewriter(options);
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{action=Index}/{id?}",
defaults: new { controller = "Home" }
);
});
}
Run Code Online (Sandbox Code Playgroud) 我在我的 ASP.NET Core Web 应用程序中启动并运行了 Azure AD B2C。但我想知道新用户注册时真正批准他们的最佳方式是什么?有内置的东西吗?
现在,任何人都可以单击“注册”链接,然后提供数据并单击按钮。您位于我的租户 Azure AD B2C 目录中!现在,我想对此进行一些控制。
我是否提到过,当您想要自定义 Azure AD UI 时,每个用户的费用为 1 美元/月???(据我理解,如有错误,请指正)。因此,如果有人去注册 1000 个用户,我就必须支付 1000 美元?
我的ASP.NET Core 2.0 MVC应用程序的VSTS版本失败并出现以下警告:
警告MSB3245:无法解析此引用.无法找到程序集"Microsoft.AspNetCore.Mvc.ViewFeatures".警告MSB3245:无法解析此引用.无法找到程序集"Microsoft.Extensions.Logging.Abstractions".检查以确保磁盘上存在程序集.如果您的代码需要此引用,则可能会出现编译错误.警告MSB3245:无法解析此引用.找不到程序集"System.Data.SqlClient".检查以确保磁盘上存在程序集.如果您的代码需要此引用,则可能会出现编译错误.
然后我得到像这样的编译错误:
命名空间"Microsoft"中不存在类型或命名空间名称"Extensions"(您是否缺少程序集引用?)
错误CS0246:找不到类型或命名空间名称"ILogger"(您是否缺少using指令或程序集引用?)
等等,对于ILoggerFactory,SqlDataReader等.一切都在我的本地机器上完美构建.我错过了什么?
如何在ASP.NET Core 1.1应用程序中禁用客户端表单验证?但是我需要服务器端的。
我需要IDistributedCache在我的应用程序中使用它,它可以是MemoryDistributedCache或RedisCache作为底层实现。我的理解是这些不是线程安全的,所以我使用ReaderWriterLockSlim.
ReaderWriterLockSlim允许多个线程进行读取或独占访问进行写入。现在我想知道它是否适合这项工作,MemoryDistributedCache以及RedisCache阅读方法是否是线程安全的。
至于整体解决方案 - 我知道从像 Redis 这样的分布式缓存中存储和读取值需要时间。但我没有太多选择,因为我存储的值获取和管理的速度更慢。
这是片段:
...
public async Task<byte[]> GetAsync(string key, CancellationToken token = new CancellationToken())
{
_cacheLock.EnterReadLock();
try
{
return await _cache.GetAsync(GetCacheKey(key), token);
}
finally
{
_cacheLock.ExitReadLock();
}
}
public async Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token = new CancellationToken())
{
_cacheLock.EnterWriteLock();
try
{
await _cache.SetAsync(GetCacheKey(key), value, options, token);
}
finally
{
_cacheLock.ExitWriteLock();
}
}
public async Task RemoveAsync(string key, …Run Code Online (Sandbox Code Playgroud) 我一直运行的功能最近停止工作了。所以我开始看看有什么变化,在VS2017中本地加载解决方案并进行编译。一切似乎都在编译,但是当我在本地运行时,我得到:
错误索引方法'CheckNewBlob.Run'Microsoft.Azure.WebJobs.Host:错误索引方法'CheckNewBlob.Run'。System.Private.CoreLib:无法从程序集“ Microsoft.Azure.WebJobs”中加载类型“ Microsoft.Azure.WebJobs.BlobTriggerAttribute”,版本= 3.0.0.0,文化=中性,PublicKeyToken =空
好的,我尝试注册绑定并尝试安装最新的Azure.WebJobs.Core(无论如何)包-祝您好运!它只是不再编译了!我什至试图重新创建该项目,这很浪费时间。功能未损坏。甚至还没有到达表存储输出...
那么,Azure职能团队,我们应该怎么做?
可以说现有功能不再由新的blob触发。它过去只在昨天工作,但仅此而已。
Azure Functions核心工具(2.0.1-beta.36)函数运行时版本:2.0.12050.0
我有这个路由设置:
const SONGS_ROUTES = [
{
path: "songs",
children: [
// ...
{
path: "edit/:id",
component: PerformancesComponent, // CHILD ROUTE
},
{
path: "",
component: PerformancesComponent,
},
],
},
];
const routes: Routes = [
{
path: "",
component: ConcertsComponent,
children: [
{
path: "edit/:friendlyUrl",
component: ConcertEditComponent, // PARENT route
children: SONGS_ROUTES,
},
],
},
];
Run Code Online (Sandbox Code Playgroud)
我需要能够friendlyUrl在树中的每个组件中使用 ngrx 选择器。所以我定义如下:
export const routerFeatureKey = "router";
export const selectRouterState = createFeatureSelector<
fromRouter.RouterReducerState
>(routerFeatureKey);
export const {
selectCurrentRoute, // select the …Run Code Online (Sandbox Code Playgroud) 我在面向Internet(PubWeb)的Azure中有一个Web API应用程序,因此可以在任何地方使用它.我创建了一个Web API(再次,在Azure中,我们称之为InWeb).我想要强有力的安全规则:
那么2的最佳解决方案是什么?
更新 - 这里是InWeb Core 2.0 Auth设置:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddAzureAdBearer(options => Configuration.Bind("AzureAd", options));
services.AddMvc(options => { options.InputFormatters.Add(new TextPlainInputFormatter()); });
}
Run Code Online (Sandbox Code Playgroud) c# azure azure-web-sites azure-active-directory asp.net-core-2.0
我有一个用 Angular 11.2.7 和 Angular Material 制作的简单注册表单。这是堆栈闪电战。
我将密码字段的可见性更改为最后 3 秒,然后它们的状态更改回“密码”。因此,当用户单击任何密码控件中的“眼睛”时,密码文本将以明文显示,然后在 3 秒内变回点。
但问题是,此状态更改会触发整个表单验证,并且所有无效的内容都会看起来“无效”(呈红色)。谁能告诉我为什么吗?
另外,我必须对我的 Observables 使用多播,但我可能做得不对。我不知道。
好的,我已经使用 ARM 模板完成了此处描述的所有操作 - https://azure.microsoft.com/en-us/documentation/articles/web-sites-integrate-with-vnet。除了一件事 - 启用与预先存在的 VNET 的 VNET 集成。
这可以在 ARM 模板中完成吗?谢谢!
asp.net-core ×4
azure ×4
c# ×4
.net-core ×2
angular ×2
azure-ad-b2c ×2
azure-devops ×1
caching ×1
cors ×1
ngrx ×1
ngrx-store ×1
rxjs ×1
rxjs6 ×1
testing ×1
validation ×1
xunit ×1