Cannot use query parameter to select category.

Aug 17, 2012 at 6:33 PM

When I try to do:

http://somedomain.com/blog?id=idnumberfromdatabase

It does not work. 

Coordinator
Aug 17, 2012 at 9:15 PM

You calling default page and passing it id. Page has no idea what this id means - blog? post? category? something else? So it ignores it and loads posts as usual. 

Aug 17, 2012 at 11:08 PM
Edited Aug 17, 2012 at 11:09 PM

I have tried " category= " also. I was using the id query parameter because that is what is used in the DisplayCategories method .  

I think there is something wrong with the code. I have a workaround.

I hacked up a new method called DisplayByCategory and placed in the the default.aspx.cs, after the DisplayCategories method.  

 

 

private void DisplayByCategory()
        {
        if (!String.IsNullOrEmpty(Request.QueryString["cat"]))
            {
            Category tradeCategory = Category.Categories.Find(
                delegate(Category c)
                    {
                    string foo = Request.QueryString["cat"];
                    return c.Title == foo;
                    });

            if (tradeCategory != null)
                {
                PostList1.Posts = tradeCategory.Posts.ConvertAll(
                    new Converter(delegate(Post p)
                    {
                        return p as IPublishable;
                    }));
                }
            }
        }

 

 

Also, in the ... Page_Load

 

 

 if (Request.RawUrl.ToLowerInvariant().Contains("/category/"))
            {
            DisplayCategories();
            }
       
//this new stuff

 else if (Request.QueryString["cat"] != null)
            {
            DisplayByCategory();
            }

//end new stuff

        else if (Request.RawUrl.ToLowerInvariant().Contains("/author/"))
            {
            DisplayAuthors();
            }
Coordinator
Aug 18, 2012 at 1:48 AM

I'm a little at lost. The way you load category is:

http://domain.com/blog/category/categoryname.aspx

Why do you need to work around it?

Aug 18, 2012 at 6:28 PM

The problem is that I could not select the theme and category at the same time. I describe the problem in the following post:

http://blogengine.codeplex.com/discussions/362163

Intuitively, I wanted to use http://domain.com/blog/category/nameofcategory.aspx?theme=nameoftheme

That did not work, so I tried to combine parameters with &

Coordinator
Aug 19, 2012 at 7:01 AM

What do you mean "not working"? For example, if you try link below you'll see that theme changes from normally used "boldy" to "standard". It doesn't do it in your case or you expect it to do something different?

http://rtur.net/blog/category/aspnet.aspx?theme=standard

Aug 19, 2012 at 9:27 PM

I am not sure exactly why it is not working but when I combine the url routing and query parameter like: http://domain.com/category/foo.aspx?theme=bar ... the theme changes to bar, but the posts are not all in the category of foo.

 

If I do http://domain.com/category/foo.aspx ... that makes all of the posts in category show the foo category. It is different behavior if the query parameter is added

Aug 19, 2012 at 9:34 PM

I checked out your example(rtur.net) and it looks like you do not have the same behavior.

 

I modified my version of BE as a result of fixing another problem described in the following post: http://blogengine.codeplex.com/discussions/360321 

 

Maybe that is the problem?

Aug 20, 2012 at 5:33 PM

 

If it helps at all, here is some more information:

http://domain.com/blog/category/foo.aspx?theme=bar --- changes the theme, but does not show foo as the category --- it also shows "http://domain.com/blog/default.aspx?id=90916e1a-3ea0-4b20-be73-b95d309ab150&" in the address bar. The id number shown is the CategoryID of the category foo. Foo is not selected as the category, but the theme is selected. Very strange, could it have something to do with the modifications made to set the theme cookie? 
Coordinator
Aug 20, 2012 at 7:00 PM

It shouldn't, but you can remove that modification, which is just a few lines of code, and see if it changes behavior.