好吧,這讓我瘋狂。MVC該資源無法找到
我有這個項目,我是個月,沒有觸及FeedController
。一切工作正常。 然後,我打開FeedController
來更改某個操作中的某些代碼,出於某種原因,VS2010崩潰了。好的,VS之前已經崩潰了,沒什麼不尋常的。
所以我重新啓動VS,並神祕地,FeedController
開始給「404資源無法找到」錯誤。
所以我查了Global.asax
,Web.Config
,StartURL,所有人都推薦的東西。無法讓它工作。如果我撥打/Feed/Index
,It Works!但/Feed/
只是給了我錯誤。
將整個控制器的名稱更改爲ShitController
,它完美無缺!不知何故,該項目決定「飼料」是某種「詛咒詞」。
清理解決方案,/bin/
重啓vs dev服務器,重新啓動計算機,它只是經紀人永遠。
我開始認爲這是一個MVC3嚴重的BUG。
有人嗎?
我越來越瘋狂。我應該出去走走,也許:)
路線:
routes.MapRoute(
"XBLContentDetailsLocale",
"XBLContent/Details/{guid}/{locale}",
new { controller = "XBLContent", action = "Details"},
new { guid = @"[0-9|a-z|\-]{36}", locale = @"[a-z|A-Z]{2}-[A-Z|a-z]{2}"}
);
routes.MapRoute(
"XBLContentDetails",
"XBLContent/Details/{guid}",
new { controller = "XBLContent", action = "Details" },
new { guid = @"[0-9|a-z|\-]{36}" }
);
routes.MapRoute(
"XBLContentDaysLocale",
"XBLContent/{days}/{locale}",
new { controller = "XBLContent", action = "Index" },
new { days = @"[0-9]", locale = @"[a-z|A-Z]{2}-[A-Z|a-z]{2}" }
);
routes.MapRoute(
"XBLContentDays",
"XBLContent/{days}",
new { controller = "XBLContent", action = "Index" },
new { days = @"[0-9]" }
);
routes.MapRoute(
"FeedRouteFull",
"Feed/{action}/{sort}/{locale}",
new { controller = "Feed", action = "GameAddons" },
new { sort = @"[a-z|A-Z]+", locale = @"[a-z|A-Z]{2}-[A-Z|a-z]{2}" }
);
routes.MapRoute(
"FeedRouteSort",
"Feed/{action}/{sort}",
new { controller = "Feed", action = "GameAddons", sort = UrlParameter.Optional },
new { sort = @"[a-z|A-Z]+" }
);
routes.MapRoute(
"FeedRoute",
"Feed/{action}",
new { controller = "Feed", action = "Index" }
);
routes.MapRoute(
"Locale",
"{locale}",
new { controller = "Home", action = "Index" },
new { locale = @"[a-z|A-Z]{2}-[A-Z|a-z]{2}" }
);
routes.MapRoute(
"ControllerLocale",
"{controller}/{locale}",
new { controller = "Home", action = "Index", locale = UrlParameter.Optional },
new { locale = @"[a-z|A-Z]{2}-[A-Z|a-z]{2}" }
);
routes.MapRoute(
"ControllerActionLocale",
"{controller}/{action}/{locale}",
new { controller = "Home", action = "Index", locale = UrlParameter.Optional },
new { locale = @"[a-z|A-Z]{2}-[A-Z|a-z]{2}" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
UPDATE: 我評論的所有路由只留下一個默認,並且錯誤依然存在。
更新: 這裏是整個控制器。不僅改變了街機動作,並評論了「oldcode」:
public class FeedController : Controller
{
XBLContentContext db = new XBLContentContext();
private int activemenu = 4;
private const int QT_FEED = 12;
public ActionResult Index(string locale)
{
if (String.IsNullOrEmpty(locale))
locale = "en-us";
ViewBag.Title = "Xbox LIVE Feeds";
ViewBag.Description = "Xbox LIVE Feed generator. Configure and add it to your favourite feed reader.";
ViewBag.Keywords = "xbox, live, tools, feed, syndication, rss, atom";
ViewBag.ContentType = Enum.GetValues(typeof(ContentType)).Cast<ContentType>().Select(v => new SelectListItem
{
Selected = (v == ContentType.Arcade),
Text = v.ToString().ToSentence(),
Value = v.ToString()
});
ViewBag.SortBy = Enum.GetValues(typeof(SortBy)).Cast<SortBy>().Select(v => new SelectListItem
{
Selected = (v == SortBy.OfferStartDate),
Text = v.ToString().ToSentence(),
Value = v.ToString()
});
ViewBag.Regions = (from x in GlobalVariables.Regions
select new SelectListItem
{
Selected = (x.ID.ToLower() == locale),
Text = x.Country,
Value = x.ID.ToLower()
}).OrderBy(x => x.Text).ToList();
return View();
}
public ActionResult AllDownloads(string sort, string locale)
{
var today = DateTime.Today;
var region = "All Regions";
var qry = from c in db.XBLRegionalContents.Include("Region").Include("Content")
where c.PublishDate <= today
select c;
var qry2 = from c in qry
group c by c.ContentId into grouped
let maxdate = grouped.Max(x => x.PublishDate)
select new
{
Key = grouped.Where(x => x.ContentId == grouped.Key && (x.PublishDate == maxdate)).FirstOrDefault(),
Value = grouped.Where(x => x.ContentId == grouped.Key).Select(x => x.Region)
};
if (!String.IsNullOrEmpty(locale))
qry2 = from c in qry2
where c.Value.Any(x => x.ID == locale)
select c;
var model = qry2.OrderByDescending(x => x.Key.PublishDate).Take(QT_FEED).ToDictionary(x => x.Key, x => x.Value);
if (!String.IsNullOrEmpty(locale) && model.Count() > 0)
region = model.FirstOrDefault().Key.Region.CountryEnglish;
ViewBag.Language = locale;
ViewBag.FeedTitle = "XBLTOOLS - Latest Content";
ViewBag.FeedDescription = String.Format("{0} - {1}", region, DateTime.Now);
return View("GlobalFeed", model);
}
public ActionResult FullGames(string sort, string locale)
{
var today = DateTime.Today;
var region = "All Regions";
var indie = ContentType.IndieGames.ToString();
var qry = from c in db.XBLRegionalContents.Include("Region").Include("Content")
where c.Content.RelatedGameId == null && c.Content.FileSize > 0
&& c.PublishDate <= DateTime.Today
&& c.Content.ContentType != indie
select c;
var qry2 = from c in qry
group c by c.ContentId into grouped
select new
{
Key = grouped.Where(x => x.ContentId == grouped.Key).FirstOrDefault(),
Value = grouped.Where(x => x.ContentId == grouped.Key).Select(x => x.Region)
};
if (!String.IsNullOrEmpty(locale))
qry2 = from c in qry2
where c.Value.Any(x => x.ID == locale)
select c;
var model = qry2.OrderByDescending(x => x.Key.PublishDate).Take(QT_FEED).ToDictionary(x => x.Key, x => x.Value);
if (!String.IsNullOrEmpty(locale) && model.Count > 0)
region = model.FirstOrDefault().Key.Region.CountryEnglish;
ViewBag.Language = locale;
ViewBag.FeedTitle = "XBLTOOLS - Full Games";
ViewBag.FeedDescription = String.Format("{0} - {1}", region, DateTime.Now);
return View("GlobalFeed", model);
}
public ActionResult Arcade(string sort, string locale)
{
var page = db.XBLPages.First(x => x.Type == (int)XBLPageType.List);
using (XBLPageCrawler crawler = new XBLPageCrawler(page, ContentType.Arcade, DownloadType.Game, sort, locale))
{
var countrycode = String.IsNullOrEmpty(locale) ? String.Empty : String.Format("{0} - ", locale.Split('-')[1].ToUpper());
ViewBag.Language = locale;
ViewBag.FeedTitle = String.Format("{0}{1}", countrycode, crawler.CType.GetDescription());
return View("Feed", crawler.PageContent);
}
#region OLDCODE
// using (XBLChart p = new XBLChart(ContentType.Arcade, DownloadType.Game, sort, locale))
// {
// var countrycode = String.IsNullOrEmpty(locale) ? String.Empty : String.Format("{0} - ", locale.Split('-')[1].ToUpper());
// ViewBag.Language = locale;
// ViewBag.FeedTitle = String.Format("{0}{1}", countrycode, p.CType.GetDescription());
// return View("Feed", p.ListaRegional);
// }
#endregion
}
public ActionResult GamesOnDemand(string sort, string locale)
{
using (XBLChart p = new XBLChart(ContentType.GamesOnDemand, DownloadType.Game, sort, locale))
{
var countrycode = String.IsNullOrEmpty(locale) ? String.Empty : String.Format("{0} - ", locale.Split('-')[1].ToUpper());
ViewBag.Language = locale;
ViewBag.FeedTitle = String.Format("{0}{1}", countrycode, p.CType.GetDescription());
return View("Feed", p.ListaRegional);
}
}
public ActionResult IndieGames(string sort, string locale)
{
using (XBLChart p = new XBLChart(ContentType.IndieGames, DownloadType.Game, sort, locale))
{
var countrycode = String.IsNullOrEmpty(locale) ? String.Empty : String.Format("{0} - ", locale.Split('-')[1].ToUpper());
ViewBag.Language = locale;
ViewBag.FeedTitle = String.Format("{0}{1}", countrycode, p.CType.GetDescription());
return View("Feed", p.ListaRegional);
}
}
public ActionResult GameDemos(string sort, string locale)
{
using (XBLChart p = new XBLChart(ContentType.GameDemos, DownloadType.GameDemo, sort, locale))
{
var countrycode = String.IsNullOrEmpty(locale) ? String.Empty : String.Format("{0} - ", locale.Split('-')[1].ToUpper());
ViewBag.Language = locale;
ViewBag.FeedTitle = String.Format("{0}{1}", countrycode, p.CType.GetDescription());
return View("Feed", p.ListaRegional);
}
}
public ActionResult GameAddons(string sort, string locale)
{
using (XBLChart p = new XBLChart(ContentType.GameAddons, DownloadType.GameAddon, sort, locale))
{
var countrycode = String.IsNullOrEmpty(locale) ? String.Empty : String.Format("{0} - ", locale.Split('-')[1].ToUpper());
ViewBag.Language = locale;
ViewBag.FeedTitle = String.Format("{0}{1}", countrycode, p.CType.GetDescription());
return View("Feed", p.ListaRegional);
}
}
public ActionResult GameVideos(string sort, string locale)
{
using (XBLChart p = new XBLChart(ContentType.GameVideos, DownloadType.GameVideo, sort, locale))
{
var countrycode = String.IsNullOrEmpty(locale) ? String.Empty : String.Format("{0} - ", locale.Split('-')[1].ToUpper());
ViewBag.Language = locale;
ViewBag.FeedTitle = String.Format("{0}{1}", countrycode, p.CType.GetDescription());
return View("Feed", p.ListaRegional);
}
}
public ActionResult ThemesAndGamerPic(string sort, string locale)
{
using (XBLChart p = new XBLChart(ContentType.ThemesAndGamerPic, DownloadType.ThemesAndGamerPic, sort, locale))
{
var countrycode = String.IsNullOrEmpty(locale) ? String.Empty : String.Format("{0} - ", locale.Split('-')[1].ToUpper());
ViewBag.Language = locale;
ViewBag.FeedTitle = String.Format("{0}{1}", countrycode, p.CType.GetDescription());
return View("Feed", p.ListaRegional);
}
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
UPDATE 改變了指數動作配置和它的作品。似乎問題與默認隱式「索引」,因爲顯式/飼料/索引也起作用。
你能張貼你的路線嗎?如果主機IDE崩潰並導致問題,那麼這不是一個錯誤。 –
您的Feed控制器中是否有多種方法?你能夠在控制器中發佈代碼和調用它的代碼嗎? –
您是將它部署到IIS還是在本地開發服務器上運行? – flup