I have a routing setup which is doing this Rewrite:
<rule name="some Rule" patternSyntax="Wildcard"> <match url="*" /> <conditions> <add input="{PATH_INFO}" pattern="/folder/*" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="/folder/details.aspx?url={PATH_INFO}" appendQueryString="true" /> </rule>
And I also have this:
<httpRuntime targetFramework="4.6.1" maxUrlLength="256" />
I have a bot calling to an invalid url, something like:
So ASP.NET throws this exception
The length of the URL for this request exceeds the configured maxUrlLength value.
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
The problem I have is that the ValidateInputIfRequiredByConfig
from ASP.NET is being called after my Page_Load and Page_PreRender. I could explain a little more about what I'm doing here but my question is:
Why ASP.NET is validating the URL after my page is executed? it makes no sense, why it wastes time processing the page, shouldn't make more sense to do that before? Is there any way to change this behavior?
I uploaded a demo on Github: So you can download this solution https://github.com/kblok/StackOverflowExamples/tree/master/AspNetDemoProject
And break In the page load and then in the Error module. You'll see that the PageLoad is being hit first.
1 Answers
Answers 1
Based on the points that you have mentioned in the comments what I understand is
- Your page
details.aspx
is getting accessed with query string paramurl=<path with unicode characters>
. - In the
Page_Load
your code checks the request, finds out that its invalid and redirects user to new URL. - And THIS NEW URL is longer than the max allowed length so you get
The length of the URL for this request exceeds the configured maxUrlLength value.
The lengh of the original request URL is within limits so there is no error before Page_Load
.
0 comments:
Post a Comment