0

Well im trying a simple

i have a simple web service like page containing

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

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

i have added the following to "Global.asax.cs" (Application_BeginRequest)

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

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

but asp.net seems to have a problem with this the function is never called and javascript just reports "Method Not Allowed".

Is there some thing more i have to do to make this work?

6
  • 1
    You should take a look at the IIS UrlWrite Module. iis.net/download/URLRewrite Commented Mar 12, 2012 at 22:44
  • @Phill what is the difference between IIS Rewrite and ASP.net Rewrite and how would it solve my problem? Commented Mar 13, 2012 at 9:20
  • Because the IIS Rewrite Module will rewrite the URL before it gets to your application (.NET or PHP or anything) and will be much easier to setup and test in the GUI window which allows you to write a regular expression and sample url to test with. Commented Mar 13, 2012 at 11:15
  • Also now that .NET has Routing, and IIS has UrlRewrite Module, any custom rewriting functionality like you're trying to do... is pretty much void now. :( (it really is easy with IIS Rewrite Module) Commented Mar 13, 2012 at 11:16
  • @Phill ok ill try it when i get home! Commented Mar 13, 2012 at 11:19

1 Answer 1

1

I recommend using IIS Url Rewrite Module rather than trying to roll your own. It will intercept the request before it gets to your application, and provides a GUI for you to write and test the regular expression against your urls.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.