.NET下如何实现伪静态,服务器不在本地能实现吗? 在网上看了好多的关于伪静态的技术,好像都是要设置IIS,但是现在有一个问题就是服务器不在本地,有办法实现吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在你的IIS上新建一个网站指向你的项目(你在服务器怎么建,这里也是一样的),然后再找到C:\WINDOWS\system32\drivers\etc\hosts,用文本打开添加一个192.168.1.2 www.hao.com(你计算机的IP,你新建网站的站点) 与服务器商联系context.rewriterpath重写路径 <?xml version="1.0"?><configuration> <configSections> <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" /> </configSections> <system.web> <httpModules> <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/> </httpModules> </system.web> <rewriter> <rewrite url="~/products/books.aspx" to="~/products.aspx?category=books" /> <rewrite url="~/products/CDs.aspx" to="~/products.aspx?category=CDs" /> <rewrite url="~/products/DVDs.aspx" to="~/products.aspx?category=DVDs" /> </rewriter> </configuration> http://www.chinaz.com/Program/.NET/0410H2112009.html 可以实现。其实就是重写url呀。原理就是当一个用户请求你的1.html地址,你的站点程序在处理这个请求之前将1.html地址改为了a.aspx?id=1。然后处理程序也就是a.aspx去执行就可以了。不修改iis或加载任何dll的方法当然可以,如下:1、 如何在请求前将地址1.html改成a.aspx?id=1呢。在Global.asax文件里的Application_BeginRequest方法里做就行了:void Application_BeginRequest(object sender, EventArgs e) { //URL重写 string url = HttpContext.Current.Request.Path; int idx = url.IndexOf(".html"); if (idx != -1) { int lastidx = url.LastIndexOf('/'); HttpContext.Current.RewritePath(string.Concat(url.Substring(0, lastidx), "/a.aspx?id=", url.Substring(lastidx + 1, idx - lastidx - 1))); } }以上只是个示例,当然你可以把重写路径的方法写的非常复杂,例如支持正则表达式替换,支持缓存路径......你想怎么改都行。呵呵~ .net url转向判断问题 下面代码什么意思啊 请问怎样增加IIS Serve中的站点? 类型转换错误,急!!!!! 在自定义控件中放一个DropDownList 然后数据绑定 问怎么设置这个控件的属性用来获取DropDownList选定项 读取Excel表格问题 正则表达式如何匹配字符串最后一位是空或者是"/" 请问在引用项目中如何添加LINQ对象 help:文件上传问题--文件大小<4M的时候就没有问题,当>4M时就出错了,而且什么提示也没有,就出现“网页无法显示”--在线 这个oa在线例子我没权看,谁能帮我? 如何调用js类 如何解决保存时页面的两次刷新?
context.rewriterpath重写路径
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
</system.web> <rewriter>
<rewrite url="~/products/books.aspx" to="~/products.aspx?category=books" />
<rewrite url="~/products/CDs.aspx" to="~/products.aspx?category=CDs" />
<rewrite url="~/products/DVDs.aspx" to="~/products.aspx?category=DVDs" />
</rewriter>
</configuration>
1、 如何在请求前将地址1.html改成a.aspx?id=1呢。在Global.asax文件里的
Application_BeginRequest方法里做就行了:void Application_BeginRequest(object sender, EventArgs e)
{
//URL重写
string url = HttpContext.Current.Request.Path;
int idx = url.IndexOf(".html");
if (idx != -1)
{
int lastidx = url.LastIndexOf('/');
HttpContext.Current.RewritePath(string.Concat(url.Substring(0, lastidx), "/a.aspx?id=", url.Substring(lastidx + 1, idx - lastidx - 1)));
}
}以上只是个示例,当然你可以把重写路径的方法写的非常复杂,例如支持正则表达式替换,支持缓存路径......你想怎么改都行。呵呵~