开发者

Unable to determine why the URL does not include application folder within IIS

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.

UPDAT开发者_Go百科E:

The form definition looks like...

<form class="..." action="/Request/Add" method="post" id="requestForm">


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:

<link href="/Content/Site.css" rel="stylesheet" type="text/css" />

use url helpers:

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />

and concerning your HTML forms and anchors always use HTML helper to generate them:

<% using (Html.BeginForm()) { %>
    ...
<% } %> 

and concerning your javascript files absolutely never hardcode any urls like this:

$.ajax({
    url: '/foo/bar',
    ...
});

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:

 <form class="..." action="/Request/Add" method="post" id="requestForm">

you should use html helpers to generate them:

<% using (Html.BeginForm("Add", "Request", null, FormMethod.Post, new { id = "requestForm", @class = "foo" })) { %>
    ...
<% } %> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜