我通过以下配置自我托管WebApi:
Visual Studio 2012/.NET 4.0
public void Configuration(IAppBuilder appBuilder)
{
var config = new HttpConfiguration();
// authentication
config.MessageHandlers.Add(new Shield.PresharedKeyAuthorizer());
// routing
config.Routes.MapHttpRoute(
name: "Default",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
}
Run Code Online (Sandbox Code Playgroud)
我有一个简单的测试设置,使用以下内容DelegatingHandler创建声明并将其附加到当前线程.
public class PresharedKeyAuthorizer : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, "superstar"));
var identity = new ClaimsIdentity(claims, "PresharedKey");
var principal = new ClaimsPrincipal(identity);
Thread.CurrentPrincipal = principal;
if (HttpContext.Current != null)
HttpContext.Current.User …Run Code Online (Sandbox Code Playgroud) c# authentication claims-based-identity asp.net-web-api owin
使用Express with Node,我可以成功上传文件并将其传递到以下代码块中的Azure存储.
app.get('/upload', function (req, res) {
res.send(
'<form action="/upload" method="post" enctype="multipart/form-data">' +
'<input type="file" name="snapshot" />' +
'<input type="submit" value="Upload" />' +
'</form>'
);
});
app.post('/upload', function (req, res) {
var path = req.files.snapshot.path;
var bs= azure.createBlobService();
bs.createBlockBlobFromFile('c', 'test.png', path, function (error) { });
res.send("OK");
});
Run Code Online (Sandbox Code Playgroud)
这很好用,但Express会创建一个临时文件并先存储图像,然后我从文件中将其上传到Azure.这似乎是一个低效且不必要的步骤,我最终必须管理临时文件目录的清理.
我应该能够使用blobService.createBlockBlobFromStreamAzure SDK中的方法将文件直接流式传输到Azure存储,但我不熟悉Node或Express以了解如何访问流数据.
app.post('/upload', function (req, res) {
var stream = /// WHAT GOES HERE ?? ///
var bs= azure.createBlobService();
bs.createBlockBlobFromStream('c', 'test.png', stream, function (error) { });
res.send("OK");
});
Run Code Online (Sandbox Code Playgroud)
我发现以下博客表明可能有办法这样做,当然Express也会抓取流数据并解析并将其保存到文件系统中. …
我正在使用Request.IsSecureConnection来检查SSL并在适当的地方重定向.在Rackspace的云上运行我的asp.net网站时,服务器在SSL集群后运行,因此IsSecureConnection将始终返回false.检查URL是否包含"https://",始终为false,检查端口等等也是如此.因此网站陷入了大重定向循环.
是否有其他方法可以检查SSL并在适当的位置重定向?有人在Rackspace的云上实际做过这个吗?
Public Class SecurityAwarePage
Inherits Page
Private _requireSSL As Boolean = False
Public Property RequireSSL() As Boolean
Get
Return _requireSSL
End Get
Set(ByVal value As Boolean)
_requireSSL = value
End Set
End Property
Private ReadOnly Property IsSecure() As Boolean
Get
Return Request.IsSecureConnection
End Get
End Property
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
PushSSL()
End Sub
Private Sub PushSSL()
Const SECURE As String = "https://"
Const UNSECURE As String = "http://"
If RequireSSL AndAlso Not IsSecure Then
Response.Redirect(Request.Url.ToString.Replace(UNSECURE, …Run Code Online (Sandbox Code Playgroud) 我正在维护几个Perl脚本,它们都具有用于不同功能的类似代码块.每次更新代码块时,我都必须遍历每个脚本并手动进行更改.
有没有办法将常用函数封装到自己的脚本中并调用它们?
如何在平滑"规范"之外的任何点的同时计算一组数据的平均值.已经有一段时间了,因为我必须做任何真正的数学,但我确信我在某处学到了......
假设我有一个项目的12天销售数据:2,2,2,50,10,15,9,6,2,0,2,1
我想计算每天的平均销售额而不允许第4天(50)将平均值搞得太多.Log,Percentile,我认为......