Saturday, 31 December 2016

.asp webpage download file by iis

downloads take place on several client computers simultaneously, they can be paused and resume.


create .asp webform project

//default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="download._default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">

        <div>
            <asp:Button ID="Button1" runat="server" Text="download" OnClick="Button1_Click" />
        </div>

    </form>
</body>
</html>

------------------------------------------------------------------
//default.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace download
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + "office2010破解版.7z" + ";");
            Response.Flush();
            Response.TransmitFile(Server.MapPath("~/files/office2010破解版.7z"));
            Response.End();
        }
    }
}

-----------------------------------------------------------------------
//web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>

    <httpRuntime targetFramework="4.5.2" />

  </system.web>
  
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
</configuration>

create files folder under visual studio download project -> copy office2010破解版.7z into files folder for debugging

publish download project

open iis -> right click on download -> explore


create files folder -> copy office2010破解版.7z into files folder for client download


reference:

https://www.youtube.com/watch?v=h48Le6EB6Yc
http://ctrlcvprogrammer.blogspot.ca/2012/02/normal-0-false-false-false-en-us-x-none_18.html

No comments:

Post a Comment