URL重写问题
已经设置好了泛域名,希望实现test.abc.com实际访问目录为www.abc.com\test
研究了半天UrlRewrite,才发现在net2.0中无法使用,虽然有源码,还不明白该如何修改。不知除了UrlRewrite还有其它方法没?
------解决方案--------------------写一个创建静态页带URL重写的例子希望对楼主有用:
先新建一个CreatHtml.aspx页 用来创建静态页
主要代码如下:
页面代码:
<form id= "Form1 " method= "post " runat= "server ">
<asp:TextBox id= "TextBox1 " style= "Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 40px " runat= "server "
Width= "240px "> </asp:TextBox>
<asp:TextBox id= "TextBox2 " style= "Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 88px " runat= "server "
TextMode= "MultiLine " Width= "456px " Height= "280px "> </asp:TextBox>
<asp:Button id= "Button1 " style= "Z-INDEX: 103; LEFT: 456px; POSITION: absolute; TOP: 40px " runat= "server "
Text= "创建 "> </asp:Button>
<asp:HyperLink id= "HyperLink1 " style= "Z-INDEX: 104; LEFT: 656px; POSITION: absolute; TOP: 88px "
runat= "server "> HTML页 </asp:HyperLink>
<DIV style= "DISPLAY: inline; Z-INDEX: 105; LEFT: 112px; WIDTH: 78px; POSITION: absolute; TOP: 88px; HEIGHT: 36px "
ms_positioning= "FlowLayout "> 页面内容: </DIV>
<DIV style= "DISPLAY: inline; Z-INDEX: 106; LEFT: 112px; WIDTH: 88px; POSITION: absolute; TOP: 40px; HEIGHT: 36px "
ms_positioning= "FlowLayout "> 页面标题: </DIV>
</form>
后台程序:
实现引用这两个类:
using System.Text;
using System.IO;
在创建按钮事件中:
private void Button1_Click(object sender, System.EventArgs e)
{
string[] newContent=new string[5];//定义和HTML标记数目一致得数组
StringBuilder strhtml=new StringBuilder();
try
{
//创建StreamReader对象
using(StreamReader sr=new StreamReader(Server.MapPath( "createHTML ")+ "\\template.html "))
{
String oneline;
//读取指定的HTML文件模板
while((oneline=sr.ReadLine())!=null)
{
strhtml.Append(oneline);
}
//sr.Close;
}
}
catch(Exception err)
{
//输出异常
Response.Write(err.ToString());
}
//为标记数组赋值
newContent[0]=this.TextBox1.Text;//标题
newContent[1]= "BackColor= '#cccfff ' ";//背景色
newContent[2]= "#ff0000 ";//字体颜色
newContent[3]= "100px ";//字体大小
newContent[4]=this.TextBox2.Text;//主要内容
//根据上面新得内容生成html文件
try
{
//指定要生成的html文件
string fname=Server.MapPath( "createHTML ")+ "\\ "+DateTime.Now.ToString( "yyyymmddhhmmss ")+ ".liping19851014 ";//这里后缀可以随便改
//替换html模板文件中里的标记为新的内容
for(int i=0;i <5;i++)
{
strhtml.Replace( "$htmlkey[ "+i+ "] ",newContent[i]);
}
//创建文件信息对象
FileInfo finfo=new FileInfo(fname);
//以打开或者写入的形式创建文件流
using(FileStream fs=finfo.OpenWrite())
{
//根据上面创建的文件流创建写数据流
StreamWriter sw=new StreamWriter(fs,System.Text.Encoding.GetEncoding( "GB2312 "));
//把新的内容写到创建的html页面中
sw.WriteLine(strhtml);
sw.Flush();
sw.Close();
}
//设置超级连接的属性
this.HyperLink1.Text=DateTime.Now.ToString( "yyyymmddhhmmss ")+ ".html ";
this.HyperLink1.NavigateUrl= "createHTML/ "+DateTime.Now.ToString( "yyyymmddhhmmss ")+ ".liping19851014 ";//这里后缀可以随便改
}
catch(Exception err)
{
Response.Write(err.ToString());
}
}
最后是模板页:
template.html
<!DOCTYPE HTML PUBLIC "-/