Azure使用带令牌的长URL时出现错误。

huangapple go评论65阅读模式
英文:

Azure giving error with long URL with Token

问题

I have hosted a front end app using React and React Router Dom to Azure.

I have a reset password link with token as below:

https://abc.azurewebsites.net/reset/CfDJ8AkOTLe70aJDl6Jq93G40f4OoMX35xv1bg73%2fU9WyIDfJae9LcF8iFFF6oiO7atp8l9O%2fr1lBq%2bMPZd2aPkELXWPB7YQ5lYoAkh3t2QdB5a%2fB%2bRvJordH34lEbPRBV%2by842E5z%2b1ZNSBstZljGOPZ6tOQNjLGH%2byAAUURGK2Z8rSFjQa22t0RXaVTzP59yCEagf42DGK9UM1PLqtSun655EVkoRH8Jg2LtgK2YZYv6zD

This works fine with localhost. However, in Azure, it gives this error:

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

I have already added the web.config that was suggested in a few posts. It works for shorter URLs but not sure how to make it work for bigger URLs with tokens.

英文:

I have hosted a front end app using React and React Router Dom to Azure.

I have a reset password link with token as below

https://abc.azurewebsites.net/reset/CfDJ8AkOTLe70aJDl6Jq93G40f4OoMX35xv1bg73%2fU9WyIDfJae9LcF8iFFF6oiO7atp8l9O%2fr1lBq%2bMPZd2aPkELXWPB7YQ5lYoAkh3t2QdB5a%2fB%2bRvJordH34lEbPRBV%2by842E5z%2b1ZNSBstZljGOPZ6tOQNjLGH%2byAAUURGK2Z8rSFjQa22t0RXaVTzP59yCEagf42DGK9UM1PLqtSun655EVkoRH8Jg2LtgK2YZYv6zD

This work fine with localhost. However in Azure it gives this error

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

I have already added the web.config that was suggested in few posts. It works for shorter URL but not sure how to make it work for bigger urls with tokens.

<?xml version="1.0"?>
<configuration>
  <system.web>
    <customErrors mode="Off"/>
    <httpRuntime maxQueryStringLength = "10000" />
  </system.web>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="React Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
    <security>
      <requestFiltering>
        <requestLimits maxQueryString="10000" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

答案1

得分: 0

以下是您要翻译的内容:

"The error message is due to the length of the URL with the token.

Azure has a default limit of 2048 characters for URLs. You can increase the limit by adding the following configuration to your web.config file.

<?xml version="1.0"?>
<configuration>
	<system.web>
		<customErrors mode="Off"/>
		<httpRuntime maxQueryStringLength = "32768" />
	</system.web>
	<system.webServer>
		<rewrite>
			<rules>
				<rule name="React Routes" stopProcessing="true">
					<match url=".*" />
					<conditions logicalGrouping="MatchAll">
						<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
						<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
						<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
					</conditions>
					<action type="Rewrite" url="/" />
				</rule>
			</rules>
		</rewrite>
		<security>
			<requestFiltering>
				<requestLimits maxQueryString="32768" />
			</requestFiltering>
		</security>
	</system.webServer>
</configuration>

As per the Azure Web App URL Length Limitations. The increase in the maximum length of the query string to 32768 characters.

And you need to adjust the maxQueryStringLength value in the httpRuntime element to match the new limit you set in the requestLimits element.

Approach 2

const myToken = "long token"; 
const encoded_Token = encodeURIComponent(myToken); 
const reset_PasswordUrl = `https://somesample.com/reset-password/${encoded_Token}`;

And it is a good practice to ensure that the URL is properly formatted and can be parsed correctly by the server.

If the token is too long, it may exceed the maximum URL length allowed by Azure. In this case, you need to consider using a POST request instead of a GET request to pass the token.

Alternatively, you can try shortening the token by using a tokenization service or by generating a shorter token.

Another option is storing the token in a database and passing a unique identifier in the URL instead of the entire token.

For further information refer to the SO link."

英文:

>The error message is due to the length of the URL with the token.

Azure has a default limit of 2048 characters for URLs. You can increase the limit by adding the following configuration to your web.config file.

&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;configuration&gt;
	&lt;system.web&gt;
		&lt;customErrors mode=&quot;Off&quot;/&gt;
		&lt;httpRuntime maxQueryStringLength = &quot;32768&quot; /&gt;
	&lt;/system.web&gt;
	&lt;system.webServer&gt;
		&lt;rewrite&gt;
			&lt;rules&gt;
				&lt;rule name=&quot;React Routes&quot; stopProcessing=&quot;true&quot;&gt;
					&lt;match url=&quot;.*&quot; /&gt;
					&lt;conditions logicalGrouping=&quot;MatchAll&quot;&gt;
						&lt;add input=&quot;{REQUEST_FILENAME}&quot; matchType=&quot;IsFile&quot; negate=&quot;true&quot; /&gt;
						&lt;add input=&quot;{REQUEST_FILENAME}&quot; matchType=&quot;IsDirectory&quot; negate=&quot;true&quot; /&gt;
						&lt;add input=&quot;{REQUEST_URI}&quot; pattern=&quot;^/(api)&quot; negate=&quot;true&quot; /&gt;
					&lt;/conditions&gt;
					&lt;action type=&quot;Rewrite&quot; url=&quot;/&quot; /&gt;
				&lt;/rule&gt;
			&lt;/rules&gt;
		&lt;/rewrite&gt;
		&lt;security&gt;
			&lt;requestFiltering&gt;
				&lt;requestLimits maxQueryString=&quot;32768&quot; /&gt;
			&lt;/requestFiltering&gt;
		&lt;/security&gt;
	&lt;/system.webServer&gt;
&lt;/configuration&gt;

As per the
Azure Web App URL Length Limitations.
The increase in the maximum length of the query string to 32768 characters.

And you need to adjust the maxQueryStringLength value in the httpRuntime element to match the new limit you set in the requestLimits element.

Approach 2

const myToken = &quot;long token&quot;; 
const encoded_Token = encodeURIComponent(myToken); 
const reset_PasswordUrl = `https://somesample.com/reset-password/${encoded_Token}`;

And it is a good practice to ensure that the URL is properly formatted and can be parsed correctly by the server.

>If the token is too long, it may exceed the maximum URL length allowed by Azure. In this case, you need to consider using a POST request instead of a GET request to pass the token.

Alternatively, you can try shortening the token by using a tokenization service or by generating a shorter token.

Another option is storing the token in a database and passing a unique identifier in the URL instead of the entire token.

For further information refer to the SO link.

答案2

得分: 0

SOLVED: 请使用以下内容。看起来这是一个错误,他们在2019年修复了它,链接在github.com/Azure/azure-functions-host/pull/3916

<security>
    <requestFiltering allowDoubleEscaping="true">
        <requestLimits maxAllowedContentLength="104857600" maxUrl="8192" maxQueryString="2048"/>
    </requestFiltering>
</security>
英文:

SOLVED: Please use below. It seems this was a bug and they fixed it in 2019 github.com/Azure/azure-functions-host/pull/3916

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;security&gt; &lt;requestFiltering allowDoubleEscaping=&quot;true&quot;&gt; &lt;requestLimits maxAllowedContentLength=&quot;104857600&quot; maxUrl=&quot;8192&quot; maxQueryString=&quot;2048&quot;/&gt; &lt;/requestFiltering&gt; &lt;/security&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年4月11日 09:49:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75981867.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定