Пример #1
0
    protected void Page_PreRender(object sender, EventArgs e)
    {
        string      errorMessage;
        DownloadKey downloadKey = new DownloadKey(ProductID, SystemConst.AnonymousUser, OrderItemID);

        bool isAnonymousCheckout = (
            downloadKey.VerifyKey(Key, out errorMessage) == DownloadKey.VerifyStatus.OK);

        if (!isAnonymousCheckout)
        {
            downloadKey         = new DownloadKey(ProductID, SystemConst.UnknownUser, OrderItemID);
            isAnonymousCheckout = (downloadKey.VerifyKey(Key, out errorMessage) == DownloadKey.VerifyStatus.OK);
        }

        if (!Roles.IsUserInRole("Customers") && !isAnonymousCheckout)
        {
            // Response.Redirect( "FileDownloadManager.aspx?ProductID=" + ProductID + "&Key=" + Key );
            Response.Redirect(
                "FileDownloadManager.aspx?ProductID=" + HttpContext.Current.Server.UrlEncode(ProductID) +
                "&OrderItemID=" + HttpContext.Current.Server.UrlEncode(OrderItemID) +
                "&Key=" + HttpContext.Current.Server.UrlEncode(Key));
        }

        if (!isAnonymousCheckout)
        {
            downloadKey = new DownloadKey(ProductID, Membership.GetUser().UserName, OrderItemID);
        }

        if (isAnonymousCheckout ||
            downloadKey.VerifyKey(Key, out errorMessage) == DownloadKey.VerifyStatus.OK)
        {
            Product product = DataAccessContext.ProductRepository.GetOne(StoreContext.Culture, ProductID, new StoreRetriever().GetCurrentStoreID());

            // Identify the file to download including its path.
            string filepath = HttpContext.Current.Server.MapPath("~/" + product.DownloadPath);

            // Identify the file name.
            string filename = Path.GetFileName(filepath);

            // Open the file.
            Stream iStream = new FileStream(filepath, FileMode.Open,
                                            FileAccess.Read, FileShare.Read);

            Exception ex;
            WebUtilities.CreateExportFile(System.Web.HttpContext.Current.ApplicationInstance, iStream, filename, out ex);
            if (ex != null)
            {
                uxMessageLabel.Text = "<strong>Error:</strong> " + ex.GetType().ToString();
            }
        }
        else
        {
            uxMessageLabel.Text = "<strong>Error:</strong> [$Cannot Download]";
        }
    }
    private DownloadKey.VerifyStatus VerifyDownloadInfoAnonymous(out string errorMessage)
    {
        DownloadKey downloadKey = new DownloadKey(ProductID, SystemConst.AnonymousUser, OrderItemID);

        if (VerifyDownloadInfoAnonymous(out errorMessage, SystemConst.AnonymousUser) != DownloadKey.VerifyStatus.InvalidUser)
        {
            return(VerifyDownloadInfoAnonymous(out errorMessage, SystemConst.AnonymousUser));
        }
        else
        {
            return(VerifyDownloadInfoAnonymous(out errorMessage, SystemConst.UnknownUser));
        }
    }
 private DownloadKey.VerifyStatus VerifyDownloadInfo(out string errorMessage)
 {
     errorMessage = String.Empty;
     if (Roles.IsUserInRole("Customers"))
     {
         DownloadKey downloadKey = new DownloadKey(ProductID, Page.User.Identity.Name, OrderItemID);
         return(downloadKey.VerifyKey(Key, out errorMessage));
     }
     else
     {
         return(DownloadKey.VerifyStatus.InvalidUser);
     }
 }
    private DownloadKey.VerifyStatus VerifyDownloadInfoAnonymous(out string errorMessage, string userName)
    {
        DownloadKey downloadKey = new DownloadKey(ProductID, userName, OrderItemID);

        return(downloadKey.VerifyKey(Key, out errorMessage));
    }