那个想法比较完成示例代码
《asp.net应用程序html化的一个想法》比较完成示例代码
MyHtmlModule.cs
MyHtmlModule.cs
public class MyHtmlModule:IHttpModule
{
public MyHtmlModule()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
IHttpModule 成员
private void context_EndRequest(object sender, EventArgs e)
{
}
public static string GetHtmlPage(string strAspxPage)
{
string pattern =@"([\w/]*)(.aspx)([?]*)([\w=&]*)";
Regex reg = new Regex(pattern,RegexOptions.IgnoreCase);
string str = reg.Replace(strAspxPage,"$1/_$4.htm");
str = str.Replace("=","_");
str = str.Replace("&","_");
return str;
}
public static bool BuildHtmlPage2(string strAspxPage,string strHtmlFile)
{
return false;
}
public static bool BuildHtmlPage(string strAspxPage,string strHtmlFile)
{
bool bRet = false;
StreamWriter writer = null;
try
{
writer = new StreamWriter(strHtmlFile,false,System.Text.Encoding.GetEncoding("GB2312"));
HttpContext.Current.Server.Execute(strAspxPage,writer);
bRet = true;
}
catch(Exception ee)
{
string str = ee.Message;
}
finally
{
if(writer!=null)
writer.Close();
}
return bRet;
}
}
{
public MyHtmlModule()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
IHttpModule 成员
private void context_EndRequest(object sender, EventArgs e)
{
}
public static string GetHtmlPage(string strAspxPage)
{
string pattern =@"([\w/]*)(.aspx)([?]*)([\w=&]*)";
Regex reg = new Regex(pattern,RegexOptions.IgnoreCase);
string str = reg.Replace(strAspxPage,"$1/_$4.htm");
str = str.Replace("=","_");
str = str.Replace("&","_");
return str;
}
public static bool BuildHtmlPage2(string strAspxPage,string strHtmlFile)
{
return false;
}
public static bool BuildHtmlPage(string strAspxPage,string strHtmlFile)
{
bool bRet = false;
StreamWriter writer = null;
try
{
writer = new StreamWriter(strHtmlFile,false,System.Text.Encoding.GetEncoding("GB2312"));
HttpContext.Current.Server.Execute(strAspxPage,writer);
bRet = true;
}
catch(Exception ee)
{
string str = ee.Message;
}
finally
{
if(writer!=null)
writer.Close();
}
return bRet;
}
}