相关疑难解决方法(0)

URL中的URL编码斜杠

我的地图是:

routes.MapRoute(
   "Default",                                             // Route name
   "{controller}/{action}/{id}",                          // URL with params
   new { controller = "Home", action = "Index", id = "" } // Param defaults
);
Run Code Online (Sandbox Code Playgroud)

如果我使用URL http://localhost:5000/Home/About/100%2f200,则没有匹配的路由.我将URL更改为http://localhost:5000/Home/About/100然后再次匹配路由.

有没有简单的方法来处理包含斜杠的参数?其他转义值(空格%20)似乎有效.

编辑:

编码Base64对我有用.它使URL变得丑陋,但现在还可以.

public class UrlEncoder
{ 
    public string URLDecode(string  decode)
    {
        if (decode == null) return null;
        if (decode.StartsWith("="))
        {
            return FromBase64(decode.TrimStart('='));
        }
        else
        {
            return HttpUtility.UrlDecode( decode) ;
        }
    }

    public string UrlEncode(string encode)
    {
        if (encode == null) return null;
        string encoded = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc urlencode asp.net-mvc-routing

56
推荐指数
5
解决办法
6万
查看次数

如何创建使用GenericUriParserOptions.DontCompressPath解析的Uri实例

当.NET System.Uri类解析字符串时,它会对输入执行一些规范化操作,例如对方案和主机名进行下限.它还会修剪每个路径段的尾随时段.后一个特性对于OpenID应用程序是致命的,因为一些OpenID(如从Yahoo发布的那些)包括base64编码的路径段,其可以以句点结束.

如何禁用Uri类的周期修剪行为?

使用UriParser.Register初始化的解析器注册我自己的方案GenericUriParserOptions.DontCompressPath可以避免周期修剪,以及其他一些对OpenID也不可取的操作.但我无法为HTTP和HTTPS等现有方案注册新的解析器,我必须为OpenID做这些.

我尝试的另一种方法是注册我自己的新方案,并编程自定义解析器以将方案更改回标准HTTP方案作为解析的一部分:

public class MyUriParser : GenericUriParser
{
    private string actualScheme;

    public MyUriParser(string actualScheme)
        : base(GenericUriParserOptions.DontCompressPath)
    {
        this.actualScheme = actualScheme.ToLowerInvariant();
    }

    protected override string GetComponents(Uri uri, UriComponents components, UriFormat format)
    {
        string result = base.GetComponents(uri, components, format);

        // Substitute our actual desired scheme in the string if it's in there.
        if ((components & UriComponents.Scheme) != 0)
        {
            string registeredScheme = base.GetComponents(uri, UriComponents.Scheme, format);
            result = this.actualScheme + result.Substring(registeredScheme.Length);
        }

        return result;
    } …
Run Code Online (Sandbox Code Playgroud)

.net c# uri http

17
推荐指数
1
解决办法
5281
查看次数

以%20结尾的网址出现问题

我有一个大问题.现场有设备发送URL"/ updates".这是这些设备开发人员的错字.在服务器日志中,它看起来像"/ updates +".

我有一个ManageURL重写模块,可以处理所有没有扩展名的请求.但是这个请求会导致HttpException:

System.Web.HttpException:

System.Web.HttpException
   at System.Web.Util.FileUtil.CheckSuspiciousPhysicalPath(String physicalPath)
   at System.Web.HttpContext.ValidatePath()
   at System.Web.HttpApplication.ValidatePathExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Run Code Online (Sandbox Code Playgroud)

正如我在日志中看到的,URL重写模块甚至没有获取此URL,因此我无法在那里修复它.

有没有办法用ASP.NET处理这些URL?

asp.net iis redirect

14
推荐指数
1
解决办法
8114
查看次数

标签 统计

c# ×2

.net ×1

asp.net ×1

asp.net-mvc ×1

asp.net-mvc-routing ×1

http ×1

iis ×1

redirect ×1

uri ×1

urlencode ×1