1

I have a simple webservice with two webmethods.

https://localhost/Sub/WS/Dash.asmx/test_error_methodnameXXXXXXXXXXX

When i call the above request from the browser. It gives me a error message saying something like this:-

System.InvalidOperationException: test_error_methodnameXXXXXXXXXXX Web Service method name is not valid. at System.Web.Services.Protocols.HttpServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

I tried to make a work around with the help of web.config file as follows:-

<system.web>    
    <customErrors mode="On" defaultRedirect="~/Sub/ErrorPage/AppErrors.aspx">
       <error statusCode="500" redirect="500.aspx" />
    </customErrors>       
</system.web>

Here in this case, the redirection is not happening to the 500.aspx page or the AppErrors.aspx. I can see the change happening, if i change the value in the mode attribute..

Thanks.

2 Answers 2

2

I found the fix with the help of web.config.

Stick

<diagnostics suppressReturningExceptions="true"/>  
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to either change what this error says or redirect it to a different page? This currently gives me a blank page that just says "An error occurred on the server." I would like to redirect that to a custom error page if possible.
0

To call web methods for javascript you should mark your webservice as a script service.

[ScriptService]
public class MyService : WebService
{

}

Include a reference to it in script manager:

<asp:ScriptManager ID="_scriptManager" runat="server">
  <Services>
    <asp:ServiceReference Path="Dash.asmx" />
  </Services>
</asp:ScriptManager>

Call it in js

try {
    Dash.MyService.ErrorMethodName();
}
catch(exception){
    //handle exception
}
finally {
    //round up
}

7 Comments

It is already marked as scriptservice. That is fine. The problem i am facing is the handling of the InvalidOperationException message, when someone call the webservice method directly from the browser location bar..
the javascript try catch will help you there
But this thing is not called from client side... I want to make this change to give the appropriate message and thus to prevent the content spoofing from the malicious user. test_error_methodnameXXXXXXXXXXX does not exist in the web-service.
I tried with the help of web.config CustomErrors, but the redirection is not happening..
Redirection will not happen automatically, in case you detect an error in javascript, you will have to redirect yourself, by setting the location.href = CUSTOM_ERROR_URL
|

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.