开发者

asp.net mvc using HREF in application running on IIS

开发者 https://www.devze.com 2023-01-22 23:27 出处:网络
There is a partial view representing pager control (very similar to this) for blog content. Code generates HTML withreferences and href like, \"/Blog/Posts/Page/1\", \"/Blog/Posts/Page/2\" etc.

There is a partial view representing pager control (very similar to this) for blog content. Code generates HTML with references and href like, "/Blog/Posts/Page/1", "/Blog/Posts/Page/2" etc.

It worked absolutely fine on Cassini, but after I switched to IIS problems appeared.

IIS application running in virtual folder, so URL is

http://localhost/tracky

and blog area located,

http://localhost/tracky/blog

As I press on pager button, I recieve 404, because the URL woul开发者_如何学Pythond be

http://localhost/blog/page/3

Instead of

http://localhost/tracky/blog/page/3

My question is, how to handle such situation? how to change code generation to provide correct URL? how to make it work same - as root applicaton or application in virtual folder?

Source code is here


You need to generate your urls either by using ActionLink in your view, or using an UrlHelper in your href as follows: <a href="<%=Url.Content("~/blog/page/3")%>" ..>bla</a>. This will generate Urls that are adjusted accoring to your application root.


You should be using the following:

UrlHelper.GenerateContentUrl("~/Blog/Posts/Page/1");

The ~ allows the url to be resolved relative to the application path and should produce correct results in both cassini and IIS.

0

精彩评论

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