Google Chrome HttpPost问题

时间:2014-06-25 15:39:30

标签: asp.net-mvc google-chrome browser http-post

我对ASP.net mvc比较新,我遇到了一个非常奇怪的浏览器错误。问题是它在客户的电脑上(我还没有访问)。

他的计算机上发布数据时似乎存在间歇性问题,此时他只尝试使用chrome(我要求他尝试不同的浏览器)。我无法复制这个问题,并尝试了两台计算机,三个浏览器和三个不同的操作系统(Windows 7,Windows 8(通过mac parallels)和Osx Mavericks)。

我会发布模型和相关的控制器代码(希望它不是太邋code的编码)

我澄清了以下内容: - 我们都使用相同版本的chrome - 我们都使用相同的ISP - 他有AVG跑 - 该网站托管在Azure上 - 分配了大量的数据库和文件内存(只使用了10%) - 我的代码中很少有与在线示例不同的内容,而且这一切都适用于我

所以我的问题是,我还能在哪里找到错误: - 我应该考虑添加或更改代码中的某些内容 - 他的Chrome版本可能是cookie问题吗? - 某处有防火墙问题吗?

模型

public class KitchenItem:Post
{


    public virtual ICollection<Image> Images { get; set; }


    //Optional Project Variables
    public bool Project { get; set; }
    public string ProjectName { get; set; }
    public string Customer { get; set; }
    public DateTime? projectStart { get; set; }
    public DateTime? projectEnd { get; set; }

}
}

继承模型:

public class Post
{
    public int Id
    { get; set; }

    [Required]
    public  string Title
    { get; set; }

    [Required]
    [Display(Name="Short Description")]
    [DataType(DataType.MultilineText )]
    public  string ShortDescription
    { get; set; }

    [Required]
    [AllowHtml]
    [UIHint("tinymce_full_compressed")]
    public string Description
    { get; set; }

    [Display(Name = "Meta Keywords")]
    [DefaultValue (" ")]
    public  string Meta
    { get; set; }



    public  string UrlSlug
    { get; set; }

    public  bool Published
    { get; set; }

    public  DateTime? PostedOn
    { get; set; }

    public  DateTime? Modified
    { get; set; }

    public int? CategoryID { get; set; }


    public Category Category
    { get; set; }

    [NotMapped]
    public HttpPostedFileBase uploadedFile { get; set; }
    public string mainImagePath { get; set; }

    public virtual ICollection<Tag> Tags
    { get; set; }
}

视图模型:

public class CreateProjectViewModel
{
    public KitchenItem  KitchenItem { get; set; }

    [Display(Name = "Upload Image")]
    public HttpPostedFileBase[] ImagesFiles { get; set; }


    public Image[] Images { get; set; }
    public int CategoryID { get; set; }

    public int[] imageDeletes { get; set; }
}

创建帖子:

    [HttpPost]
    [Authorize]
    [ValidateAntiForgeryToken]
    public ActionResult Create(CreateProjectViewModel viewModel)
    {
        KitchenItem model = new KitchenItem();
        model = viewModel.KitchenItem;
        try
        {
            /* 
             *Create ID from total Images to allow for specific folders to be created when file saved, iteration (totalImages) 
             *Calls for loop for each element of array to ensure that specific titles and tags are associated to correct image
             * Add image to model collection to be saved to db                 
             */

            List<Image> imgCollection = new List<Image>();
            int totalKitchenItems = unitofWork.KitchenItemRepository.dbSet.Count() + 1;



            //update model images
            model.Images = handleEditImage(viewModel.ImagesFiles, viewModel.Images, imgCollection, model.Id);


            //Log date posted
            model.PostedOn = DateTime.Now;


            Category cat = new Category();

            model.Category = unitofWork.CategoryRepository.GetByID(viewModel.CategoryID);



            //create post
            unitofWork.KitchenItemRepository.Insert(model);
            unitofWork.Save();

            return RedirectToAction("Index");

        }
        catch (DbEntityValidationException dbEx)
        {
            foreach (var validationErrors in dbEx.EntityValidationErrors)
            {
                foreach (var validationError in validationErrors.ValidationErrors)
                {
                    Trace.TraceInformation("Class: {0}, Property: {1}, Error: {2}",
                        validationErrors.Entry.Entity.GetType().FullName,
                        validationError.PropertyName,
                        validationError.ErrorMessage);
                }
                foreach (var eve in dbEx.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
            }


            PopulateCategoriesDropDownList(0);

            return RedirectToAction("Index");

        }
    }

处理图像&amp;添加图像功能:

 public ICollection<Image> handleEditImage(HttpPostedFileBase[] imageFiles, Image[] images, ICollection<Image> modelImages, int modelID)
    {           
        /* 
                *Create ID from total Images to allow for specific folders to be created when file saved, iteration (totalImages) 
                *Calls for loop for each element of array to ensure that specific titles and tags are associated to correct image
                * Add image to model collection to be saved to db                 
                */

        List<Image> imgCollection = new List<Image>();

        for (int i = 0; i < 5; i++)
        {
            Image uploadImage = new Image();

            //check to make sure there is an image
            if (imageFiles[i] != null)
            {
                //handle httppostedfilebase conversion to image file and add Url to image model
                uploadImage = AddImage(imageFiles[i], images[i], modelID);
                //Add img to be updated to model
                imgCollection.Add(uploadImage);
            }

        }
        if (modelImages != null)
        {

            //check for deleted images
            foreach (var img in modelImages)
            {
                //loop through image array to determine whether image is currently assigned to model
                for (int i = 0; i < 5; i++)
                {

                    if (images[i].ImageUrl != null)
                    {
                        //replace string element modified before passed to view
                        images[i].ImageUrl = images[i].ImageUrl.Replace("../../", "~/");
                    }
                    if (img.ImageUrl == images[i].ImageUrl)
                    {

                        imgCollection.Add(img);
                    }
                }

            }

        }

        return imgCollection;
    }

  public Image AddImage(HttpPostedFileBase imageToSave, Image modelImage, int Id)
    {
        Image img = new Image();
        img = modelImage;
        img.ImageUrl = SaveUploadedFile(imageToSave, Id);
        unitofWork.ImagesRepository.Insert(img);
        return img;
    } 

0 个答案:

没有答案