WebApi method with email address parameter returns 404 from HttpClient

前端 未结 4 1434
盖世英雄少女心
盖世英雄少女心 2021-01-01 10:32

I have a WebApi controller with a method that looks like such:

[HttpGet]
[AcceptVerbs(\"GET\")]
public HttpResponseMessage Run(string reportName, int someId,         


        
相关标签:
4条回答
  • 2021-01-01 11:04

    This is because IIS is trying to map special characters. Adding the following to the web.config should fix the issue:

    <system.webServer>  
         <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    

    More information here: http://www.iis.net/configreference/system.webserver/modules

    0 讨论(0)
  • 2021-01-01 11:12

    Adding the following to the web.config should not fix the complete issue:

    <system.webServer>  
         <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    

    The solution no longer works as an extra path segment is used in the uri for me. https://localhost:xxxx/user@domain.com does work

    https://localhost:xxxx/path/user@domain.com does not work

    I google around and around and i understood that it is an extension. (.cs gives a different error as .com) and finaly find this: ASP.net MVC4 WebApi route with file-name in it

    My solution was to add or change the following handler in the <handlers> section of your <system.webServer>:

    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" 
               path="*.*" 
               verb="*" 
               type="System.Web.Handlers.TransferRequestHandler" 
               preCondition="integratedMode,runtimeVersionv4.0" />
    

    or change the path to path=*@*.*

    0 讨论(0)
  • 2021-01-01 11:21

    You need a basic URL query.

    [Route("api/emails")]
    public HttpResponseMessage Run(string email) {...}
    
    GET api/emails?email=user@domain.com
    
    0 讨论(0)
  • 2021-01-01 11:27

    Just a quick thought... could the ".com" be causing the issue?

    0 讨论(0)
提交回复
热议问题