我的业务层中有几个自定义异常,在我的ASP.NET应用程序中冒泡到我的API方法.
目前,它们都转换为Http状态500.如何映射这些自定义异常,以便我可以返回不同的Http状态代码?
我在没有 ASP.NET Identity 的 ASP.NET Core 1.0 中使用 cookie 中间件 - 如本文所述: https ://docs.asp.net/en/latest/security/authentication/cookie.html
当用户对其个人资料进行某些更改时,我需要更改 cookie 中的某些值。在这种情况下,这篇文章告诉我
调用 context.ReplacePrincipal() 并将 context.ShouldRenew 标志设置为 true
我到底该怎么做?我认为这篇文章指的是HttpContext。我在 HttpContext 下没有看到 ReplacePrincipal() 方法。
我希望得到一些帮助。谢谢。
cookies asp.net-mvc asp.net-authentication asp.net-core-mvc asp.net-core-1.0
我将文件存储在云中,因此在上传过程中,它们会得到前缀,从而使它们的名称唯一。例如,如果我上传一个名为的文件test.txt,则在上传过程中该文件将另存为7ea205f01ae5_test.txt。请务必注意,我确实捕获并保存了原始文件名。
在我的React组件中,我试图通过使用download属性使其变得用户友好,以便当用户单击以下载文件时,该文件将被下载为,test.txt但无法正常工作。该文件仍以下载7ea205f01ae5_test.txt。
这就是我的React代码的样子
<a href={fileUrl} download={origName}>{fileName}</a>
Run Code Online (Sandbox Code Playgroud)
我的组件看起来像这样的对象:
{
id: 123,
fileName: "7ea205f01ae5_test.txt",
origName: "test.txt",
fileUrl: "https://myBlobStorageUrl.com/container/7ea205f01ae5_test.txt?signature=123abcxyz"
}
Run Code Online (Sandbox Code Playgroud)
请注意,fileUrl包含一个安全访问签名,该签名允许用户访问文件。没有它,用户将无权访问该文件。
我需要怎么做才能将文件下载为test.txt?
我正在尝试在我的ASP.NET Core 2.0应用程序中实现LinkedIn/OAuth身份验证,我需要将范围设置为{ "r_basicprofile", "r_emailaddress" }以便我可以使用用户的电子邮件,个人资料图像等.
当我尝试在以下代码中设置范围时,我收到以下错误:
无法将属性或索引器"OAuthOptions.Scope"分配给 - 它是只读的.
这是代码:
services.AddOAuth(CookieAuthenticationDefaults.AuthenticationScheme, options => {
options.SignInScheme = "LinkedIn";
options.ClientId = "1234567890";
options.ClientSecret = "1234567890";
options.CallbackPath = "/linkedin-callback";
// Configure the LinkedIn endpoints
options.AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization",
options.TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken",
options.UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,picture-urls::(original))",
options.Scope = { "r_basicprofile", "r_emailaddress" };
options.Events = new OAuthEvents
{
OnCreatingTicket = OnCreatingTicketLinkedInCallBack,
OnTicketReceived = OnTicketReceivedCallback
};
})
Run Code Online (Sandbox Code Playgroud)
知道如何设置范围吗?
PS我试图改编我的ASP.NET Core 1.1中的代码.此代码在ASP.NET Core 1.1应用程序中运行良好.
我正在尝试将 LinkedIn 身份验证添加到我的 ASP.NET Core 2.0 应用程序,但收到以下错误:
没有配置身份验证处理程序来处理该方案:LinkedIn
以下是我在ConfigureServicesin 中添加 LinkedIn/OAuth 身份验证的方法Startup.cs:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie("internal_cookie", options => {
options.AccessDeniedPath = "/Account/Forbidden/";
options.LoginPath = "/Account/Login";
})
.AddCookie("external_cookie")
.AddOAuth("LinkedIn", options => {
options.SignInScheme = "external_cookie";
options.ClientId = "1234567890";
options.ClientSecret = "1234567890";
options.CallbackPath = "/linkedin-callback";
options.AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization";
options.TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
options.UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,picture-urls::(original))";
options.Scope.Add("r_basicprofile");
options.Scope.Add("r_emailaddress");
options.Events = new OAuthEvents
{
OnCreatingTicket = OnCreatingTicketLinkedInCallBack,
OnTicketReceived = OnTicketReceivedCallback
};
})
.AddFacebook(options =>
{
options.AppId = "1234567980";
options.AppSecret = "1234567890";
options.Events = …Run Code Online (Sandbox Code Playgroud) 我试图围绕我们应该如何构建Azure功能.
我喜欢构建响应事件的无服务器,紧凑,单功能应用程序的想法.
以下是我遇到的问题:
此时,我看到的唯一选择是将代码"复制并粘贴"到新的Azure Functions项目中,并在没有任何DI的情况下使用它.
这似乎违背了"最佳做法".那么除了创建单片代码或等到Azure Functions支持.NET Core和DI之外,还有什么解决方案.
我以为我可以使用面向.NET Framework的常规Azure Functions项目中的.NET Standard类库.毕竟,.NET Standard的想法是"标准化"事物.我在SO上开了几个帖子.我正在提供链接,以便您可以看到我遇到的问题:
在WebJob中使用.NET Core 2.0库定向.NET Framework 4.7
使用.NET Core和Ninject的WebJobs中没有无参数构造函数错误
PS我以前的帖子指的是WebJobs.这是B计划的方法,因为在支持.NET Core和DI等事情时,WebJobs似乎比Azure Functions领先半步.最后,我想构建一些可以使用我在.NET Standard 2中构建的类库的Azure函数.
此外,我之前的帖子提到我的类库以.NET Core 2.0为目标.从那时起,我将它们转换为.NET Standard 2,它实际上并没有太多用处.我这样做是为了让我真正符合.NET Standard 2.
什么是在Web API中使用的最佳选项,它将返回结果HTTP status codes和JSON结果?
我一直使用IActionResult它,但它始终是一个带有Web API的Web应用程序.这次它只是Web API.
我有以下简单的方法,给我一个错误,内容如下:
无法将Microsoft.AspNetCore.Mvc.OkObjectResult类型隐式转换为System.Threading.Tasks.Task Microsoft.AspNetCore.Mvc.IActionResult
[HttpGet]
public Task<IActionResult> Get()
{
return Ok();
}
Run Code Online (Sandbox Code Playgroud) asp.net asp.net-web-api .net-core asp.net-core asp.net-core-webapi
诚然,我有基本的了解source maps和webpack.我的理解是,如果我devtools在我的webpack.config.js文件中正确设置,我应该获得映射到原始代码的源映射文件.
我正在使用以下配置文件,我没有得到任何源映射文件.知道为什么吗?
var IS_DEV = false;
var webpack = require('webpack');
var path = require("path");
// Define plugins needed for production and dev cases
var _pluginsDev = [
new webpack.ProvidePlugin({
'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
moment: 'moment',
ps: 'perfect-scrollbar'
}),
];
var _pluginsProd = [
new webpack.ProvidePlugin({
'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
moment: 'moment',
ps: 'perfect-scrollbar'
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: true,
output: { comments: false }
})
]; …Run Code Online (Sandbox Code Playgroud) IHttpClientFactory新的ASP.NET Core 2.1中有一个非常酷的功能,
https://www.hanselman.com/blog/HttpClientFactoryForTypedHttpClientInstancesInASPNETCore21.aspx
我正在尝试在ASP.NET Core 2.1 Preview-2应用程序中使用此功能,但是我需要HttpClient在.NET Standard 2.0中的类库中使用。
有一次,我执行AddHttpClient中ConfigureServices()的Startup.cs,我怎么通过这个HttpClientFactory或命名具体HttpClient到我在.NET 2.0标准类库创建的API客户端?该客户端几乎可以处理我对第三方的所有API调用。
基本上,我只是想将特定的名称添加HttpClient到我的中thirdPartyApiClient。
这是我的代码ConfigureServices():
public void ConfigureServices(IServiceCollection services)
{
// Create HttpClient's
services.AddHttpClient("Api123Client", client =>
{
client.BaseAddress = new Uri("https://api123.com/");
client.DefaultRequestHeaders.Add("Accept", "application/json");
});
services.AddHttpClient("Api4567Client", client =>
{
client.BaseAddress = new Uri("https://api4567.com/");
client.DefaultRequestHeaders.Add("Accept", "application/json");
});
}
Run Code Online (Sandbox Code Playgroud) 我对SignalR. 显然,有什么称呼它如一些争论onClosed(),closed()等等。
在SignalR客户端的侦听器中,我正在尝试实现此事件,但不断收到错误消息,指出它不是函数。我试过onClosed()和closed()。同样的错误。如何检测客户端的关闭事件?
const signalRListener = () => {
connection.on('new_message', message => {
// Handle incoming message.
// This is working fine.
})
connection.closed(e => {
// Try to restart connection but I never get here to due error I'm receiving
})
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
这是我开始连接的方式:
export const signalRStart = (token) => {
connection = new signalR.HubConnectionBuilder()
.withUrl("/chat?access_token=" + token)
.configureLogging(signalR.LogLevel.Information)
.build();
// Set connection time out
connection.serverTimeoutInMilliseconds = …Run Code Online (Sandbox Code Playgroud) asp.net-core ×5
.net-core ×2
oauth ×2
asp.net ×1
asp.net-mvc ×1
azure ×1
c# ×1
cookies ×1
html5 ×1
javascript ×1
reactjs ×1
signalr ×1
source-maps ×1
webpack ×1
webpack-2 ×1