MVC URL请求 - 路径中的非法字符 [英] MVC Url Request - Illegal Characters in path

查看:387
本文介绍了MVC URL请求 - 路径中的非法字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概述:




  • 404错误页面在web.config中配置并正常工作

  • 使用Umbraco v6.2

  • customErrors设置为 RemoteOnly



    • 问题是当我将%7C放在URL中时,我收到这个:

       code>路径中的非法字符。 

      说明:在执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误的更多信息及其在代码中的起始位置。

      异常详细信息:System.ArgumentException:路径中的非法字符。

      源错误:

      在执行当前Web请求期间生成了未处理的异常。有关异常的来源和位置的信息可以使用下面的异常堆栈跟踪来识别。

      堆栈跟踪:

      [ArgumentException:路径中的非法字符]
      System.IO.Path.GetExtension(String path)+14365864
      Umbraco .Core.UriExtensions.IsClientSideRequest(Uri url)+23
      Umbraco.Web.UmbracoModule.BeginRequest(HttpContextBase httpContext)+365
      System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
      System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)+165



      < hr>

      %7C是一个管道|。 %7C是唯一一个(我尝试过的)给我的YSOD。



      如果我放任何东西(我已经尝试了30+组合),如%7A,%2A,那么有时它会给我这个错误w / o去404页面,但从来没有YSOD:

       错误请求 - 无效的URL 

      HTTP错误400.请求URL无效。






      web.config



      < customErrors mode =RemoteOnlydefaultRedirect =〜/ error-page/> p>

       < httpErrors errorMode =CustomdefaultResponseMode =ExecuteURLexistingResponse =Replace> 
      < remove statusCode =404subStatusCode = - 1/>
      < remove statusCode =500subStatusCode = - 1/>
      < remove statusCode =503subStatusCode = - 1/>
      < error statusCode =404prefixLanguageFilePath =path =〜/ error-pageresponseMode =ExecuteURL/>
      < error statusCode =500prefixLanguageFilePath =path =〜/ error-pageresponseMode =ExecuteURL/>
      < error statusCode =503prefixLanguageFilePath =path =〜/ error-pageresponseMode =ExecuteURL/>
      < / httpErrors>






      在Umbraco中有一个配置文件(umbracoSettings .config),其中包含一个包含字符替换的XML部分。



      示例:

       < char org =〜>< / char> 
      < char org => - < / char>
      < char org =& quot;>< / char>
      < char org ='>< / char>
      < char org =%>< / char>
      < char org =。>< / char>
      < char org =|>< / char>

      你可以看到管道在那里。如果我输入URL,



      local.website.com/asdf | (注意管道),它被编码成 local.website.com/asdf%7C



      我尝试添加< char org =%7C>< / char> 它不工作我错过了什么吗?这是一个已知的错误吗?

      解决方案

      必须添加到web.config

       < remove statusCode =400subStatusCode = -  1/> 
      < error statusCode =400prefixLanguageFilePath =path =〜/ error-pageresponseMode =ExecuteURL/>

      另外一次我在上修改错误customErrors =On这个错误消失了。



      如果任何人有更好的替代或推理背后,我开放的建议


      Overview:

      • 404 error page is configured in web.config and working
      • Using Umbraco v6.2
      • customErrors are set to RemoteOnly

      The issue is when I put "%7C" in the URL, I receive this:

      Illegal characters in path.
      
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
      
      Exception Details: System.ArgumentException: Illegal characters in path.
      
      Source Error: 
      
      An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
      
      Stack Trace:    
      
      [ArgumentException: Illegal characters in path.]
         System.IO.Path.GetExtension(String path) +14365864
         Umbraco.Core.UriExtensions.IsClientSideRequest(Uri url) +23
         Umbraco.Web.UmbracoModule.BeginRequest(HttpContextBase httpContext) +365
         System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
         System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165
      


      %7C is a pipe "|". %7C is the only one (that I've tried) that gives me the YSOD.

      If I put anything (I've tried 30+ combinations), such as %7A, %2A, then sometimes it'll give me this error w/o going to the 404 page, but never the YSOD:

      Bad Request - Invalid URL
      
      HTTP Error 400. The request URL is invalid.
      


      web.config

      <customErrors mode="RemoteOnly" defaultRedirect="~/error-page" />

      <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL" existingResponse="Replace">
        <remove statusCode="404" subStatusCode="-1" />
        <remove statusCode="500" subStatusCode="-1" />
        <remove statusCode="503" subStatusCode="-1" />
        <error statusCode="404" prefixLanguageFilePath="" path="~/error-page" responseMode="ExecuteURL" />
        <error statusCode="500" prefixLanguageFilePath="" path="~/error-page" responseMode="ExecuteURL" />
        <error statusCode="503" prefixLanguageFilePath="" path="~/error-page" responseMode="ExecuteURL" />
      </httpErrors>
      


      In Umbraco, there is a config file (umbracoSettings.config) that has an XML section that houses character replacement.

      Example:

       <char org="~"></char>
        <char org=" ">-</char>
        <char org="&quot;"></char>
        <char org="'"></char>
        <char org="%"></char>
        <char org="."></char>
        <char org="|"></char>
      

      You can see that the pipe is in there. If I put into the URL,

      local.website.com/asdf| (notice the pipe), it gets encoded into local.website.com/asdf%7C.

      I have tried to add <char org="%7C"></char> but it doesn't work. Am I missing something? Is this a known bug?

      解决方案

      Had to add to web.config

        <remove statusCode="400" subStatusCode="-1" />
        <error statusCode="400" prefixLanguageFilePath="" path="~/error-page" responseMode="ExecuteURL" />
      

      Also once I turned errors on customErrors="On" this error went away.

      If anybody has a better alternative or reasoning behind this, I'm open for suggestions

      这篇关于MVC URL请求 - 路径中的非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆