我的设置:
只是尝试运行默认的角度模板:
> npm install -g @angular/cli # this installed the angular version mentioned above
> ng new test # Chose default options for the project
> cd test
> npm ci # lots of error messages
Run Code Online (Sandbox Code Playgroud)
最后一个命令会导致输出中出现很多错误(但不会使命令失败):
> fsevents@1.2.11 install C:\test\node_modules\@angular\compiler-cli\node_modules\fsevents
> node-gyp rebuild
C:\test\node_modules\@angular\compiler-cli\node_modules\fsevents>if not defined npm_config_node_gyp (node "C:\Users\foo\AppData\Roaming\nvm\v12.14.1\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users\foo\AppData\Roaming\nvm\v12.14.1\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find Python
gyp …Run Code Online (Sandbox Code Playgroud) 我们最近将一个API应用程序从Azure云服务迁移到Azure网站,一些客户端仍在使用我们的旧协议进行身份验证,该协议使用cookie(而不是通常的Authorization: BearerHTTP标头).我们需要支持此身份验证协议一段时间,因为客户端无法立即迁移.
为了支持针对API的跨源ajax请求中的cookie,客户端需要将设置withCredentials设置为trueXMLHttpRequest,并且服务器需要使用Access-Control-Allow-Credentials标头以及任何CORS请求进行响应.
我们面临的问题是Azure网站自己管理CORS,并使用自己的配置(限于允许的来源列表)作为响应,这不允许设置此标头...从而打破了申请我们所有的Ajax客户端!
有没有办法(临时)在响应中添加此标头?
我正在尝试实现一个 JSON 序列化机制,它处理nullJSON 值和丢失的 JSON 值,以便能够在需要时执行部分更新(这样当值丢失时它不会触及数据库中的字段,但它会在该值显式设置为null)。
我创建了一个从 RoslynOptional<T>类型复制的自定义结构:
public readonly struct Optional<T>
{
public Optional(T value)
{
this.HasValue = true;
this.Value = value;
}
public bool HasValue { get; }
public T Value { get; }
public static implicit operator Optional<T>(T value) => new Optional<T>(value);
public override string ToString() => this.HasValue ? (this.Value?.ToString() ?? "null") : "unspecified";
}
Run Code Online (Sandbox Code Playgroud)
现在我希望能够对 JSON 进行序列化/反序列化,以便在通过Optional<T>对象往返时保留 JSON 中的任何缺失字段:
public class CustomType
{
[JsonPropertyName("foo")]
public Optional<int?> Foo { …Run Code Online (Sandbox Code Playgroud) 我正在尝试覆盖默认的"具有该用户名的用户已存在".在我的自定义UserChangeForm表单中输入现有用户名时显示的错误消息.使用的Django版本:1.6.1
这是我的代码:
class CustomUserChangeForm(forms.ModelForm):
username = forms.RegexField(
label="User name", max_length=30, regex=r"^[\w.@+-]+$",
error_messages={
'invalid': ("My message for invalid"),
'unique': ("My message for unique") # <- THIS
}
)
class Meta:
model = get_user_model()
fields = ('username', 'first_name', 'last_name', 'email',)
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用此代码输入现有用户名,我仍然会获得默认"具有该用户名的用户已存在".信息.请注意,输入错误的用户名(包含无效字符)时会显示自定义"我的无效邮件".
我想使用HTTP PUT动词公开ASP.Net Web Api 2动作来上传文件.这与我们的REST模型一致,因为API代表一个远程文件系统(类似于WebDAV,但实际上是简化的),因此客户端选择资源名称(因此PUT是理想的,POST不是一个合理的选择).
Web Api文档描述了如何使用multipart/form-data表单上载文件,但没有描述如何使用PUT方法进行上传.
您将使用什么来测试这样的API(HTML多部分表单不允许PUT动词)?服务器实现是否类似于web api文档中描述的多部分实现(使用MultipartStreamProvider),或者应该如下所示:
[HttpPut]
public async Task<HttpResponseMessage> PutFile(string resourcePath)
{
Stream fileContent = await this.Request.Content.ReadAsStreamAsync();
bool isNew = await this._storageManager.UploadFile(resourcePath, fileContent);
if (isNew)
{
return this.Request.CreateResponse(HttpStatusCode.Created);
}
else
{
return this.Request.CreateResponse(HttpStatusCode.OK);
}
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的Web API应用程序(Visual Studio中的空模板,启用了Web API),添加了一个控制器:
[RoutePrefix("api/test")]
public class TestController : ApiController
{
[HttpGet]
[Route(@"resource/{*path?}")]
public async Task<HttpResponseMessage> GetFolder(string path = "")
{
return this.Request.CreateResponse(HttpStatusCode.OK, new { Status = "OK" });
}
}
Run Code Online (Sandbox Code Playgroud)
现在我们需要file.pdf在path变量中支持文件扩展名(例如),所以我修改了web.config:
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<!-- API must handle all file names -->
<add name="ApiUrlHandler" path="/api/test/*" verb="GET,POST,PUT,DELETE,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
现在的问题是HTTP状态代码是不一致的,具体取决于前缀后提供的URL段/api/test/:
GET /api/test/resource => HTTP 200 (as …Run Code Online (Sandbox Code Playgroud) 我有一个使用 SMS REST API 的服务HttpClient:
HttpClient http = this._httpClientFactory.CreateClient();
// Skipped: setup HttpRequestMessage
using (HttpResponseMessage response = await http.SendAsync(request))
{
try
{
_ = response.EnsureSuccessStatusCode();
}
catch (HttpRequestException)
{
string responseString = await response.Content.ReadAsStringAsync(); // Fails with ObjectDisposedException
this._logger.LogInformation(
"Received invalid HTTP response status '{0}' from SMS API. Response content was {1}.",
(int)response.StatusCode,
responseString
);
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
API 返回错误,但我希望能够记录它。因此,我需要记录失败的状态代码(我可以从中读取response.StatusCode)和相关内容(其中可能包含其他有用的错误详细信息)。
此代码在await response.Content.ReadAsStringAsync()此异常的指令上失败:
System.ObjectDisposedException:无法访问已处理的对象。
对象名称:'System.Net.Http.HttpConnection+HttpConnectionResponseContent'。
模块“System.Net.Http.HttpContent”,在 CheckDisposed
模块“System.Net.Http.HttpContent”,在 ReadAsStringAsync
一些消息来源建议,当状态码不在成功范围(200-299)内时,您不应读取响应内容,但如果响应确实包含有用的错误详细信息呢?
使用的 .NET 版本:AWS lambda linux …
我有一个由多个模块组成的单页AngularJS应用程序,其目的是为用户提供协作板(主要小部件)和其他相关小部件(其他连接用户,pad元数据等).
我选择拆分应用程序如下:
让我们通过假设我只有一个小部件来简化这一点,小部件的唯一目标是向用户显示状态消息:"authenticating","authenticated","error"或"ready".
我选择在服务中使用订阅/通知模式,以通知窗口小部件共享组件状态的更改.
服务:
angular.module("app.core").factory("padService", padService);
function padService() {
// Callback registration and notification code omitted
return {
initialize: function (authToken) { ... },
onAuthenticated: function (callback) { ... },
onReady: function (callback) { ... },
onError: function (callback) { ... }
};
}
Run Code Online (Sandbox Code Playgroud)
小部件:
angular.module("app.widget").directive("widget", widget);
function widget() {
return {
templateUrl: 'app/widget.html',
restrict: 'E',
controller: widgetController
};
}
function widgetController($scope, padService) {
$scope.message = "authenticating";
padService.onAuthenticated(function (user) {
$scope.message = "authenticated";
// Do other …Run Code Online (Sandbox Code Playgroud) 我们希望将ASP.NET MVC应用程序从Azure Cloud Service切换到Azure App Service(Web应用程序).该应用程序当前正在使用WIF作为其身份框架,并且当它在服务器场配置中运行时,我们配置了一个SessionSecurityTokenHandler使用证书加密会话cookie 的自定义(因此,cookie可以由Web场的所有实例解密).
我们可以使用csdef/cscfg文件和与Cloud Service关联的内置Azure证书存储在Cloud Service方案中配置此证书,但Azure App Services没有这样的功能(除非我遗漏了一些内容).
有没有办法在App Service中配置证书?我们是否应该回退到另一种加密会话cookie的机制,例如共享机器密钥?机器密钥不是理想的解决方案,因为它迫使我们将某些配置从源代码控制中移除以避免泄漏密钥.
我试图让我的基于类的装饰器保持repr()原始包装函数的行为(以匹配functools.wraps装饰器在函数上的工作方式).我正在使用python 3.3.
首先我尝试了functools:
import functools
class ClassBasedDecorator():
def __init__(self, fn):
self.fn = fn
functools.update_wrapper(self, fn)
def __call__(self, *args, **kwargs):
self.fn(*args, **kwargs)
@ClassBasedDecorator
def wrapped(text):
pass
Run Code Online (Sandbox Code Playgroud)
但是当我调用repr()装饰函数时,我得到:
>>> repr(wrapped)
'<__main__.ClassBasedDecorator object at 0x2d8860b6850>'
Run Code Online (Sandbox Code Playgroud)
很好,所以我试着自定义__repr__我的装饰器的方法,它应该被调用repr().
再次使用functools:
class ClassBasedDecorator():
def __init__(self, fn):
self.fn = fn
functools.update_wrapper(
self, fn,
assigned=functools.WRAPPER_ASSIGNMENTS + ('__repr__',)
)
def __call__(self, *args, **kwargs):
self.fn(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
不会改变输出,但会发生一些有趣的事情:
>>> repr(wrapped)
'<__main__.ClassBasedDecorator object at 0x2d8860b69d0>'
>>> wrapped.__repr__()
'<function wrapped at 0x2d8860a9710>'
Run Code Online (Sandbox Code Playgroud)
显式设置__repr__ …