Example #1
0
        public virtual ActionResult GetPackage(string id, string version)
        {
            // if the version is null, the user is asking for the latest version. Presumably they don't want includePrerelease release versions.
            // The allow prerelease flag is ignored if both partialId and version are specified.
            var package = packageSvc.FindPackageForDownloadByIdAndVersion(id, version, allowPrerelease: false);

            if (package == null)
            {
                return(new HttpStatusCodeWithBodyResult(HttpStatusCode.NotFound, string.Format(CultureInfo.CurrentCulture, Strings.PackageWithIdAndVersionNotFound, id, version)));
            }

            // CloudFlare IP passed variable first
            var ipAddress = Request.Headers["CF-CONNECTING-IP"].to_string();

            if (string.IsNullOrWhiteSpace(ipAddress))
            {
                ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].to_string();
            }
            if (string.IsNullOrWhiteSpace(ipAddress))
            {
                ipAddress = Request.UserHostAddress;
            }

            packageSvc.AddDownloadStatistics(package, ipAddress, Request.UserAgent);

            return(packageFileSvc.CreateDownloadPackageActionResult(package));
        }
Example #2
0
        public virtual ActionResult GetPackage(string id, string version)
        {
            // if the version is null, the user is asking for the latest version. Presumably they don't want includePrerelease release versions.
            // The allow prerelease flag is ignored if both partialId and version are specified.
            var package = _packageSvc.FindPackageByIdAndVersion(id, version, allowPrerelease: false);

            if (package == null)
            {
                return(new HttpStatusCodeWithBodyResult(
                           HttpStatusCode.NotFound, String.Format(CultureInfo.CurrentCulture, Strings.PackageWithIdAndVersionNotFound, id, version)));
            }

            _packageSvc.AddDownloadStatistics(
                package,
                Request.UserHostAddress,
                Request.UserAgent);

            if (!String.IsNullOrWhiteSpace(package.ExternalPackageUrl))
            {
                return(Redirect(package.ExternalPackageUrl));
            }
            else
            {
                return(_packageFileSvc.CreateDownloadPackageActionResult(package));
            }
        }