500 Internal Server Error
jQuery Ajax not calling webmethod after url rewriting
WebService.asmx
contain following colde
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
-------------my jquery code -------------
<script type="text/javascript">
$(document).ready(function ()
{
$.ajax({
type: "POST",
url: 'WebService.asmx/HelloWorld',
data: {},
contentType: "application/json; charset=utf-8",
success: countItem
});
function countItem(data, status, xhr)
{
alert(data.d);
}
});
</script>
it is working fine but when i use url rewrite or url rooting it give error
original path
http://localhost:1388/WebSite15/WebService.asmx/HelloWorld
it will work
but after url rewrite or url rooting
http://localhost:1388/WebSite15/Products/WebService.asmx/HelloWorld
so it gives error
What I have tried:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// Code that runs on application startup
RegisterRoute(System.Web.Routing.RouteTable.Routes);
}
void RegisterRoute(System.Web.Routing.RouteCollection routes)
{
routes.Add("Products", new System.Web.Routing.Route("{Products}/{category}", new CategoryRouteHandler()));
}
public class CategoryRouteHandler : IRouteHandler
{
public CategoryRouteHandler() { }
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// AdventureWorksEntities awe = new AdventureWorksEntities();
string cat = requestContext.RouteData.Values["category"] as string;
string pageval = requestContext.RouteData.Values["Products"] as string;
//int catid = awe.ProductCategories.Where(x => x.Name == cat).FirstOrDefault().ProductCategoryID;
HttpContext.Current.Items["catid"] = cat;
if (pageval.ToLower().ToString().Trim() == "test")
{
return BuildManager.CreateInstanceFromVirtualPath("~/test1.aspx", typeof(Page)) as Page;
}
else
{
return BuildManager.CreateInstanceFromVirtualPath("~/Products.aspx", typeof(Page)) as Page;
}
// string vartualpath=BuildManager.CreateInstanceFromVirtualPath("~/Products.aspx", typeof(Page)).ToString();
//return BuildManager.CreateInstanceFromVirtualPath("~/category.aspx", typeof(Page)) as Page;
}
}