ApiController returns 404 when ID contains period

前端 未结 3 1341
别跟我提以往
别跟我提以往 2020-11-27 19:35

I have an ApiController and I want to use email addresses as the ID parameter for requests:

// GET api/employees/email@address.com
public CompactEmployee Get         


        
相关标签:
3条回答
  • 2020-11-27 19:48

    This is what worked for me:

    I was running on targetFramework = 4.6.1. I have upgraded to 4.6.2 and added this in web.config:

    <system.web>
            <customErrors mode="Off"/>
            <compilation debug="true" targetFramework="4.6.2"/>
            <!-- This will allow to search for stuff that contains . & etc.-->
            <httpRuntime targetFramework="4.6.2" maxRequestLength="100000" maxUrlLength="2048" relaxedUrlToFileSystemMapping="true" requestPathInvalidCharacters=""/>
      </system.web>
    

    The requestPathInvalidCharacters="" is to be able to have stuff like & etc in URI, in encoded form, of course.

    0 讨论(0)
  • 2020-11-27 19:55

    Check your IIS settings:

    Home Directory -> Configuration

    Edit the .aspx application extension and ensure that the setting Verify that file exists is off.

    UPDATE

    I've just tested with a default MVC4 Web API project

    URL: http://localhost:10983/api/values/cool@email.com

    Action in ValuesController:

    public string Get(string id)
    {
        return id;
    }
    

    This was the response:

    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">cool@email.com</string>
    
    0 讨论(0)
  • Would adding a trailing slash work for your scenario?

    http://localhost:33021/api/employees/employee@company.com/
    
    0 讨论(0)
提交回复
热议问题