Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my web site name is "nezamerafsanjan" and i writ it with asp.net mvc 4
look at this picutre:88%CPU

my code in Home Page :
C#
public ActionResult Index()
       {

           HttpCookie username = Request.Cookies["nezamcookie"];
           if (username != null && User.Identity.IsAuthenticated == false)
           {
               string us = username.Values["UserName"].ToString();
               string ps = username.Values["Password"].ToString();
               WebSecurity.Login(us, ps, persistCookie: true);
               //ControllerContext.HttpContext.Response.Redirect(Request.UrlReferrer.ToString());
           }
           // CreateDate =DateTime.Parse( (persian.GetYear(r.CreateDate) + "/" + persian.GetMonth(r.CreateDate) + "/" + persian.GetDayOfMonth(r.CreateDate))),
           //         UpdateDate =DateTime.Parse ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
           var Query = _db.News.Take(30);
           var model = (from r in Query.AsEnumerable()
                        orderby r.CreateDate descending
                        select new NewsHomeViewModel
                        {

                            Id = r.Id,
                            ImageUrl = r.ImageUrl,
                            Summary = r.Summary,
                            Title = r.Title,
                            UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
                        }).Take(6);
           var modelSpecial = (from r in Query.AsEnumerable()
                               orderby r.CreateDate descending
                               where r.Special == true
                               select new NewsHomeViewModel
                               {

                                   Id = r.Id,
                                   ImageUrl = r.ImageUrl,
                                   Summary = r.Summary,
                                   Title = r.Title,
                                   UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
                               }).Take(12);
           var modelEducation = (from r in Query.AsEnumerable()
                                 orderby r.CreateDate descending
                                 where r.Education == true
                                 select new NewsHomeViewModel
                               {

                                   Id = r.Id,
                                   ImageUrl = r.ImageUrl,
                                   Summary = r.Summary,
                                   Title = r.Title,
                                   UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
                               }).Take(6);
           ViewBag.model = model;
           ViewBag.NewsViewModelSpecial = modelSpecial;
           ViewBag.modelEducation = modelEducation;
           return View();
       }


my code is news page:
C#
[OutputCache(Duration=360,VaryByHeader="X-Requested-With",Location= OutputCacheLocation.Server)]
        public ActionResult Index(int page = 1)
        {
            
            var model = (from r in db.News.AsEnumerable()
                         orderby r.CreateDate descending
                         select new NewsViewModel
                         {
                             Body = r.Body,
                             Comments = r.Comments,
                             Education = r.Education,
                             Financial = r.Financial,
                             Id = r.Id,
                             ImageUrl = r.ImageUrl,
                             Notic = r.Notic,
                             Public = r.Public,
                             Refahi = r.Refahi,
                             Special = r.Special,
                             Summary = r.Summary,
                             Title = r.Title,
                             Visitors = r.Visitors,
                             CreateDate = ((persian.GetYear(r.CreateDate) + "/" + persian.GetMonth(r.CreateDate) + "/" + persian.GetDayOfMonth(r.CreateDate))),
                             UpdateDate = ((persian.GetYear(r.UpdateDate) + "/" + persian.GetMonth(r.UpdateDate) + "/" + persian.GetDayOfMonth(r.UpdateDate)))
                         }).ToPagedList(page,6);
            ViewData["News"] = model;
            if (Request.IsAjaxRequest())
            {
                return PartialView("_PartialNews", ViewData["News"]);
            }
            
            return View();
        }


i dont know why this application give a lot of CPU and Memory when i upload it on my Host?
Posted
Comments
Suvabrata Roy 3-Nov-14 23:48pm    
what is the news table size ?
Sergey Alexandrovich Kryukov 4-Nov-14 1:19am    
The CPU is used by the HTTP server, not "site". It looks like you would prefer the server using, say, 5% of CPU, leaving the rest of the CPU to some trash, unrelated to serving your valuable site. Why? :-)
—SA

1 solution

Hi NorouzFar, You code doesn't appears problematic but regarding the consumption, the best way to test this is try uploading some html page only or some other website on the host and check if your code is causing this or the Host itself has an issue.
 
Share this answer
 
Comments
NorouziFar 4-Nov-14 6:06am    
my host have a lot of websit and don't had any problem

i check it

i dont know what can i do
Er. Puneet Goel 20-Nov-14 2:34am    
Ah sorry to hear that...but without watching the code..its hard to answer. Better if you consult with some IT guy!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900