2 Replies - 1556 Views - Last Post: 28 March 2013 - 06:28 AM Rate Topic: -----

#1 Vouksh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-September 12

Best website/file structure practices?

Posted 27 March 2013 - 09:23 PM

I'm pretty new to ASP.NET, building my first simple website using C#/RazorV2, hosting it on the free Windows Azure site.

I've found plenty of articles explaining how the URL structure works, and I've mostly got it figured out, but what I'm wonder is, what's the best/safest/most correct way of doing it?

Is it better to actually have multiple smaller files to handle things? Or is it "OK" or accepted to have one file handle several things?

For example, I'm building a simple blog web app, and right now I'm using single files to handle multiple sections, like I have a Blog.cshtml:
    if (urlDepth > 0) {
        renderPost = new List<BlogPost>();
        switch (UrlData[0]) {
            case "Post":
                int _postID = 0;
                _postID = Convert.ToInt32(UrlData[1]);
                renderPost.Add(blogRender.ShowSinglePost(_postID));
                Page.Title = renderPost[0].Name;
                break;
            case "Category":
                BlogCategory selCat = catDisplay.GetCategory(UrlData[1].Replace("_", " "));
                Page.Title = selCat.Name;
                renderPost = blogRender.PostsInCategory(selCat.ID);
                break;
        }
    } else {
        renderPost = blogRender.MultiplePosts(10);
    }

I know it's a bit crude as it is, but it's a work-in-progress, I plan on making it more failsafe as I go. But before I get too deep into it and possibly end up needing to tear it apart, Would it be better to actually just make a folder named Blog, and have separate Post.cshtml and Category.cshtml files to handle their respective areas?

Figure it's best to know now so I can fix it if need be, rather than find out down the road that I messed up and have to try and pry apart the code.

Is This A Good Question/Topic? 0
  • +

Replies To: Best website/file structure practices?

#2 Vouksh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-September 12

Re: Best website/file structure practices?

Posted 27 March 2013 - 09:31 PM

Sorry for the double post, but if someone wants to see it in action to get a better idea of what I'm doing, it's currently at http://vouksh.azurewebsites.net/

Can't figure out how to edit my post.. ><
Was This Post Helpful? 0
  • +
  • -

#3 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 282
  • Posts: 1,491
  • Joined: 07-April 08

Re: Best website/file structure practices?

Posted 28 March 2013 - 06:28 AM

A file should be for one object. When you say file you need to be a bit more clear as a file can be anything. It looks like you are using ASP.NET MVC so you will have models, views, and controllers.

Each controller should work on a single object and each view should be for a single Action, such as if you have a CustomerController you would have a view for Index a view for edit aswell. When you try and have things handle multiple tasks, object, ect. you are adding unneeded complexity and confusion.

This post has been edited by rgfirefly24: 28 March 2013 - 06:28 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1