IIS URL Rewrite For URL Link with %3D

让人想犯罪 __ 提交于 2019-12-11 04:34:40

问题


I am having an issue where someone has posted a URL for my asp.net mvc3 site that contains %3D instead of an equal sign after my id parameter like this: http://ultimategamedb.com/Article/Article?id%3D398210c1-529e-4909-9793-a11b8a832dcc . I have tried various rewrite rules but cannot seem the URL to rewrite correctly to: http://ultimategamedb.com/Article/Article?id=398210c1-529e-4909-9793-a11b8a832dcc . It is a problem because the URL with the %3D gives a 404 error. If possible I would like to create a rule that rewrite any URL with % encoding to the correct decoded values. If this is not possible I would just like to know how to rewrite my article URLs to ensure that a %3D will never show up for the equals sign in an Article URL again.

Could anyone explain to me how I would go about creating these rewrite rules? Thanks in advance!


回答1:


You have few options:

  1. Write your own provider which will replace %3D with =.

    Reference: http://www.iis.net/learn/extensions/url-rewrite-module/developing-a-custom-rewrite-provider-for-url-rewrite-module

  2. In Application_BeginRequest, replace your path:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        string path = HttpContext.Current.Request.Url.PathAndQuery;
    
        // Search for %3D and replace.
        path = path.Replace("%3D","=");
    
        HttpContext.Current.RewritePath(path);
    }
    


来源:https://stackoverflow.com/questions/19530880/iis-url-rewrite-for-url-link-with-3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!