小编aik*_*ixd的帖子

使用System.IO.Packaging在c#中创建zip

我试图在服务器上动态创建zip文件,其中包括来自在线服务的照片.但是当我尝试打开文件时,WinRar sais文件格式未知或已损坏.

这是代码:

MemoryStream stream = new MemoryStream();
Package package = ZipPackage.Open(stream, FileMode.Create, FileAccess.ReadWrite);

foreach (Order o in orders)
{
    o.GetImages();

    Parallel.ForEach(o.Images, (Dictionary<string, object> image) =>
    {
        string imageId = (string)image["ID"];
        int orderId = (int)image["OrderId"];
        string fileName = (string)image["FileName"];
        string url = (string)image["URL"];

        if (string.IsNullOrEmpty(fileName))
        {
            System.Net.WebClient wc = new System.Net.WebClient();
            byte[] data = wc.DownloadData(url);
            MemoryStream ms = new MemoryStream(data);
            ms.Write(data, 0, data.Length);

            string ext;

            switch(wc.ResponseHeaders["Content-Type"])
            {
                case "image/jpeg":
                case "image/jpg":
                ext = "jpg";
                    break;

                case "image/png":
                    ext = "png"; …
Run Code Online (Sandbox Code Playgroud)

.net c# zip system.io.packaging

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

为什么'for ... in'允许关闭?

闭包中不允许使用可变值,但for .. in表达式是可以的.在C#中,for循环更新迭代器,但不会在F#中更新.怎么样和为什么?

foreach f# closures for-loop immutability

4
推荐指数
1
解决办法
117
查看次数

F# - 使用条件元素创建列表

考虑这段代码

let a, b, c = ...
let mutable l = [a]

if conditionB then l <- b :: l
if conditionC then l <- c :: l
Run Code Online (Sandbox Code Playgroud)

我觉得这违背了语言原则.这是正确的方式还是我错过了什么?

编辑: l然后返回结果

f# list

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

Request.Cookies 中的双重 cookie

我在 global.asax 中有以下代码:

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
    if (Request.Cookies["AUTH"] != null)
    {
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies["AUTH"].Value);

        HttpContext.Current.User = new MyPrincipal(ticket.Name);

        HttpCookie cookie = Request.Cookies["AUTH"];
        cookie.Expires = DateTime.Now.AddDays(30);

        Response.Cookies.Add(cookie);
    }
}
Run Code Online (Sandbox Code Playgroud)

它工作正常,但是当我检查 Request.Cookies 集合时,AUTH cookie 有 2 个条目,具有不同的值。怎么来的?

这是登录页面中认证过程的代码:

if (Account.Authenticate(login.Text, pass.Text))
{
    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(login.Text, true, 43200);

    HttpCookie cookie = new HttpCookie("AUTH");
    cookie.Expires = DateTime.Now.AddDays(30);
    cookie.HttpOnly = true;
    cookie.Value = FormsAuthentication.Encrypt(ticket);

    Response.Cookies.Add(cookie);


    Response.Redirect(Page.Request.UrlReferrer.ToString());
}
Run Code Online (Sandbox Code Playgroud)

asp.net authentication cookies

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