Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
How to pass special character in query string in .Net core API?

Net core application. I have one GET api as below:

        [HttpGet]
        [Route("configId={configId}&quoteId={quoteId}"), EnableQuery()]
        public async Task<IEnumerable<Scenario>> GetScenario(string configId, int quoteId)
        {
            var result = await configScenarioService.GetScenarioAsync(configId, quoteId);
            if (result.IsSuccess)
            {
                return result.scenarioResults;
            }
            return new List<Scenario>();
        }

I am trying to hit from Postman as below:

https://localhost:44362/api/v1/Scenario/configId=JBEL+ASS_60_SG_5.2-145_MY21_T102.5_25y&quoteId=236

Unfortunately, this is giving 404 error. Maybe the '+' sign is causing the issue. After looking into some documentation, I tried as below:

1. https://localhost:44362/api/v1/Scenario/configId="+ encodeURIComponent(BEL+ASS_60_SG_5.2-145_MY21_T102.5_25y) +"&quoteId=236

This didn't work for me and still gave a 404 error.

How can this be fixed?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Try this

[HttpGet]
        [Route, EnableQuery()]
        public async Task<IEnumerable<Scenario>> GetScenario([FromQuery(Name = "configId")]string configId, [FromQuery(Name = "quoteId")]int quoteId)
        {
about 4 years ago · Juan Pablo Isaza Report

0

since you have + sign you have to encode your url, for + url encoded is %2B https://www.w3schools.com/tags/ref_urlencode.asp

..../Scenario?configId=JBEL%2BASS_60_SG_5.2-145_MY21_T102.5_25y&quoteId=236

and since you have 404 you have to fix an action route too

[Route("~/api/v1/Scenario")]
 public async Task<IEnumerable<Scenario>> GetScenario([FromQuery] string configId, [FromQuery] int quoteId)
about 4 years ago · Juan Pablo Isaza Report

0

Then try this:

[ApiController]
[Route("api/v1/[controller]/[action]")]
public class YourController : ControllerBase
{
    //... ctor and your other stuff

    [HttpGet("{configId}/{quoteId}", Name = "Scenario")]
    [ProducesResponseType(typeof(IEnumerable<Scenario>)]
    public async Task<ActionResult<IEnumerable<Scenario>>> GetScenario(string configId, string quoteId)
    {
        
    }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!