读书人

请大家帮忙实现一个最简单的 URL 重写

发布时间: 2012-01-18 00:23:26 作者: rapoo

请大家帮忙实现一个最简单的 URL 重写。
用 VB 语法实现,在网上找了份代码,但是是 C# 的,搞了半天也没有搞定,请大家帮忙把下面代码转成 VB 的。
------------------------------------------

using System;
using System.IO;
using System.Web;
using System.Web.UI;

namespace ZDIL.URLRewriter
{
/**//// <summary>
/// URL重写
/// </summary>
public class RewriterFactoryHandler : IHttpHandlerFactory
{
/**//// <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)
{
string sendToUrl = url; //地址栏里面的地址
string filePath = pathTranslated;

string sendToURLString = "/user_web/test.aspx "; //真正要访问的页面
string queryString = " "; //参数。比如 ?id=123

filePath = context.Server.MapPath(sendToURLString); //物理地址

//这句最重要了。转向了。
context.RewritePath(sendToURLString, String.Empty, queryString);

//这个还没有弄明白 :)
return PageParser.GetCompiledPageInstance(url, filePath, context);
}

public virtual void ReleaseHandler(IHttpHandler handler)
{ //这个也不懂了
}
}
}



[解决办法]
Public Overridable Function GetHandler(ByVal context As HttpContext, ByVal requestType As String, ByVal url As String, ByVal pathTranslated As String) As IHttpHandler


Dim inputFile As String = pathTranslated
Dim path As String = "/user_web/test.aspx "
Dim queryString As String = " "
inputFile = context.Server.MapPath(path)
context.RewritePath(path, String.Empty, queryString)
Return PageParser.GetCompiledPageInstance(url, inputFile, context)
End Function


Public Overridable Sub ReleaseHandler(ByVal handler As IHttpHandler)
End Sub





[解决办法]
up
[解决办法]
顶一下。。
[解决办法]
using replace with imports

读书人网 >asp.net

热点推荐