2012-03-12 50 views
0

那么我尝试简单ASP.NET URL重写功能不正常

我有一个像含

public partial class WebApi : System.Web.UI.Page 
{ 

    [WebMethod] 
    public static GetImageResult GetRandomImage() 
    ... 

我已经添加了以下为“的Global.asax.cs”页一个简单的Web服务(的Application_BeginRequest)

string absolutePath = Request.Url.AbsolutePath.Substring(1); 

if (absolutePath.StartsWith("WebApi/", StringComparison.OrdinalIgnoreCase)) 
{ 
    Context.RewritePath("/WebApi.aspx/" + absolutePath.Substring(7)); 
} 

但asp.net似乎也与此功能不会被调用和JavaScript只是报告“不允许的方法”的问题。

有什么更多我必须做的这项工作?

+1

您应该看看IIS UrlWrite模块。 http://www.iis.net/download/URLRewrite – Phill 2012-03-12 22:44:05

+0

@Phill IIS Rewrite和ASP.net Rewrite有什么区别,它将如何解决我的问题? – Peter 2012-03-13 09:20:29

+0

因为IIS重写模块会在它到达您的应用程序(.NET或PHP或其他)之前重写URL,并且在GUI窗口中设置和测试会更容易,您可以在其中编写正则表达式和示例url来测试用。 – Phill 2012-03-13 11:15:14

回答

1

我推荐使用IIS Url重写模块,而不是试图推出自己的。它会在请求到达你的应用程序之前拦截请求,并提供一个GUI,供你编写和测试你的URL的正则表达式。

http://www.iis.net/download/URLRewrite