ASP .NET Core Web API route dot in url causes 404 not found
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a problem of url routing in ASP.NET Core web api. When the URL contins dot (.) it returns 404 not found. For example,
http://localhost:9030/api/test/109/fake@email.com
The code that doesn't work with email but work with no dot
public class TestController : Controller{
{
[HttpGet]
[Route("{id:int}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet]
[Route("{id:int}/{name:alpha}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
However, this works
http://localhost:9030/api/test/getbyname/109/fake@email.com
public class TestController : Controller{
{
[HttpGet("GetById/{id}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet("GetByName/{id}/{name}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
How to solve that problem?
c# asp.net-core asp.net-core-webapi
add a comment |
I have a problem of url routing in ASP.NET Core web api. When the URL contins dot (.) it returns 404 not found. For example,
http://localhost:9030/api/test/109/fake@email.com
The code that doesn't work with email but work with no dot
public class TestController : Controller{
{
[HttpGet]
[Route("{id:int}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet]
[Route("{id:int}/{name:alpha}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
However, this works
http://localhost:9030/api/test/getbyname/109/fake@email.com
public class TestController : Controller{
{
[HttpGet("GetById/{id}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet("GetByName/{id}/{name}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
How to solve that problem?
c# asp.net-core asp.net-core-webapi
2
fake@email.com
would not be valid regardless. Did you forget to url encode the@
? urlencoder.org
– mjwills
Jan 3 at 12:05
No problem with @. The problem is dot (.). I'm using IIS 8.5
– derodevil
Jan 3 at 12:13
It may work, but you shouldn't be passing@
like that. You should url encode it.
– mjwills
Jan 3 at 12:21
add a comment |
I have a problem of url routing in ASP.NET Core web api. When the URL contins dot (.) it returns 404 not found. For example,
http://localhost:9030/api/test/109/fake@email.com
The code that doesn't work with email but work with no dot
public class TestController : Controller{
{
[HttpGet]
[Route("{id:int}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet]
[Route("{id:int}/{name:alpha}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
However, this works
http://localhost:9030/api/test/getbyname/109/fake@email.com
public class TestController : Controller{
{
[HttpGet("GetById/{id}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet("GetByName/{id}/{name}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
How to solve that problem?
c# asp.net-core asp.net-core-webapi
I have a problem of url routing in ASP.NET Core web api. When the URL contins dot (.) it returns 404 not found. For example,
http://localhost:9030/api/test/109/fake@email.com
The code that doesn't work with email but work with no dot
public class TestController : Controller{
{
[HttpGet]
[Route("{id:int}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet]
[Route("{id:int}/{name:alpha}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
However, this works
http://localhost:9030/api/test/getbyname/109/fake@email.com
public class TestController : Controller{
{
[HttpGet("GetById/{id}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet("GetByName/{id}/{name}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
How to solve that problem?
c# asp.net-core asp.net-core-webapi
c# asp.net-core asp.net-core-webapi
edited Jan 3 at 12:07
mjwills
16k52644
16k52644
asked Jan 3 at 12:02
derodevilderodevil
130112
130112
2
fake@email.com
would not be valid regardless. Did you forget to url encode the@
? urlencoder.org
– mjwills
Jan 3 at 12:05
No problem with @. The problem is dot (.). I'm using IIS 8.5
– derodevil
Jan 3 at 12:13
It may work, but you shouldn't be passing@
like that. You should url encode it.
– mjwills
Jan 3 at 12:21
add a comment |
2
fake@email.com
would not be valid regardless. Did you forget to url encode the@
? urlencoder.org
– mjwills
Jan 3 at 12:05
No problem with @. The problem is dot (.). I'm using IIS 8.5
– derodevil
Jan 3 at 12:13
It may work, but you shouldn't be passing@
like that. You should url encode it.
– mjwills
Jan 3 at 12:21
2
2
fake@email.com
would not be valid regardless. Did you forget to url encode the @
? urlencoder.org– mjwills
Jan 3 at 12:05
fake@email.com
would not be valid regardless. Did you forget to url encode the @
? urlencoder.org– mjwills
Jan 3 at 12:05
No problem with @. The problem is dot (.). I'm using IIS 8.5
– derodevil
Jan 3 at 12:13
No problem with @. The problem is dot (.). I'm using IIS 8.5
– derodevil
Jan 3 at 12:13
It may work, but you shouldn't be passing
@
like that. You should url encode it.– mjwills
Jan 3 at 12:21
It may work, but you shouldn't be passing
@
like that. You should url encode it.– mjwills
Jan 3 at 12:21
add a comment |
1 Answer
1
active
oldest
votes
Your problem is the
[Route("{id:int}/{name:alpha}")]
You are saying only accept alphabet characters which means a-z and A-Z not including any special characters. you are best using a regex to validate if it is always an email address.
try this
[Route("{id:int}/{name}")]
Thanks. It works now. This is the complete explanation docs.microsoft.com/en-us/aspnet/core/fundamentals/… and this is for custom constraints sample c-sharpcorner.com/article/creating-custom-routing-constraint
– derodevil
Jan 3 at 12:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021924%2fasp-net-core-web-api-route-dot-in-url-causes-404-not-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your problem is the
[Route("{id:int}/{name:alpha}")]
You are saying only accept alphabet characters which means a-z and A-Z not including any special characters. you are best using a regex to validate if it is always an email address.
try this
[Route("{id:int}/{name}")]
Thanks. It works now. This is the complete explanation docs.microsoft.com/en-us/aspnet/core/fundamentals/… and this is for custom constraints sample c-sharpcorner.com/article/creating-custom-routing-constraint
– derodevil
Jan 3 at 12:41
add a comment |
Your problem is the
[Route("{id:int}/{name:alpha}")]
You are saying only accept alphabet characters which means a-z and A-Z not including any special characters. you are best using a regex to validate if it is always an email address.
try this
[Route("{id:int}/{name}")]
Thanks. It works now. This is the complete explanation docs.microsoft.com/en-us/aspnet/core/fundamentals/… and this is for custom constraints sample c-sharpcorner.com/article/creating-custom-routing-constraint
– derodevil
Jan 3 at 12:41
add a comment |
Your problem is the
[Route("{id:int}/{name:alpha}")]
You are saying only accept alphabet characters which means a-z and A-Z not including any special characters. you are best using a regex to validate if it is always an email address.
try this
[Route("{id:int}/{name}")]
Your problem is the
[Route("{id:int}/{name:alpha}")]
You are saying only accept alphabet characters which means a-z and A-Z not including any special characters. you are best using a regex to validate if it is always an email address.
try this
[Route("{id:int}/{name}")]
edited Jan 3 at 12:27
answered Jan 3 at 12:15
Reece TaylorReece Taylor
4614
4614
Thanks. It works now. This is the complete explanation docs.microsoft.com/en-us/aspnet/core/fundamentals/… and this is for custom constraints sample c-sharpcorner.com/article/creating-custom-routing-constraint
– derodevil
Jan 3 at 12:41
add a comment |
Thanks. It works now. This is the complete explanation docs.microsoft.com/en-us/aspnet/core/fundamentals/… and this is for custom constraints sample c-sharpcorner.com/article/creating-custom-routing-constraint
– derodevil
Jan 3 at 12:41
Thanks. It works now. This is the complete explanation docs.microsoft.com/en-us/aspnet/core/fundamentals/… and this is for custom constraints sample c-sharpcorner.com/article/creating-custom-routing-constraint
– derodevil
Jan 3 at 12:41
Thanks. It works now. This is the complete explanation docs.microsoft.com/en-us/aspnet/core/fundamentals/… and this is for custom constraints sample c-sharpcorner.com/article/creating-custom-routing-constraint
– derodevil
Jan 3 at 12:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021924%2fasp-net-core-web-api-route-dot-in-url-causes-404-not-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
fake@email.com
would not be valid regardless. Did you forget to url encode the@
? urlencoder.org– mjwills
Jan 3 at 12:05
No problem with @. The problem is dot (.). I'm using IIS 8.5
– derodevil
Jan 3 at 12:13
It may work, but you shouldn't be passing
@
like that. You should url encode it.– mjwills
Jan 3 at 12:21