C
C#10mo ago
Rename

Bad Request for URL containing token route on server

I have this endpoint: [HttpGet("setup-account/{token}")] public IActionResult SetupAccountPassword([FromRoute] string token, [FromQuery] string email) { //manually decode because route parameters do not get automatically decoded. token = Base64UrlEncoder.Decode(token); return View("ResetPassword", new ResetPasswordViewModel(email, token)); } I open it from an email link such as: https://localhost:5001/auth/setup-account/Q2ZESjhDT3ZWdEtLK0FSSHBaV09tNG5Lem1wTXpWcjF0MmV5ZWF5Z1ZYZkNsS3licVBFV3k5VlFOc2I2VEN5TmF5anNLV0hyck15eEpNb21zMis1cG9UME1FUkw4V2hwWFVXRVlWcnkrNlhzYUoyK0QwcW1mdzNJUHNERlFaR3FjRWxzQ2loamVBTEpTM1ZLWHROaTVDd2l0djRGTGdvc013SHFOMWQveFBLREVoNDNGQ3pPV1plcXlEa2ZydjBWRjkyNjl3PT0?email=test@icloud.com this link works properly on localhost but it doesn't once I publish the website to a server and access it from the domain, in that case I get 400 Bad Request error Invalid URL any idea?
34 Replies
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
thanks for the reply, this is hosted in IIS, I'm not sure where exactly I can increase the log level there. Log files aren't showing any errors also.
Plerx
Plerx10mo ago
appsettings.json should work i think
Rename
RenameOP10mo ago
changing the LogLevel didn't seem to affect it as I got no files/updated from IIS looking into this I found: https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/iis/health-diagnostic-performance/troubleshoot-http-400-errors-in-iis where I got HTTP/2.0 GET /auth/setup-account/Q2ZESjhMTEJMczNqZHVCRG1DMEZEYXV5RCtxVjRtanZSL2YxdkUvVFQyZ3BxUmhaV2tQa2FVMmgwOGxCRWtWUzB4ZlZ3Q2dRSjdTTnlSMmJ6eGM1empIQ1BsTkhVbk80SzNoTmNHZHpsTnMvUDVROVJqd3MwWnNHVEdmeXMydVRRb0FQb2VTbmhFOGR5TFZQNDg5bUxubEJIR2pZbjVPdU5SMk9lMzVhRlBwQ2ZnMTdpRjFoWjloSjBaa01DcUllREhaT3lBPT0?email=test@example.com 1 400 - URL - and that URL part is described here: https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/aspnet/site-behavior-performance/error-logging-http-apis#kinds-of-errors-that-the-http-api-logs URL --> A parse error occurred while processing a URL I'm still not sure what could be causing it since email and token are both strings
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX10mo ago
Plerx
appsettings.json should work i think
React with ❌ to remove this embed.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
changed log level to Debug for appsettings.json (including production and development) but there's no changes in that page, same error as before
Rename
RenameOP10mo ago
No description
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
I'm thinking the error should be more descriptive, but it doesn't change at all. neither are there any logs generated, or I just can't find them.
Plerx
Plerx10mo ago
The http response only changes if u enable dev exceptions on your application builder
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\example.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\example.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
that's the web.config but there's no logs folder within the website path and the appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=localhost;Initial Catalog=Example;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"UAT": "Database=Example; Data Source=IP;User Id=example;Password=example;MultipleActiveResultSets=True;"
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Debug"
}
},
"AllowedHosts": "*",
"EPPlus": {
"ExcelPackage": {
"LicenseContext": "Commercial" //The license context used
}
}
}
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=localhost;Initial Catalog=Example;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
"UAT": "Database=Example; Data Source=IP;User Id=example;Password=example;MultipleActiveResultSets=True;"
},
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Debug"
}
},
"AllowedHosts": "*",
"EPPlus": {
"ExcelPackage": {
"LicenseContext": "Commercial" //The license context used
}
}
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
created those in wwwroot/applicationName > log folder > stdout folder restarted website, tried the same endpoint/url, no other files generate in there
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
yes that's windows it should be in inetpub then? path seems relative in webconfig ./
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
no that's inetpub > wwwroot dir not the application's wwwroot obviously
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
huh, well that's where the new website is also
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
C: / intepub has got a few folders: ftproot, history, logs, wwwroot wwwroot has all the websites there meanwhile the logs folder had no stdout in it. I added stdout there also but no logs yet
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
yep I understand, they threw me on this issue and it's already been setup like this!
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
made a new path C:/iis-websites/website1 and deployed there. webconfig had
<aspNetCore processPath="dotnet" arguments=".\website1.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<aspNetCore processPath="dotnet" arguments=".\website1.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
added C:/iis-websites/website1/logs/stdout folder also on C:/logs/stdout tried with stdoutLogEnabled = false and true while requesting that page/url and no files there
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
yep tried with true also, nothing changed..
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
no luck still! am I supposed to add something in program.cs maybe
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rename
RenameOP10mo ago
finally fixed it! I ran out of options, the error in httperr as mentioned above was simply URL and not about the length. but i figured what the hell nothing else makes sense. so I added registry key UrlSegmentMaxLength as mentioned here: https://stackoverflow.com/questions/42243211/increase-max-url-length-in-asp-net-core there was no need for the webconfig section to be added it required a system restart for it to take effect but works perfectly now, thanks for helping guys
Want results from more Discord servers?
Add your server