发布一个aspx生成为html的函数过程源码

本文介绍了一种使用VB.NET将ASPX动态页面转换为HTML静态页面的方法。通过调用特定函数,可以指定模板文件、目标HTML文件及编码方式,实现网页的静态化,便于后续的部署与访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  ''' <summary>
  ''' 生成Html静态网页
  ''' </summary>
  Function AspxToHtml(ByVal TemplateFile As String, ByVal HtmlFile As String, Optional ByVal GEncoding As String = "UTF-8", Optional ByVal Cover As Integer = 1) As Boolean
    Try
      Dim SHtml As String = GetURL(TemplateFile, GEncoding), HtmlPath As String = AppPath & HtmlFile.Replace("/", "\")
      If SHtml = "" Then Return False
      If IO.File.Exists(HtmlPath) = True Then '文件存在
        If Cover = 0 Then Return False '不复盖
        IO.File.Delete(HtmlPath) ',删除
      Else
        Dim HDir As String = HtmlPath.Substring(0, HtmlPath.LastIndexOf("\"))
        If IO.Directory.Exists(HDir) = False Then IO.Directory.CreateDirectory(HDir) '文件夹是否存在,不存在而创建
      End If

      Dim SWtr As New IO.StreamWriter(HtmlPath, False, Encoding.GetEncoding(GEncoding))
      SWtr.Write(SHtml) : SWtr.Flush() : SWtr.Close() : SWtr.Dispose()
      Return True
    Catch ex As Exception
      Return False
    End Try
  End Function

vb.net写的aspx生成为html源码,调用方法如下:

Private WebUrl As String = "http://" & HttpContext.Current.Request.ServerVariables("server_name")

AspxToHtml(WebUrl & "/Template/web/Default.aspx", "\Html\web\Default.html")
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值