开发者

Reject (Hard 404) ASP.NET MVC-style URLs

开发者 https://www.devze.com 2022-12-25 05:27 出处:网络
ASP.NET MVC web app that exposes \"friendly\" URLs: http://somesite.com/friendlyurl ...which are rewritten (not redirected) to ASP.NET MVC-style URLs under the hood:

ASP.NET MVC web app that exposes "friendly" URLs:

http://somesite.com/friendlyurl

...which are rewritten (not redirected) to ASP.NET MVC-style URLs under the hood:

http://somesite.com/Controller/Action

The user never actually sees any ASP.NET MVC style URLS. If he requests one, we hard 404 it. ASP.NET MVC is (in this app) an implementation detail, not a fundamental interface.

My question: how do you examine an arbitrary incoming URL and determine whether or not that URL matches a defined ASP.NET MVC path?

For extra credit: how do you do it from inside an ASP.NET-style IHttpModul开发者_运维技巧e, where you're getting invoked upstream from the ASP.NET MVC runtime?

Thanks!


why do you have the "hard" urls in the first place then? just change your routing, it seems kind of odd to rewrite something you have complete control over.

If you can't, you probably want something along these lines

Response.StatusCode = (int)HttpStatusCode.NotFound;
return View("NotFound");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号