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>大虾们帮帮忙呀 本机运行不行呢
解决方案 »
- asp,session简单计算器 一
- 母版页上的控件 在内容页是子文件夹内的页时 无法执行javascript?
- 在密码输入框中,为何我输入密码后,点击别的输入控件,在postback后,密码输入框的密码就没了 ?
- 如何动态添加 radiobuttonlist??
- 发包 解包
- Web开发中,水晶报表打印的控制问题(挑战)!急用!
- ★★★★★★做一个友情连接显示版块,遇到个问题★★★★★★
- 框架顶不住了!
- 急求webservice远程引用时无法下载**.asmx?wsdl的问题
- 没见过的问题??各位高手,思归大侠请进!!!
- 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]