无法确定 URL 为何不包含 IIS 中的应用程序文件夹
假设该应用程序物理上位于:
C:\inetpub\wwwroot\MyApplication
这已通过 IIS 7.5 转换为应用程序,我现在可以通过...访问该应用程序
http://localhost/MyApplication
,因为它将使用默认路由。如果我打电话给...
http://localhost/MyApplication/MyRequest
...则使用相同的路线并提供正确的页面。问题是上述 URL 是一个表单,提交该表单后,我在同一个控制器中调用一个操作,但没有相应地路由。生成的 URL 是...
http://localhost/MyRequest/MyMethod
与...
http://localhost/MyApplication/MyRequest/MyMethod
应用程序内的唯一路由是...
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
这是路由问题吗?驻留在 Scripts 文件夹中的 JS(jqueryUI 等...)也没有被加载,就好像所有内容都设置为驻留在层次结构中的根级别,并且添加到 IIS 中的 MyApplication 文件夹中已经抛出了一些东西环形。
更新:
表单定义看起来像......
<form class="..." action="/Request/Add" method="post" id="requestForm">
Assume that the application is physically located at:
C:\inetpub\wwwroot\MyApplication
This has been converted into an application via IIS 7.5 and I am now able to access the application via...
http://localhost/MyApplication
...as it will engage the default route. If I make a call to...
http://localhost/MyApplication/MyRequest
...the same route is engaged and the proper page is served up. The issue is that aforementioned URL is a form and upon submitting that form I call an action within the same Controller
, yet am not routed accordingly. The resulting URL is...
http://localhost/MyRequest/MyMethod
versus...
http://localhost/MyApplication/MyRequest/MyMethod
The only route within the application is...
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Is this a routing issue? The JS (jqueryUI, etc...) which resides in the Scripts folder is also not being loaded, it's as if everything is set to reside at the root level within the hierarchy and adding in the MyApplication folder within IIS has thrown things for a loop.
UPDATE:
The form definition looks like...
<form class="..." action="/Request/Add" method="post" id="requestForm">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我敢打赌,您的视图和脚本中已经硬编码了 url,而不是使用助手。
例如,关于CSS,不要像这样硬编码它:
使用url helpers:
关于你的HTML表单和锚点总是使用HTML helper来生成它们:
关于你的javascript文件绝对不要像这样硬编码任何url:
你应该始终依赖url 在 ASP.NET MVC 应用程序中处理 url 时提供帮助程序。现在,无论您的应用程序托管在何处以及您的路线如何,它都可以正常工作。
更新:
现在看到您的更新后,
您应该使用 html 帮助程序来生成它们,而不是对表单进行硬编码:
I bet you have hardcoded urls in your views and scripts instead of using helpers.
For example concerning the CSS, instead of hardcoding it like this:
use url helpers:
and concerning your HTML forms and anchors always use HTML helper to generate them:
and concerning your javascript files absolutely never hardcode any urls like this:
You should always rely on url hepers helpers when dealing with urls in an ASP.NET MVC application. Now, no matter where your application is hosted and how your routes look like, it will work.
UPDATE:
And now after seeing your update, instead of hardcoding your forms:
you should use html helpers to generate them: