Asp.net Mvc Error 400
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about aspnet mvc nuget hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Aspnet Mvc Source
Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each aspnet mvc tutorial other. Join them; it only takes a minute: Sign up MVC Controller return a bad request? up vote 6 down vote favorite 1 I was wondering if it was possible to return a bad request with content from an aspnet mvc 5 MVC Controller? The only way I have been able to do this is to throw HttpException however here I can't set any content. Tried this approach to but for some odd reason I am always getting an OK back. Is it possible to do this? public class SomeController : Controller { [HttpPost] public async Task
Aspnet Mvc 4
Aug 22 at 10:14 ekad 9,695102635 asked Jul 8 '15 at 8:17 Dr Schizo 1,1871925 1 Try return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad Request"); –greenhoorn Jul 8 '15 at 8:22 add a comment| 5 Answers 5 active oldest votes up vote 4 down vote Set the Http status code to bad request and use Content method to send your content along with response. public class SomeController : Controller { [HttpPost] public async Task
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more aspnet mvc cms about Stack Overflow the company Business Learn more about hiring developers or posting ads aspnet mvc 6 with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow
Aspnet Mvc 3
is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ASP.NET MVC 400 Bad Request with URL restricted characters such as % http://stackoverflow.com/questions/31287090/mvc-controller-return-a-bad-request up vote 8 down vote favorite 2 I'm developing an ASP.NET MVC 3 blog application using VS10 and its asp.net development server, and today I encountered the "HTTP Error 400 - Bad Request" error when I request on a blog post with a slug that has these chars "doesn%25e2%2580%2599t" in it. I thought the "%" char is allowed in the URL, for example, on StackOverflow you have http://stackoverflow.com/questions/tagged/c%23 and http://stackoverflow.com/questions/5058863/asp-net-mvc-400-bad-request-with-url-restricted-characters-such-as this link shows you all questions tagged with c#. So what is the difference for my URL and how do you fix it? Could anyone explain. Thank you so much! url asp.net-mvc-3 bad-request share|improve this question asked Feb 20 '11 at 18:00 fanray 4,3441665102 add a comment| 1 Answer 1 active oldest votes up vote 7 down vote accepted You may checkout the following blog post in which Scott Hanselman explains how you could enable special characters in urls. Don't get too fancy though, it's still pretty limited. You might also checkout the following post to see how this is implemented on SO (the post is pretty old and things might have changed since but still good source for information). share|improve this answer answered Feb 20 '11 at 18:03 Darin Dimitrov 688k15924972374 Thank you Darin for pointing out to me those info, they are very helpful. I have upvoted you and marked you as answer. –fanray Feb 20 '11 at 19:09 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By
will show its own error page for resources that are not served by ASP.NET. EDIT: Sorry for the wrong answer. I have XP machine currently that shows 404 for % sign so couldn't verify above. Searching over internet, I found that it's simply not possible to display custom error page for 400 status code. See this question from server fault for more information. Hi VinayC, thanks for the quick response, but looks like this solution doesn't work for the requests ending with %, are you sure it works? @Andy, appologies for wrong answer. Apparently, its not possible to have custom error page for 400 status code. See this link for more info: serverfault.com/questions/257680/ ASP.NET MVC: How to handle 400 bad request error when url end with % -... View More at http://stackoverflow.com/questions/7511239/asp-net-mvc-how-to-han... Who said not possible? Response.TrySkipIisCustomErrors = true;