Centralised 404 error handling in ASP NET Core

  Рет қаралды 79,154

kudvenkat

kudvenkat

Күн бұрын

Пікірлер: 49
@ben5676755
@ben5676755 2 жыл бұрын
Life saver for a needed quick fix. Appreciate it.
@pollo5422
@pollo5422 5 жыл бұрын
Thanks a lot man!!!!.... The best .net core videos.
@duytran5670
@duytran5670 4 жыл бұрын
Thanks for video. Nice!
@TommiLipponen
@TommiLipponen 5 жыл бұрын
I just keep getting this "Hello World!" from Startup.cs last method. app.Run(async (context) => {await context.Response.WriteAsync("Hello World"); No 404 messages, no NotFound views, nothing, just Hello World! I am using ASP NET Core 3.1.1 and VS 16.4.3. Enviroment variable has no effect, any error gives me Hello World!. Kind of funny aigh. Edit; When i type url Error/404 it goes to that page, otherwise not. I have tried changes mentioned in previous comments too. Edit1; I got it; had to disable the last "Hello World" method. The request went down there through the pipeline without returning to if else block. Great tutorial Mr.Kudvenkat Sir.
@nithinreddykotta9680
@nithinreddykotta9680 4 жыл бұрын
Yes, I got the same problem and resolved it by disabling the last middleware which shows "Hello world" Thanks. But I have faced an another problem when i change my environment to production sizes and alignment have changed can anyone let me know. Thanks.
@SoftwareDeveloperAspNet
@SoftwareDeveloperAspNet 3 жыл бұрын
@@nithinreddykotta9680 yes please do let me know about the same if you found solution. After changing aspnetcore_enviornment value to production design changes
@WeBreatheOxy
@WeBreatheOxy 2 жыл бұрын
my guy you saved my life here with this one ha
@jatinkumar4410
@jatinkumar4410 Жыл бұрын
amazing tutorial🔥
@nishthakapur997016
@nishthakapur997016 5 жыл бұрын
Sir, can we add hyperlink in form if we have already given tag helper in form tag. Also how we can get value of textbox on controller? Not on form submit but on clicking hyperlink
@esracigdem2714
@esracigdem2714 3 жыл бұрын
thank you, great content
@abeare9616
@abeare9616 5 жыл бұрын
Very helpful thanks.
@gyan_ko_sagar
@gyan_ko_sagar 4 жыл бұрын
Thanks for great video tutorial but i have one problem. This works as good as shown when we use other route than we have in our app. What if we have custom route with parameters to navigate and we state other parameters than it should be instead of showing error same page is viewed? My question: How to handle when the URL provided matches one of your routes, but the controller name OR PARAMETERS provided isn't correct.? I have setup my custom routes in start up as: endpoints.MapControllerRoute( name: "singleproduct", pattern: "productlist/{catlinkUrl}/{subcatlinkUrl?}/{sku}", defaults: new { controller = "Product", action = "SingleProduct" } ); endpoints.MapRazorPages(); This projects my url how it should be.. But if someone types diffrently in exact same route syntax then how to show notfound page error without redirecting
@nimaljvalath
@nimaljvalath 4 жыл бұрын
Those who still have 500 error , Move NotFound.cshtml to Error Folder(create) in Views. Also add @section scripts to NotFound.cshtml , [optional {if required add @model int -- for statusCode}] ...launchSettings.json : if you run in IIS Express profile keep -->profiles: "IIS Express" "ASPNETCORE_ENVIRONMENT": "Production" or if you run in EmployeeManagement --> "ASPNETCORE_ENVIRONMENT": "Production"..and use app.UseStatusCodePagesWithReExecute("/Error/{0}");
@williamneel5562
@williamneel5562 5 жыл бұрын
Hey guys need some help! I have followed these tutorials from the beginning and everything worked fine up til now. Any issues I had turned out to be typos. I have followed the suggestions in these comments but it does not change anything for me. If I navigate to /foo/bar I get a 500 error. What can I do?
@JacobGoodwin
@JacobGoodwin 5 жыл бұрын
I had the same problem and there are potentially four questions related to this. I'll answer this most recent post, but credit to all of the others who asked. For me, the problem originated from the _ViewStart.cshtml code (in the top-level of the "Views" folder) that Venkat entered here kzbin.info/www/bejne/qGi6mJ2oibifhZo. I left this code, which handles views not inside of the home folder (we have a separate _ViewStart file in this folder overriding the higher-level one). Therefore, my NotFound page was attempting to load a layout View _NonAdminLayout that we never defined. You can fix the problem by changing the code of the top-level _ViewStart.cshtml file with the same code as that contained in the Home folder's _ViewStart.cshtml. Then the standard navbar layout will be applied to your NotFound.cshtml in the shared folder. Hope this resolves some 500 errors.
@wiontayne3794
@wiontayne3794 5 жыл бұрын
@@JacobGoodwin Thank you very much mate, this solved my problem!
@Fetretim
@Fetretim 2 жыл бұрын
@@JacobGoodwin You saved my day man, thank you so much, this is solid..
@fabloalencar5076
@fabloalencar5076 4 жыл бұрын
Thank you! :)
@hanymohamed7219
@hanymohamed7219 5 жыл бұрын
Greate Thanks
@MegaJorgovan
@MegaJorgovan 4 жыл бұрын
Why we created new Razor View called NotFound in Shared folder insead to create new folder Error (because we created ErrorController)? As we have Home folder for HomeController...
@javaguitarist
@javaguitarist 4 жыл бұрын
This is so it will be available to any page, just like the _Layout shared view, not just views from the Home controller.
@sakthir3892
@sakthir3892 5 жыл бұрын
Thank you sir....
@p_andrej_
@p_andrej_ 5 жыл бұрын
After doing everything as you did, instead of getting Error/404 view, I got: This page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500 I changed environment back to Development and got: InvalidOperationException: The layout view '_NonAdminLayout' could not be located. The following locations were searched: /Views/Error/_NonAdminLayout.cshtml /Views/Shared/_NonAdminLayout.cshtml /Pages/Shared/_NonAdminLayout.cshtml So I copied _Layout.cshtml and renamed it to _NonAdminLayout.cshtml and it worked in both Development and Production environment. Is there another way to solve this (without _NonAdminLayout.cshtml) and does anyone know why it didn't work without _NonAdminLayout.cshtml? PS I'm working on Ubuntu machine and using Visual Studio Code which uses it's own launch.json instead of launchSettings.json and from what I've seen on one of the first tutorials in this series, VSC uses Kestrel server instead of Visual Studio's IIS Express.
@jariruddin
@jariruddin 5 жыл бұрын
Same response here, too, Helpn Please
@alih2399
@alih2399 4 жыл бұрын
@@jariruddin same here
@nithinreddykotta9680
@nithinreddykotta9680 4 жыл бұрын
@kudvenkat Hello sir, I have been following this tutorial from the very beginning and I absolutely loved each and every video Thank you soo much for helping. But I have faced an issue, So when ever i change my environment to production all the image cards alignment has changed in the Index page can you help me sort this problem?
@saikrishnak9081
@saikrishnak9081 4 жыл бұрын
Yes, even I had same problem, Did u resolve the issue ?
@hetalchavan9446
@hetalchavan9446 4 жыл бұрын
Facing the same issue. Any help is appreciated.
@saikrishnak9081
@saikrishnak9081 4 жыл бұрын
hey @@hetalchavan9446 , In Layout.cshtml .iF the environment is not development , we included a bootstrap cdn and this bootstrap cdn version should match the bootsrtrap version in html. In my case both are different, so i included the cdn which is same as bootstrap in html This resolved my issue
@hetalchavan9446
@hetalchavan9446 4 жыл бұрын
@@saikrishnak9081 Thanks! I will try this out.
@nys8260
@nys8260 4 жыл бұрын
Thanks
@miguelcastillo7346
@miguelcastillo7346 3 жыл бұрын
Fucking thank you i was searching for this.
@excessiveaholecritic672
@excessiveaholecritic672 5 жыл бұрын
Hello, For me everything works good, except for the fact that the code from the previous video doesn't work, when I change only the ID to 99 for example I get: 404 Not Found Error : Employee with Id = 0 cannot be found How do I fix this so that the ID showed will be 99 again.
@favorivideo628
@favorivideo628 5 жыл бұрын
maybe because you are not in development stage
@bigalfantasy
@bigalfantasy 3 жыл бұрын
If anyone else got the 500 error, I was getting the same thing. I realized I had created the NotFound view in the Views folder and not the Views/Shared folder. Once I fixed that, the 500 error went away.
@josephregallis3394
@josephregallis3394 5 жыл бұрын
I still get these error from using your code: CS0103 The name 'photo' does not exist in the current context EmployeeManagement C:\Projects\EmployeeManagement\EmployeeManagement\Controllers\HomeController.cs 155 Active Error CS0103 The name 'photo' does not exist in the current context EmployeeManagement C:\Projects\EmployeeManagement\EmployeeManagement\Controllers\HomeController.cs 159 Active
@qazifaheemafridi3588
@qazifaheemafridi3588 5 жыл бұрын
Change the name of Photo to Photos and then check it
@afossible886
@afossible886 5 жыл бұрын
I did the same as the video but why did i get error 500?
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 5 жыл бұрын
That's a bit strange. Can you please place a breakpoint and debug through to pin-point where it's actually going wrong. Will be great to know where it actually went wrong and if you have found the fix. Thank you for sharing.
@hossammetwally07
@hossammetwally07 5 жыл бұрын
Why do we need a new ErrorController? We could just use the HomeController!
@metalguy8117
@metalguy8117 5 жыл бұрын
Clean Separation of Concerns
@darkogele
@darkogele 5 жыл бұрын
Hmm this work only under IIS express not with full pledged IIS :(
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 5 жыл бұрын
Hello Darko - What happens when deployed on full blown IIS. Are you getting an error. Would you mind sharing the error and status code you are getting.
@FilmFaithVibes
@FilmFaithVibes 4 жыл бұрын
it still not working for me
@deepankarjoshi6057
@deepankarjoshi6057 2 жыл бұрын
Make sure to add /(slash) before the error page extension,this will prevent 500 error: app.UseStatusCodePagesWithReExecute("/Error/{0}");
The Logging Everyone Should Be Using in .NET
15:34
Nick Chapsas
Рет қаралды 96 М.
GIANT Gummy Worm #shorts
0:42
Mr DegrEE
Рет қаралды 152 МЛН
Vampire SUCKS Human Energy 🧛🏻‍♂️🪫 (ft. @StevenHe )
0:34
Alan Chikin Chow
Рет қаралды 138 МЛН
AddSingleton vs AddScoped vs AddTransient
15:23
kudvenkat
Рет қаралды 219 М.
just EUNCHAE making kpop idols feel old (mostly 3rd gen idols)
8:57
Elegant Global Error Handling Using Middleware In ASP.NET Core
13:58
Milan Jovanović
Рет қаралды 92 М.
Implementing login functionality in asp net core
14:11
kudvenkat
Рет қаралды 172 М.
Grafana is the goat... Let's deploy the LGTM stack
5:59
Fireship
Рет қаралды 494 М.
Coding Shorts: ASP.NET Core Middleware Explained
17:36
Shawn Wildermuth
Рет қаралды 32 М.