React文档声明应该从componentDidMount生命周期事件启动ajax请求 (请参阅react docs).
为什么这个活动?
在大多数情况下,当使用ajax加载数据时,我想显示某种加载条,例如:
componentDidMount() {
this.setState({isLoading: true});
fetch(...)
.then(...)
.then(() => this.setState({isLoading: false})
}
Run Code Online (Sandbox Code Playgroud)
但是这会激发render方法3次(初始渲染isLoading = true,然后立即设置,然后按isLoading = false
从componentWillMount事件发送ajax请求有什么问题?
在 Startup.ConfigureServices() 我配置授权过滤器是这样的:
services.AddMvc(options =>
{
options.Filters.Add(new AuthorizeFilter(myAuthorizationPolicy));
})
Run Code Online (Sandbox Code Playgroud)
我使用基于配置的 cookie 身份验证或 AAD 身份验证:
if (useCookieAuth)
{
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie();
}
else
{
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("Authentication:AzureAd", options));
}
Run Code Online (Sandbox Code Playgroud)
现在,当我访问一个页面并myAuthorizationPolicy失败时,我被重定向到“Account/AccessDenied?ReturnUrl=%2F”,但我想返回 403。
在Visual Studio代码的GIT选项卡上有一个上下文菜单,其中包含以下项目:
==================
==================
...
发布按钮有什么作用?
Application Insight配置存在一些混淆.它可以使用Visual Studio在应用程序本身中配置,也可以在使用Azure Portal的App Service中配置.
当我使用Visual Studio 将Application Insights遥测添加到我的asp.net core 2.0网站时,它将以下配置添加到appsettings.json:
{
// Changes to file post adding Application Insights Telemetry:
"ApplicationInsights": {
"InstrumentationKey": "10101010-1010-1010-1010-101010101010"
}
}
Run Code Online (Sandbox Code Playgroud)
然后我在startup.cs中配置AppInsights服务,如下所示:
var instrumentationKey= Configuration.GetSection("ApplicationInsights:InstrumentationKey").Value;
services.AddApplicationInsightsTelemetry(opt => opt.InstrumentationKey = instrumentationKey);
Run Code Online (Sandbox Code Playgroud)
但是,当我在Azure门户中的App Service中打开Application Insights选项卡时,它仍建议连接Application Insight.然后,向导会向配置添加新的Intrumentation Key:
仅使用APPINSIGHTS_INSTRUMENTATIONKEY有什么副作用(例如在Visual Studio工具中).我的意思是我会在startup.cs中写:
var instrumentationKey= Configuration.GetSection("APPINSIGHTS_INSTRUMENTATIONKEY ").Value;
services.AddApplicationInsightsTelemetry(opt => opt.InstrumentationKey = instrumentationKey);
Run Code Online (Sandbox Code Playgroud)我根据Tseng的回答得出结论,最好在Azure门户和appsettings.json中使用APPINSIGHTS_INSTRUMENTATIONKEY.
ASP.NET核心既了解APPINSIGHTS_INSTRUMENTATIONKEY和ApplicationInsights:InstrumentationKey,但Azure的门户网站只有第一个,它必须是环境变量.如果您使用了第二个,并尝试从代码中的某个位置的config中读取它,您可以轻松地在Azure门户和在Azure中运行的应用程序中使用不同的值.
此外,如果您从配置中手动读取检测键,则应首先查看APPINSIGHTS_INSTRUMENTATIONKEY然后ApplicationInsights:InstrumentationKey:
var instrumentationKey= Configuration.GetSection("APPINSIGHTS_INSTRUMENTATIONKEY")?.Value
?? Configuration.GetSection("ApplicationInsights:InstrumentationKey")?.Value;
Run Code Online (Sandbox Code Playgroud)
因为那是多么services.AddApplicationInsightsTelemetry(Configuration);有效.以防万一Azure …
visual-studio azure-web-sites azure-application-insights asp.net-core
我要包装这个:
<textarea asp-for="@Model.Content" ...>
Run Code Online (Sandbox Code Playgroud)
到可重用的ViewComponent,其中属性将是参数:
<vc:editor asp-for="@Model.Content" />
Run Code Online (Sandbox Code Playgroud)
我能够将asp-for参数传递给viewcomponent:
public class EditorViewComponent : ViewComponent
{
public IViewComponentResult Invoke(ModelExpression aspFor = null)
{
//when debugging, aspFor has correct value
return View(aspFor);
}
}
Run Code Online (Sandbox Code Playgroud)
但我无法在组件的视图中评估它.这不起作用:
<!-- ViewComponents/Editor/Default.cshtml -->
@model Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression
<textarea asp-for="@Model" />
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在使用Visual Studio 2012,一个SQL数据库项目和对该数据库运行数据库分析,它引发了以下警告:
WITH CHECK | NOCHECK OPTION FOR EXISTING DATA CHECK ENFORCEMENT IS IGNORED.
我对错误的理解是,在运行脚本时,现有数据将忽略CHECK和NOCHECK约束(在每种情况下对我来说都是如此ALTER TABLE).
因此,我的问题是,为什么忽略检查约束?
似乎警告ID已经改变,因此我将两者都包括在内,以便将来可以轻松搜索.
在Visual Studio 2010中,此警告ID为:SQL03159
在Visual Studio 2012中,其警告ID为:SQL70588
ALTER TABLE [dbo].[MyTable] CHECK CONSTRAINT [FK_MyTable_SomeCol]
sql-server static-analysis database-project compiler-warnings visual-studio
我已经在我的ASP.NET Core 2.0 wep应用程序中添加了OpenID身份验证:
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(option =>
{
option.ClientId = Configuration["AzureAD:ClientId"];
option.Authority = String.Format(Configuration["AzureAd:AadInstance"], Configuration["AzureAd:Tenant"]);
option.SignedOutRedirectUri = Configuration["AzureAd:PostLogoutRedirectUri"];
});
Run Code Online (Sandbox Code Playgroud)
如何打开自动质询,所以控制器,使用AuthorizeAttribute的resp操作将返回403而不是重定向?
编辑: 我最终得到了这个:
.AddOpenIdConnect(option =>
{
...
option.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProvider = context =>
{
bool isAjaxRequest = context.HttpContext.Request.Headers["x-requested-with"] == "XMLHttpRequest";
if (isAjaxRequest)
{
context.HttpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
//context.HttpContext.Response.Headers["Location"] = ???request.RedirectUrl;
context.HandleResponse();
}
return Task.CompletedTask;
}
};
});
Run Code Online (Sandbox Code Playgroud)
虽然我不想重定向Ajax请求(因为为什么?),但我想将重定向url传递给客户端.如何获得RedirectURL?
c# authorization openid-connect asp.net-core asp.net-core-2.0
我有一个简单的 ASP.NET Core 2.2 Web Api 控制器:
[ApiVersion("1.0")]
[Route("api/[controller]")]
[ApiController]
public class TestScenariosController : Controller
{
[HttpGet("v2")]
public ActionResult<List<TestScenarioItem>> GetAll()
{
var entities = _dbContext.TestScenarios.AsNoTracking().Select(e => new TestScenarioItem
{
Id = e.Id,
Name = e.Name,
Description = e.Description,
}).ToList();
return entities;
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用@angular/common/http以下命令从 angular 应用程序查询此操作时:
this.http.get<TestScenarioItem[]>(`${this.baseUrl}/api/TestScenarios/v2`);
Run Code Online (Sandbox Code Playgroud)
在 IE11 中,我只得到缓存的结果。
如何禁用所有 web api 响应的缓存?
我正在尝试在visual studio中设置TypeScript HTML应用程序.我想使用reactjs v0.14.7
我想避免使用像Browserify这样的工具.
但是,如何使用该react-dom模块呢?
让我们暂时忘掉打字稿.我需要首先启动并运行纯ES5.
目前,我有这个:
<script src="Scripts/react/react.js"></script>
<script src="Scripts/react/react-dom.js"></script>
<script>
var Button = React.createClass({
render: function () {
return (React.createElement("div", { className: "btn btn-default" }, 'hello world'));
}
});
ReactDOM.render(React.createElement('Button'), document.getElementById('container'));
</script>
Run Code Online (Sandbox Code Playgroud)
但是,浏览器抱怨,ReactDOM对象不存在.
我试过了:
<script src="Scripts/require.js"></script>
<script src="Scripts/react/react.js"></script>
<script src="Scripts/react/react-dom.js"></script>
<script>
var React = require('react');
var ReactDOM = require('react-dom');
....
</script>
Run Code Online (Sandbox Code Playgroud)
但是,它不适用于require.js:模块名称"react"尚未加载上下文:_.使用require([])
有人可以为此带来更多的光吗?如何使用反应没有任何服务器端工具,如捆绑,转换等.
像"使用npm"这样的答案将不被接受为答案.
我有启动cs,我在这里注册AuthenticationMiddleware:
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
AddAuthentication(app);
app.UseMvcWithDefaultRoute();
app.UseStaticFiles();
}
protected virtual void AddAuthentication(IApplicationBuilder app)
{
app.UseAuthentication();
}
}
Run Code Online (Sandbox Code Playgroud)
我用它来测试它:
WebApplicationFactory<Startup>().CreateClient();
Run Code Online (Sandbox Code Playgroud)
我想换成app.UseAuthentication();用app.UseMiddleware<TestingAuthenticationMiddleware>(),
我想过在我的测试项目中继承Startup:
public class TestStartup : Startup
{
protected override void AddAuthentication(IApplicationBuilder app)
{
app.UseMiddleware<AuthenticatedTestRequestMiddleware>();
}
}
class TestWebApplicationFactory : WebApplicationFactory<Web.Startup>
{
protected override IWebHostBuilder CreateWebHostBuilder()
{
return WebHost.CreateDefaultBuilder()
.UseStartup<IntegrationTestProject.TestStartup>();
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为TestStartup在另一个程序集中,它有很多副作用 WebHost.CreateDefaultBuilder()
我越来越:
System.ArgumentException:内容根"C:\ Projects\Liero\myproject\tests\IntegrationTests"不存在.参数名称:contentRootPath
asp.net-core ×6
c# ×5
reactjs ×2
caching ×1
commonjs ×1
git ×1
http-caching ×1
javascript ×1
mstest ×1
sql-server ×1
typescript ×1