开发者

url paths for resources

i am a newbie on web development, so i have some problems first of all what is the meaning of ~, / on an url? My real question in my javascript code i am doing some ajax calls with jquery like that

    $.ajax({
        ...
        url: '/Membership/Login',
        ...
    });

There is an Membership controller with an Login action method that i need to send data to. When i publish this project to IIS (my application is under xxx folder of wwwroot) i get wrong url address.

I get :

http://localhost/Membership/Login

I expect : (because my application is in xxx folder)

开发者_如何学编程
http://localhost/xxx/Membership/Login 

Note : I dont want to add xxx to all urls.


When you use ~ in a url and call the ResolveUrl method it will put in the path to your application. You can do this in your aspx page by going:

<%=ResolveUrl("~/Membership/Login")%>

This will give you the path

/xxx/Membership/Login

which you can now give to your javascript.


Using the slash makes the url relative to the root of the web server. If you want it relative to the current url, simply remove the slash character. While the tilde character has meaning in server-side controls in ASP.NET (and UNIX paths), it has no special meaning in URLs. In the context of ASP.NET, it means to make the path relative to the application, which may or may not be the web server root. In your mark up, it should be removed, either not used by you or only used in context where it is replaced by the ASP.NET framework, such as a server-side control.


When you use the form "/some/url" you are saying take me to the root of the webserver root with that url. If you want to avoid adding "xxx" to your urls you will need to either change the web server root, create a domain name and rule in IIS for that name, or use some sort of function call to generate your urls for use.

The easiest of those three is to change the webroot on the server.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜