Last post Aug 06, 2013 01:31 AM by lextm
Jul 26, 2013 06:39 PM|rcpenalosa|LINK
I'm not sure if this is the right place to ask and I'm not sure if I am describing the problem correctly, but here goes.
I have a website with the URL http://domain.com. It pulls up my default startup page default.aspx. This is a basic Hello World asp.net page. Framework is 4.0.
Now, when I type a forward slash with a fake category such as domain.com/default.aspx/nothing I get a HTTP status code of 200.
I can go on and on with a fake category names such as
http://domain.com/deafault.aspx/nothing/nothing/nothing and it will always come back with a HTTP status code of 200, not 404 which it should be since it does not exists.
But if I place an aspx file at the end of the URL such as
http://domain.com/default.aspx/nothing/nothing.aspx or if I start off with
http://domain.com/nothing I get the correct status code of 404.
Can anyone explain to me why
http://domain.com/default.aspx/nothing come back with a 200 http status code?
Is this how ASP.Net routing works?
Does it even have anything to do with ASP.Net routing?
Aug 06, 2013 01:31 AM|lextm|LINK
http://domain.com/default.aspx/nothing/nothing/nothing means access to http://domain.com/default.aspx with path info /nothing/nothing/nothing. Thus receiving 200 is perfectly expected. You can refer to
http://msdn.microsoft.com/en-us/library/system.web.httprequest.pathinfo.aspx and http://msdn.microsoft.com/en-us/library/cc668201(v=vs.100).aspx for more details.
When you access http://domain.com/nothing it looks for an application (physical or virtual directory) called nothing under
http://domain.com or a controller named NothingController for ASP.NET MVC. So receiving 404 means it does not exist at all.
The response to http://domain.com/default.aspx/nothing/nothing.aspx is bit of complex, because the path info /nothing/nothing.aspx might be processed by default.aspx which might change the
response code from 200 to anything. When you receiving 404 you have to go through all the processing units so as to know why 404 is returned.
Please make sure you fully understand how to interpret URLs before learning ASP.NET routing. Ideally, you should learn about IIS tracing and ASP.NET tracing, so as to better debug when any issue occurs.