I know this question is old but I am trying to understand the logic behind. What am I doing?
I have created an ASP.NET MVC app and I have successfully deployed it on IIS server.
The problem?
When I deploy all the ajax calls get invalid because of appname in the url:
hostname.com/{appname}/Home/Ajaxcall
in my ajax calls.
I am using relative urls like
$.ajax({
url: '/CustomerAccount/Ajaxcreateinvoicesave',
type: 'Post',
data: data,
success: function (res) {
datatable.fnDraw();
},
error: function (response) {
}
});
but to runs this on server I have to write urls like
url: '{appname}/Customeraccount/ajaxcreateinvoicesave'
What I want/want to understand?
How shared hosting or cloud hosting does not require this url rewriting. They work fine there without any modification.
Also if there any way to directly point Index without using appname in url e.g
domain.com/{appname}/home/index
to
domain.com/home/index
in iis (in production environment)
答案 0 :(得分:1)
Why are you using string literal urls, what you need it to Url.Action
helper method for generating the proper relative urls so that you don't face the problem which you have stated above, you can change your urls to be generated via the method mentioned above like:
url: '@Url.Action("Ajaxcreateinvoicesave","CustomerAccount")'
If your all js is in external files then you will need to use data-
attribute in html like:
<input type="button" id="btnId"
data-url="@Url.Action("Ajaxcreateinvoicesave","CustomerAccount")" />
and then in the client side code you would need to capture the url to send ajax call.