要求如下:
只修改web.config 和 建立类不修改iis请大虾们帮我找个例子 。如果是*.aspx 转换成 *.html 用不用修改iis配置
只修改web.config 和 建立类不修改iis请大虾们帮我找个例子 。如果是*.aspx 转换成 *.html 用不用修改iis配置
解决方案 »
- 一个显示的问题
- oledb连接ACCESS的怪问题
- 关于DataGrid的属性的使用
- 1、请问NHibernate+spring.net+atlas和ibatis.net+castle+magicajax哪个搭配好呀?
- Web User Control里面有一个按钮,按钮的点击事件就在Control的代码文件里,这个事件为什么得不到执行?
- 使用asp.net开发wap网站问题
- 这个错误怎么解决?
- 关于自定义配置文件的读写问题
- 请问如何弹出一个模式窗口?能否给一段代码学习学习?
- codebehind里动态生成的超链接列,如何设置多个参数?
- 请问在javascript中xml读取的问题
- parseHTML属于哪个类
void Application_AcquireRequestState(object sender, EventArgs e)
{
//禁止匿名用户访问Manager目录
if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
{
Response.Redirect(Request.RawUrl.ToLower().Replace(".aspx",".html"));//用Response.Redirect可以改变地址栏进行url重定向
//Context.RewritePath(Request.RawUrl.ToLower().Replace(".aspx", ".html"));//Context.RewritePath不改变地址栏的url重写
}
}
你这是不负责任,好好看看global的作用吧
去GOOGLE搜“Httpmodule 实现 URL重写”
<%@ Application Language="C#" CodeFile="Global.asax.cs" Inherits="Global" %><script runat="server">
</script>global.asax.cs文件:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Web.Caching;
void Application_BeginRequest(object sender, EventArgs e)
{
if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
{
Context.RewritePath(Request.RawUrl.ToLower().Replace(".aspx", ".html"));//Context.RewritePath不改变地址栏的url重写
}
}//或者使用下面的代码
//void Application_AcquireRequestState(object sender, EventArgs e)
//{
// if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
// {
// Response.Redirect(Request.RawUrl.ToLower().Replace(".aspx",".html"));//用Response.Redirect可以改变地址栏进行url重定向
// }
// }
{
void Application_BeginRequest(object sender, EventArgs e)
{
if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
{
Context.RewritePath(Request.RawUrl.ToLower().Replace(".aspx", ".html"));//Context.RewritePath不改变地址栏的url重写
}
}//或者使用下面的代码
//void Application_AcquireRequestState(object sender, EventArgs e)
//{
// if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
// {
// Response.Redirect(Request.RawUrl.ToLower().Replace(".aspx",".html"));//用Response.Redirect可以改变地址栏进行url重定向
// }
// }}
补充上面
在本篇将讲述利用自定义IHttpModule来实现URL地址重写。
第二步,设置web.config文件:<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
</configSections> 把上面这段代码加入<configuration>和</configuration>之间,然后把下面的代码加入<system.web>和</system.web> 之间: <httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
</httpModules> 接下来的任务就是设置具体哪些页面url重写了,具体代码写在<configuration>和</configuration>之间,如:
<RewriterConfig>
<Rules>
<!-- 新闻 -->
<RewriterRule>
<LookFor>~/news_([0-9]*).html</LookFor>
<SendTo><![CDATA[~/news.aspx?newsid=$1]]></SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>第三步:在页面程序中可以这样写:
<a href="news_<%=newsid%>.html" target="_blank">新闻标题</a>
不然 你们试试 把你们的项目放在iis里 不配置映射的话 他就不出来。用 html页试