0

I want to remove ".aspx" from my web appliaction url. also I have using webservices.

If I use below code web services is not working.

Global.asax

protected void Application_BeginRequest(object sender, EventArgs e)
{
      String WebsiteURL = Request.Url.ToString();
      String[] SplitedURL = WebsiteURL.Split('/');
      String[] Temp = SplitedURL[SplitedURL.Length - 1].Split('.');

      // This is for aspx page
      if (!WebsiteURL.Contains(".aspx") && Temp.Length == 1)
      {
          if (!string.IsNullOrEmpty(Temp[0].Trim()))

              Context.RewritePath(Temp[0] + ".aspx");
      }
}

for Eg:-

Actual page is DEFAULT.aspx, but I want to show DEFAULT in address bar. So I used Global.asax to remove (.aspx). It's working fine. but Web service is not working(Default.asmx)

1
  • 1
    I'd consider using the URLRewrite module for IIS. Not necessarily the easiest to use, but very powerful and will do what I believe you want Commented Jun 20, 2016 at 7:22

1 Answer 1

2

There is a module that will handle this for you without having to directly manipulate the urls, as described here: http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx.


Install the package, Microsoft.AspNet.FriendlyUrls.

In your RouteConfig, the extensionless urls are enabled using:

routes.EnableFriendlyUrls();

You can generate friendly urls using extension methods, for example, to generate /Foo/bar/34, you can use:

<a href="<%: FriendlyUrl.Href("~/Foo", "bar", 34) %>">Click me</a>
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.