Best URL/File Structure Practices?
-
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 wondering 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();
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]);
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. 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/
-
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 wondering 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();
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]);
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. 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/
IMO it is okay to handle differrent permission for the same thing, i.e. the admin can delete a blog post on the same page as a user can view blog posts. I would not use the same page for Categories and blog posts because they are two different things. The more features/things which can be display (categories, blog posts etc.) you add to a page the more crowded the pages' code behind gets and sooner or later you will loose the overview.
cheers Marco Bertschi
Software Developer & Founder SMGT Web-Portal CP Profile | Twitter | Facebook | SMGT Web-Portal
FizzBuzz - Gary Wheeler
-
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 wondering 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();
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]);
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. 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/
But the page looks good!
cheers Marco Bertschi
Software Developer & Founder SMGT Web-Portal CP Profile | Twitter | Facebook | SMGT Web-Portal
FizzBuzz - Gary Wheeler