Skip to content

Codepolice

  • ⤫

404 redirects in code with ASP.NET

Posted by Judy Alvarez Posted on February 25, 2022March 1, 2022
0

I have had problems doing proper 404 redirects in ASP.NET ever since I started to care about proper 404 pages. I do not have any trouble if the page does not exist. But say for example that I require a query string on some page and for some reason, I do not get a query string. Then I guess it’s proper to give a 404 error.  Today I decided to give it another try and finally, I think I have found the solution thanks to two great tips on the amazing Stackoverflow.com.

The first one is that if you want to throw a 404 error you can just do.

throw new HttpException(404, “Article not found”);

As simple as that. In almost all other articles I read about this people are talking about doing Response. Status = 404 and stuff like that. The problem with that is that the page will continue to execute and you most likely get some kind of error if something vital is missing.

The next thing I learned where that you could do like this.





Notice the “redirect mode” property. It will cause asp.net to not change the URL but do a “Server.Transfer” like redirect to the error page but keep the URL that throws the error.

Categories: JavascriptTagged: ajax in asp net, applications of asp net, asp net authentication and authorization, asp net authentication types, asp net books, asp net code, asp net components, asp net core microservices, asp net ecommerce, asp net file upload, asp net hidden field, asp net interview questions and answers pdf, asp net introduction, asp net mvc 4.0, asp net mvc web api, asp net programmer, asp net que es, asp net web development, asp net web site hosting, asp net website, curso asp net, file upload in asp net, gridview in asp net, hidden field in asp net, hire asp net developer, host asp net, net core vs asp net core, types of authentication in asp net, web api in asp net, web controls in asp net

Post navigation

Previous Previous post: Remote Desktop Connection (RDP) becomes extremely slow after installing “Intel Smart Connect Technology” update
Next Next post: New Relic and runAllManagedModulesForAllRequests flag in .net

Related Posts

  • A Bun-believable release that isn’t half-baked

    #​757 — October 17, 2025 Read on the Web JavaScript Weekly Bun 1.3: The Full-Stack JavaScript Runtime — Arriving a few hours after last week’s issue (natch!) Bun 1.3 remains the big news of the past week. Bun is a performance and DX-focused JavaScriptCore-powered runtime which, with v1.3, balances being a drop-in Node.js replacement with

    Posted by Posted on October 17, 2025
    0
  • Bringing Python apps into Node

    #​596 — October 14, 2025 Read on the Web 📂 A Modern Guide to Reading and Writing Files in Node — A comprehensive guide to various methods for working with files, from promise-based methods through to working with streams, processing files concurrently, using file handles, and memory-efficient techniques. Luciano Mammino A Way to Integrate Python ASGI with Node.js

    Posted by Posted on October 14, 2025
    0
  • Vite gets its own documentary

    #​756 — October 10, 2025 Read on the Web JavaScript Weekly ▶  Vite: The Documentary — From the same creators of the fantastic ▶️ Node.js, ▶️ Angular and ▶️ React documentaries comes an up to date look at Vite, the build tool that has taken the JavaScript ecosystem by storm in recent years. Many luminaries make an appearance to

    Posted by Posted on October 10, 2025
    0
  • npm security best practices to consider

    #​595 — October 7, 2025 Read on the Web 15 Recent Node Features That Can Replace Popular npm Packages — Many features that once required third-party packages are now built into the runtime itself. Here’s a look at some of the most notable that you may want to experiment with, prior to reducing unnecessary dependencies. Lizz

    Posted by Posted on October 7, 2025
    0
  • React 19.2 is in the building

    #​755 — October 3, 2025 Read on the Web JavaScript Weekly The State of JavaScript 2025 Survey — Each year, Devographics runs an epic survey of as many JavaScript community members as it can and turns the results into an interesting report on the state of the ecosystem – here’s the results from 2024. If

    Posted by Posted on October 3, 2025
    0
  • Using Node with Cloudflare Workers

    #​594 — September 30, 2025 Read on the Web 🗓️ We’re back after taking a week off for my birthday. I’ve never bothered to do that before, but I figured I’d give it a go, and.. it was good 😅 We’re now back every week until Christmas!__Peter Cooper, your editor A Year of Improving Node.js

    Posted by Posted on September 30, 2025
    0
Judy Alvarez

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Codepolice

  • Github
  • Atlassian
  • Flatlogic
  • Xero
  • Jetbrains
  • Figma
  • A Bun-believable release that isn’t half-baked
  • Bringing Python apps into Node
  • Vite gets its own documentary
  • npm security best practices to consider
  • React 19.2 is in the building
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice