0

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 would 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

2
  • how are you generating the url? Commented Oct 30, 2010 at 21:30
  • now it is just hardcoded as "/Blog/Posts/Page" + pageIndex; Commented Oct 30, 2010 at 21:42

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

how is it possible to use it from code-behind, HtmlExtension helper class ? I could not find Url namespace
ActionLink variant works for me... <%: Html.Pager(Url.Action("Page", "Posts", new { area = "Blog", id="{0}"}), Model.TotalPages, Model.CurrentPage)%>
0

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.

2 Comments

I think Content instead of GenerateContentUrl will suffice. There's no need to fully qualify the urls.
UrlHelper.GenerateContentUrl also recieves httpContext, that make it difficult to use code in helper classes.. and unit test it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.