Wednesday 28 November 2018

Redirect web service error to the custom error page in asp.net using Globle.asax and web.config file

////////////////////////   web.config file

  <!--<customErrors mode="On" defaultRedirect="~/Error-page"> </customErrors>-->

--------------------------------------------------
<system.web>
    <webServices>
      <protocols>
        <remove name="Documentation"/>
      </protocols>
    </webServices>
   </system.web>
--------------------------------------------------
  <system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="Redirect">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="~/Path/Error-page"
       responseMode="Redirect" />
      <remove statusCode="403" subStatusCode="-1" />
      <error statusCode="403" prefixLanguageFilePath="" path="~/Path/Error-page"
       responseMode="Redirect" />
      <remove statusCode="405" subStatusCode="-1" />
      <error statusCode="405" prefixLanguageFilePath="" path="~/Path/Error-page"
       responseMode="Redirect" />
    </httpErrors>
</system.webServer>



////////////////////////   web.config file


protected void Application_Error(object sender, EventArgs e)
    {
        Exception exception = Server.GetLastError();
        Response.Clear();

        HttpException httpException = exception as HttpException;

        if (httpException != null)
        {
            string action;

            switch (httpException.GetHttpCode())
            {
                case 404:
                    // page not found
                    action = "~/Error-page";
                    break;
                case 500:
                    // server error
                    action = "~/Error-page";
                    break;
                default:
                    action = "~/Error-page";
                    break;
            }

            // clear error on server
            Server.ClearError();
            Response.Redirect("~/Error-page");
        }
    }

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...