I’ve spent the past few weeks reading up on C#, ASP.NET, MVC stuff and everything I find just leads to more questions.
The documentation for this stuff is a scattered mess
and the documentation/articles/tutorials I’ve come across often contradict each other.
I feel like I’m following a never-ending trail of inheritance. The joys of OOP…
So, I figured looking up MvcApplication
would be a good place to start.
I tried to look at the code itself. I came across, what I believe to be, the source code for ASP.NET here:
Github – AspNetWebStack – ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
https://github.com/aspnet/AspNetWebStack
When I searched it for the string MvcApplication
I got no results.
How could the source code for the thing itself not contain the most important identifier?
A web search gives this result:
https://learn.microsoft.com/en-us/previous-versions/azure/reference/dn792792(v=azure.100)
Which says it’s in the namespace Microsoft.WindowsAzure.Mobile.Service.MvcApplication
, sure…
Also, there is a banner at the top saying the documentation is no longer updated and the article has a timestamp from 2016.
Is MvcApplication
just an entry point for ASP.NET MVC or ASP.NET? (I’m not sure what the structure of ASP.NET is.)
If that is the case, does it have to be named MvcApplication
?
How does ASP.NET MVC know how to use this?
That aside, on the topic of a “big picture understand”, I have a couple of more specific questions.
Question 1:
What is the difference between event AuthenticateRequest
and OnAuthentication()
?
https://learn.microsoft.com/en-us/dotnet/api/system.web.httpapplication?view=netframework-4.8.1#remarks
https://learn.microsoft.com/en-us/dotnet/api/system.web.requestnotification?view=netframework-4.8.1
https://learn.microsoft.com/en-us/dotnet/api/system.web.mvc.filters.iauthenticationfilter.onauthentication?view=aspnet-mvc-5.2
Upon testing it appears OnAuthentication()
occurs during/after ExecuteRequestHandler
:
BeginRequest
AuthenticateRequest In IIS Express with SSL, client has already disconnected here.
AuthorizeRequest
ResolveRequestCache
MapRequestHandler
AcquireRequestState
PreExecuteRequestHandler
ExecuteRequestHandler
OnAuthentication() How are these different from the above?
OnAuthorization()
OnAuthenticationChallenge()
ReleaseRequestState
UpdateRequestCache
LogRequest
EndRequest
SendResponse
I noticed event AuthenticateRequest
is a part of system.web.httpapplication
and OnAuthentication()
is a part of system.web.mvc
If I’m creating an MVC WebApp, should I not use the system.web
event?
Is one of these legacy?
Question 2:
I’ve seen many of article discussing and official documentation mentioning:
https://learn.microsoft.com/en-us/dotnet/api/system.web.httpresponse.redirect?view=netframework-4.8.1#system-web-httpresponse-redirect(system-string)
Don’t use Response.Redirect("here")
, instead use:
Response.Redirect("here", false)
CompleteRequest()
Also saying, don’t use Response.End()
, etc.
So I tried this. However, it appears it still continues executing stuff after calling .CompleteRequest()
, I assume this is because everything is happening inside of the singular event ExecuteRequestHandler
and it is the following events that wouldn’t be executed, jumping strait to the EndRequest
event.
Should I be using the AuthenticateRequest
event instead?
Is this even relevant to an ASP.NET MVC WebApp?
Is this a legacy issue?
Tagra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.