public virtual ActionResult DisplayPackage(string id, string version) { var package = _packageService.FindPackageByIdAndVersion(id, version); if (package == null) { return(HttpNotFound()); } var model = new DisplayPackageViewModel(package); if (package.IsOwner(HttpContext.User)) { // Tell logged-in package owners not to cache the package page, so they won't be confused about the state of pending edits. Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); Response.Cache.SetMaxAge(TimeSpan.Zero); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); var pendingMetadata = _editPackageService.GetPendingMetadata(package); if (pendingMetadata != null) { model.SetPendingMetadata(pendingMetadata); } } ViewBag.FacebookAppID = _config.FacebookAppId; return(View(model)); }
public virtual ActionResult DisplayPackage(string id, string version) { string normalized = SemanticVersionExtensions.Normalize(version); if (!String.Equals(version, normalized)) { // Permanent redirect to the normalized one (to avoid multiple URLs for the same content) return(RedirectToActionPermanent("DisplayPackage", new { id = id, version = normalized })); } var package = _packageService.FindPackageByIdAndVersion(id, version); if (package == null) { return(HttpNotFound()); } var model = new DisplayPackageViewModel(package); if (package.IsOwner(User)) { // Tell logged-in package owners not to cache the package page, so they won't be confused about the state of pending edits. Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); Response.Cache.SetMaxAge(TimeSpan.Zero); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); var pendingMetadata = _editPackageService.GetPendingMetadata(package); if (pendingMetadata != null) { model.SetPendingMetadata(pendingMetadata); } } ViewBag.FacebookAppID = _config.FacebookAppId; return(View(model)); }
public virtual async Task <ActionResult> DisplayPackage(string id, string version) { string normalized = NuGetVersionNormalizer.Normalize(version); if (!string.Equals(version, normalized)) { // Permanent redirect to the normalized one (to avoid multiple URLs for the same content) return(RedirectToActionPermanent("DisplayPackage", new { id = id, version = normalized })); } var package = _packageService.FindPackageByIdAndVersion(id, version); if (package == null) { return(HttpNotFound()); } var packageHistory = package.PackageRegistration.Packages.ToList() .OrderByDescending(p => new NuGetVersion(p.Version)); var model = new DisplayPackageViewModel(package, packageHistory); if (package.IsOwner(User)) { // Tell logged-in package owners not to cache the package page, // so they won't be confused about the state of pending edits. Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); Response.Cache.SetMaxAge(TimeSpan.Zero); Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); var pendingMetadata = _editPackageService.GetPendingMetadata(package); if (pendingMetadata != null) { model.SetPendingMetadata(pendingMetadata); } } var externalSearchService = _searchService as ExternalSearchService; if (_searchService.ContainsAllVersions && externalSearchService != null) { var isIndexedCacheKey = $"IsIndexed_{package.PackageRegistration.Id}_{package.Version}"; var isIndexed = HttpContext.Cache.Get(isIndexedCacheKey) as bool?; if (!isIndexed.HasValue) { var searchFilter = SearchAdaptor.GetSearchFilter( "id:\"" + package.PackageRegistration.Id + "\" AND version:\"" + package.Version + "\"", 1, null, SearchFilter.ODataSearchContext); var results = await externalSearchService.RawSearch(searchFilter); isIndexed = results.Hits > 0; var expiration = Cache.NoAbsoluteExpiration; if (!isIndexed.Value) { expiration = DateTime.UtcNow.Add(TimeSpan.FromSeconds(30)); } HttpContext.Cache.Add(isIndexedCacheKey, isIndexed, null, expiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, null); } model.IsIndexed = isIndexed; } ViewBag.FacebookAppID = _config.FacebookAppId; return(View(model)); }