MVC Cannot use a leading .. to exit above the top directory

馋奶兔 提交于 2019-12-12 14:51:20

问题


Have a Website build with ASP.NET MVC 3.

Publish it as below: create a virtual directory under website, copy MVC application to this folder and turn it to application. So the site structure looks like

Have UrlRewite as below so that http://www.example.com will be rewrite to http://www.example.com/travel without url changed.

<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>

Then My problem came out.

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

Url.RouteUrl("Lvxingshe")

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

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

I have codes above in my home/index view. And they threw exceptions:

Cannot use a leading .. to exit above the top directory.


回答1:


In my case creating extra rule in route config solved problem.

Got this rule:

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

In action url propery you should use this extra rule.

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


来源:https://stackoverflow.com/questions/20699150/mvc-cannot-use-a-leading-to-exit-above-the-top-directory

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