Web API 404 Not found error after chaning from HTTP to HTTPS in ASP.Net MVC

Last Reply 6 months ago By Mudassar

Posted 6 months ago

Hi All,

Please help me to resolve this issue.

we a have website like http://abc.com recently it changed to https://abc.com in iis at webserver.

 

Now the problem is website not working properly, web api's not loading(not getting json response) on https 

it's redirecting 404 not found 

please help me to this.

 

Thanks in Advance.


Posted 6 months ago

Hi Dharmendr,

 

Thanks for your reply, i was checked the provided solution but it's not working,and also tried different ways to resolve the issue, am not able to do this.

 tried with below filter in webApiconfig.cs file, still getting the 404 response,and the json api is perfectly working on postman site am getting the json response.

please help me to resolve this.

Thanks

public class RequireHttpsAttribute : AuthorizationFilterAttribute
        {
            public override void OnAuthorization(HttpActionContext actionContext)
            {
                var request = actionContext.Request;
                if (request.RequestUri.Scheme != Uri.UriSchemeHttps)
                {
                    HttpResponseMessage response;
                    UriBuilder uri = new UriBuilder(request.RequestUri);
                    uri.Scheme = Uri.UriSchemeHttps;
                    uri.Port = 443;
                    string body = string.Format("<p>The resource can be found at <a href=\"{0}\">{0}</a>.</p>",
                        uri.Uri.AbsoluteUri);
                    if (request.Method.Equals(HttpMethod.Get) || request.Method.Equals(HttpMethod.Head))
                    {
                        response = request.CreateResponse(HttpStatusCode.Found);
                        response.Headers.Location = uri.Uri;
                        if (request.Method.Equals(HttpMethod.Get))
                        {
                            response.Content = new StringContent(body, Encoding.UTF8, "text/html");
                        }
                    }
                    else
                    {
                        response = request.CreateResponse(HttpStatusCode.NotFound);
                        response.Content = new StringContent(body, Encoding.UTF8, "text/html");
                    }

                    actionContext.Response = response;
                }
            }
        }

 


Posted 6 months ago

This is something we cannot properly help through Forums.

We can only suggest links.

https://forums.asp.net/t/2083908.aspx?Calls+from+HTTPS+website+to+HTTP+Web+API+is+NOT+working