【问题标题】:MVC Cannot use a leading .. to exit above the top directoryMVC 不能使用前导 .. 退出顶级目录
【发布时间】:2013-12-20 08:22:52
【问题描述】:

使用 ASP.NET MVC 3 构建网站。

发布如下:在网站下创建一个虚拟目录,将MVC应用程序复制到该文件夹​​并转为应用程序。所以网站结构看起来像

具有如下 UrlRewite,以便 http://www.example.com 将被重写为 http://www.example.com/travel 而不会更改 url。

<rule name="rewrite rule for home page" enabled="true" stopProcessing="false">
 <match url="^$" />
 <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
 <action type="Rewrite" url="/home/index" appendQueryString="false" />
</rule>
<rule name="rewrite rule for virtual path" enabled="true">
 <match url="^[\w-/\.]+$" />
 <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
 <action type="Rewrite" url="/travel/{R:0}" appendQueryString="false" />
</rule>

然后我的问题就出来了。

script src="@Url.Content("~/Content/Js/Index.js")" type="text/javascript">

Url.RouteUrl("旅星社")

Url.RouteUrl("ListOfCity", new { locationname = "LA" })

script src="@Url.Content("/Content/Js/Index.js")" type="text/javascript">

我的主页/索引视图中有上面的代码。他们抛出了异常:

不能使用前导 .. 退出顶级目录。

【问题讨论】:

    标签: asp.net-mvc-3 url-rewriting url-routing


    【解决方案1】:

    在我的情况下,在路由配置中创建额外规则解决了问题。

    得到这条规则:

    <rule name="site/company/CompanyId-CompanyName/" stopProcessing="true">
        <match url="^company/([0-9]+)-([^/^&amp;]+)(/{0,1})$" />
        <action type="Rewrite" url="employer/{R:1}" />
    </rule>
    

    在操作 url 属性中,您应该使用这个额外的规则。

    // for urlRewrite
    routes.MapRoute("Employer", 
        "employer/{empid}", 
        new { controller = "Employer", action = "Index" }, 
        new { empid = @"\d+" }
    );
    

    【讨论】:

      猜你喜欢
      • 2012-01-14
      • 2011-01-16
      • 1970-01-01
      • 1970-01-01
      • 2011-04-19
      • 2019-09-17
      • 2014-04-28
      • 2010-09-16
      相关资源
      最近更新 更多