小编bUK*_*eer的帖子

WebAPI StreamContent vs PushStreamContent

我正在实现一个MVC4 + WebAPI版本的BluImp jQuery文件上传一切都适用于我最初的尝试,但我试图确保在下载非常大的文件(~2GB)时最好地使用内存.

我已经阅读了Filip Woj关于PushStreamContent的文章并尽可能地实现它(删除异步部分 - 也许这就是问题?).当我运行测试并观察TaskManager时,我没有看到明显不同的内存使用情况,我试图理解响应如何处理之间的差异.

这是我的StreamContent版本:

private HttpResponseMessage DownloadContentNonChunked()
{
    var filename = HttpContext.Current.Request["f"];
    var filePath = _storageRoot + filename;
    if (File.Exists(filePath))
    {
        HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
        response.Content = new StreamContent(new FileStream(filePath, FileMode.Open, FileAccess.Read));
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        {
            FileName = filename
        };
        return response;
    }
    return ControllerContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, "");
}
Run Code Online (Sandbox Code Playgroud)

这是我的PushStreamContent版本:

public class FileDownloadStream
{
    private readonly string _filename;

    public FileDownloadStream(string filePath)
    {
        _filename = filePath;
    }

    public …
Run Code Online (Sandbox Code Playgroud)

c# visual-studio asp.net-mvc-4 asp.net-web-api

36
推荐指数
1
解决办法
5万
查看次数

Google GCM中的HTTP响应代码401

下面是我得到的例外,即使我的服务器和浏览器应用程序的API密钥有效.我用curl检查了一下.我以UTF-8和JSON格式发送GCM请求.从外部企业网络测试它.

java.io.IOException: Server returned HTTP response code: 401 for URL: https://android.googleapis.com/gcm/send
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1345)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1339)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:993)
        at java.net.URLConnection.getContent(URLConnection.java:688)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getContent(HttpsURLConnectionImpl.java:406)
        at gcm1.MessageUtil.sendMessage(MessageUtil.java:58)
Run Code Online (Sandbox Code Playgroud)

我可以知道原因和解决方案吗?

java google-cloud-messaging

10
推荐指数
1
解决办法
1万
查看次数

**在SQL Server Management Studio中查看执行计划时的受限文本**

我正在审查执行计划,以了解存储过程为何运行缓慢.但是在执行计划窗口而不是Missing Indexes我得到的有用文本** Restricted Text **.

这让我好奇,因为我以前没见过它,也找不到谷歌搜索或者搜索SO的参考.

有人可以解释这是告诉我的,如果可能的话,如何不限制文本 - 我猜SSMS试图告诉我一些东西,但不管它试图告诉我的是非常冗长并被这个文本取代代替.

SQL Server Management Studio执行计划 - 受限制的文本

sql sql-server ssms sql-execution-plan

5
推荐指数
1
解决办法
769
查看次数

使用SVG路径创建加号(+)

我正在尝试为Google Maps项目创建一个+号作为SVG路径。使用符号路径属性将沿多段线绘制加号。到目前为止,我已经设法接近了,我的加号当前看起来像一条水平线,垂直线的一端设置为“-|”。我需要它出现在水平线的中间,以使其看起来像一个加号。

我的当前路径是使用以下path命令设置的:

path: 'M 0,-1 0,1 H -1,1 0,1'
Run Code Online (Sandbox Code Playgroud)

我应该如何改变它以获得我的加号?我可以找到许多更复杂的形状,曲线,渐变填充等示例,但由于我的知识有限,我一直在努力寻找正确的坐标来表达我的形状!

svg google-maps-api-3 google-polyline

3
推荐指数
1
解决办法
4678
查看次数

WebAPI 获取访问令牌,无需用户名和密码

我尝试在 Web api 中登录用户而不使用用户名/密码组合。我可以访问用户的 User 对象,但需要“登录”并将访问令牌返回给客户端应用程序以供后续请求。

我已经尝试了以下变体,但没有运气,该对象在我第一次UserManager调用时就被释放,这导致它失败,并且它警告我我的强制转换是“可疑的类型转换或检查”,但是无论如何,代码永远不会到达该行;这是我尝试过的,它是从我的班级方法中获取和修改的。顺便说一句,我的令牌端点与通常的,和请求完美配合。GenerateUserIdentityAsynccookiesIdentityOAuthGrantResourceOwnerContextCredentialsGrantResourceOwnerCredentialsApplicationOAuthProviderusernamepasswordgrant_type

var user = // Super secret way of getting the user....;
Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie);
// UserManager is not null at this point
var oAuthIdentity = await user.GenerateUserIdentityAsync(UserManager,
                OAuthDefaults.AuthenticationType);
// UserManager is null at this point and so throws exception
var cookiesIdentity = await user.GenerateUserIdentityAsync(UserManager,
                CookieAuthenticationDefaults.AuthenticationType);

var properties = ApplicationOAuthProvider.CreateProperties(user.UserName);
var ticket = new AuthenticationTicket(oAuthIdentity, properties);


((OAuthGrantResourceOwnerCredentialsContext)HttpContext.Current.GetOwinContext().Request.Context)
            .Validated(ticket);
        HttpContext.Current.GetOwinContext().Request.Context.Authentication.SignIn(cookiesIdentity);
Run Code Online (Sandbox Code Playgroud)

本质上,我想做的就是为我没有用户名和密码的用户返回一个访问令牌,但我想使用一个“秘密”而不是用户名密码。有办法吗?

asp.net-web-api

2
推荐指数
1
解决办法
2362
查看次数