asp.net URLRewriter url重写本机怎么配置
只是配置web.config 吗 ?还要不要写什么代代码呀 这个我web.config里面配置的 看哈有错没的 反正运行就是出不来
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/r_(.[\d]*).html</LookFor>
<SendTo>~/logs.aspx?id=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
</httpHandlers>大虾们帮帮忙呀 本机运行不行呢
只是配置web.config 吗 ?还要不要写什么代代码呀 这个我web.config里面配置的 看哈有错没的 反正运行就是出不来
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/r_(.[\d]*).html</LookFor>
<SendTo>~/logs.aspx?id=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
</httpHandlers>大虾们帮帮忙呀 本机运行不行呢
解决方案 »
- 进来座座
- 请问如何在b/s中做计划任务
- 我装了asp.net ajax 新建网站里面有两个选项分别是什么意思啊?
- 一个存储过程 请这会儿不忙的人看看有什么毛病
- 请教各位,我为何在DataGrid的DataGrid1_ItemCreated事件中动态加的按钮不执行事件
- 如何取得iframe里面的内容,需跨域。
- asp.net中,GridView显示数据 并且待搜索功能,把搜索后的结果重新显示在GridView 中 用ObjectDataSource数据控件
- “Configuration”不明确,从命名空间或类型“System.Web, System”导入。
- Repeater里面怎么隐藏列?在线等待,立马给分...
- 我想知道学了asp.Net后去开发三层构架的程序,还要不要去学COM,MFC之类的?请给我点意见!谢谢
- System.Data.OleDb.OleDbDataAdapter 內部錯誤: 無效的參數存取子: 1 BADBINDINFO
- 獲取listbox的值
我的web.config配置是<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>http://(\d+)\.xxx\.xxx\.cn/default\.aspx</LookFor>
<SendTo>~/gonggao/ggview.aspx?ggid=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
</httpHandlers>主要重写了RewriterFactoryHandler.cs里面的下面的内容来实现的,你可以把重写域名的注释掉,把重写url的启用 然后编译在引用试试看。/// <summary>
/// GetHandler is executed by the ASP.NET pipeline after the associated HttpModules have run. The job of
/// GetHandler is to return an instance of an HttpHandler that can process the page.
/// </summary>
/// <param name="context">The HttpContext for this request.</param>
/// <param name="requestType">The HTTP data transfer method (<b>GET</b> or <b>POST</b>)</param>
/// <param name="url">The RawUrl of the requested resource.</param>
/// <param name="pathTranslated">The physical path to the requested resource.</param>
/// <returns>An instance that implements IHttpHandler; specifically, an HttpHandler instance returned
/// by the <b>PageParser</b> class, which is the same class that the default ASP.NET PageHandlerFactory delegates
/// to.</returns>
public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
context.Trace.Write("RewriterFactoryHandler", "Entering RewriterFactoryHandler");
//string sendToUrl = url;url重写
string sendToUrl = context.Request.Url.AbsolutePath;//域名重写 string filePath = pathTranslated;
// get the configuration rules
RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules;
// iterate through the rules
for (int i = 0; i < rules.Count; i++)
{
// Get the pattern to look for (and resolve its URL)
string lookFor = "^" + RewriterUtils.ResolveUrl(context.Request.ApplicationPath, rules[i].LookFor) + "$"; // Create a regular expression object that ignores case...
Regex re = new Regex(lookFor, RegexOptions.IgnoreCase); // Check to see if we've found a match
//if (re.IsMatch(url))//URL重写
if (re.IsMatch(context.Request.Url.AbsolutePath))//域名重写
{
// do any replacement needed
//sendToUrl = RewriterUtils.ResolveUrl(context.Request.ApplicationPath, re.Replace(url, rules[i].SendTo));//url重写
sendToUrl = RewriterUtils.ResolveUrl(context.Request.ApplicationPath, re.Replace(context.Request.Url.AbsolutePath, rules[i].SendTo));//域名重写 // log info to the Trace object...
context.Trace.Write("RewriterFactoryHandler", "Found match, rewriting to " + sendToUrl); // Rewrite the path, getting the querystring-less url and the physical file path
string sendToUrlLessQString;
RewriterUtils.RewriteUrl(context, sendToUrl, out sendToUrlLessQString, out filePath); // return a compiled version of the page
context.Trace.Write("RewriterFactoryHandler", "Exiting RewriterFactoryHandler"); // log info to the Trace object...
return PageParser.GetCompiledPageInstance(sendToUrlLessQString, filePath, context);
}
}
// if we reached this point, we didn't find a rewrite match
context.Trace.Write("RewriterFactoryHandler", "Exiting RewriterFactoryHandler"); // log info to the Trace object...
return PageParser.GetCompiledPageInstance(url, filePath, context);
}
可执行文件:c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll
扩展名:.html
动作:限制为 GET,HEAD,POST,DEBUG
脚本引擎:选中
确认文件是否存在:不选
RewriterFactoryHandler.cs 这个类在那呢?
[email protected] 谢谢哈
在HttpModels这个地方添加上<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
定义规则<RewriterRule>
<LookFor>~/Shop/(\d+)</LookFor>
<SendTo>~/Shop/default.aspx?SId=$1</SendTo>
</RewriterRule>
然后你在页面写链接的时候~/shop/3他就解释到了~/shop/default.aspx?SId=3
这个里面没有name属性吧
能不能也发一个给我哦 谢谢啦 [email protected]