Posted by admin under General  sBlog.Net  Customizations  sBlog.Net v2.0  on Dec 01 2013

I have published yet another theme based on bootstrap! You can get it here! A demo helps always right? Visit the blog, it now uses the theme I just published! If you need some help on installing / using this theme, refer to this post!

Tagged sblog.net 
Posted by admin under General  sBlog.Net  Customizations  sBlog.Net v2.0  on Sep 07 2013

Hello people! 

I have published a new theme using bootstrap. It was in my to-do list for a long time and I am happy I got to this atlast! You can download this here! If you want to look at a sample, you are already seeing it!

To use this theme, download the zip file. Right click on the zip file, choose "Extract Here" [WinRAR] (If you choose "Extract to Folder.." the following may not apply. Once you extract the file, you will see the following folder structure:

                GoBootstrapDark
                                |
                                |
                                ----- css
                               |
                               ------ js
                               |
                               ------ img
                               | 
                               ------ _Layout.cshtml
                               | 
                               ----- _LayoutPage.cshmtl

With Themes folder in your web application, the same structure should be recreated (as shown below).

                Themes
                |
                ---- GoBootstrapDark
                                |
                                |
                                ----- css
                               |
                               ------ js
                               |
                               ------ img
                               | 
                               ------ _Layout.cshtml
                               | 
                               ----- _LayoutPage.cshmtl

That's it! Now, if you logon to the admin section,  go to the settings page, you will now see the new theme in the dropdown, select, update the settings, that's it! You are all set to rock on!!!

Tagged sblog.net  theming 
Posted by admin under General  Customizations  sBlog.Net v2.0  on Nov 15 2013

In this post, I am going to discuss a method by which you could change how the urls appear when a post's title is clicked. By default the when the title of the post is clicked it appears as "http://sblogproject.net/2013/09/new-theme-published-using-bootstrap". What if you wanted this to appear as "http://sblogproject.net/new-theme-published-using-bootstrap.html"? Here are the steps to do this!

We all love test driven development right? So let me start with changing the unit tests for the post routes.

// Update RouteTests.cs

[TestMethod]
public void Can_Identify_Individual_Post()
{
    var context = new MockHttpContext(0, false, "~/some-post.html");
    var routes = new RouteCollection();
    MvcApplication.RegisterRoutes(routes);
 
    var routeData = routes.GetRouteData(context);
 
    Assert.IsNotNull(routeData);
    Assert.AreEqual("Home", routeData.Values["controller"]);
    Assert.AreEqual("ViewPost", routeData.Values["action"]);
    Assert.AreEqual("some-post", routeData.Values["url"]);            
}
 
[TestMethod]
public void Can_Identify_Individual_Post_With_Status()
{
    var context = new MockHttpContext(0, false, "~/some-post.html/comment-posted");
    var routes = new RouteCollection();
    MvcApplication.RegisterRoutes(routes);
 
    var routeData = routes.GetRouteData(context);
 
    Assert.IsNotNull(routeData);
    Assert.AreEqual("Home", routeData.Values["controller"]);
    Assert.AreEqual("ViewPost", routeData.Values["action"]);
    Assert.AreEqual("some-post", routeData.Values["url"]);
    Assert.AreEqual("comment-posted", routeData.Values["status"]);
}

// Change HomeControllerTests.cs

[TestMethod]
public void Can_Return_Posts_By_URL()
{
    var httpContext = GetHttpContext(false, 0);
    var postController = GetHomeControllerInstance(httpContext);
    postController.ControllerContext = new ControllerContext { HttpContext = httpContext };
    var result = (ViewResult)postController.ViewPost("a-test-url-1", "");
    var model = result.ViewData.Model as ViewPostOrPageModel;
    Assert.IsNotNull(model);
    var post = model.Post;
    Assert.IsNotNull(post);
    Assert.AreEqual("Post Title 1", post.PostTitle);
    Assert.AreEqual(2012, post.PostAddedDate.Year);
    Assert.AreEqual(4, post.PostAddedDate.Month);
}
 
[TestMethod]
public void Can_Return_Posts_By_URL_Private_Owner()
{
    var httpContext = GetHttpContext(true, 1);
    var postController = GetHomeControllerInstance(httpContext);
    postController.ControllerContext = new ControllerContext { HttpContext = httpContext };
    var result = (ViewResult)postController.ViewPost("a-test-url-14", "");
    var model = result.ViewData.Model as ViewPostOrPageModel;
    Assert.IsNotNull(model);
    var post = model.Post;
    Assert.IsNotNull(post);
    Assert.AreEqual("[Private] Post Title 14", post.PostTitle);
    Assert.AreEqual(2012, post.PostAddedDate.Year);
    Assert.AreEqual(4, post.PostAddedDate.Month);
}
 
[TestMethod]
public void Can_Return_Posts_By_URL_Private_Admin()
{
    var httpContext = GetHttpContext(true, 1);
    var postController = GetHomeControllerInstance(httpContext);
    postController.ControllerContext = new ControllerContext { HttpContext = httpContext };
    var result = (ViewResult)postController.ViewPost("a-test-url-11", "");
    var model = result.ViewData.Model as ViewPostOrPageModel;
    Assert.IsNotNull(model);
    var post = model.Post;
    Assert.IsNotNull(post);
    Assert.AreEqual("[Private] Post Title 11", post.PostTitle);
    Assert.AreEqual(2012, post.PostAddedDate.Year);
    Assert.AreEqual(4, post.PostAddedDate.Month);
}        
 
[TestMethod]
[ExpectedException(typeof(UrlNotFoundException), "Unable to find a post w/ the url a-test-url-25 for the month 01 and year 2012")]
public void Can_Throw_Appropriate_Exception_When_Accessing_Private_Post()
{
    var httpContext = GetHttpContext(true, 1);
    var postController = GetHomeControllerInstance(httpContext);
    postController.ControllerContext = new ControllerContext { HttpContext = httpContext };
    var result = (ViewResult)postController.ViewPost("a-test-url-25", "");
    var model = result.ViewData.Model as ViewPostOrPageModel;
    Assert.IsNotNull(model);
    var post = model.Post;
}
 
[TestMethod]
[ExpectedException(typeof(UrlNotFoundException), "Unable to find a post w/ the url a-test-url-10 for the month 04 and year 2012")]
public void Can_Return_Posts_By_URL_Private_Non_Admin()
{
    var httpContext = GetHttpContext(true, 2);
    var postController = GetHomeControllerInstance(httpContext);
    postController.ControllerContext = new ControllerContext { HttpContext = httpContext };
    var result = (ViewResult)postController.ViewPost("a-test-url-10", "");
    var model = result.ViewData.Model as ViewPostOrPageModel;
    Assert.IsNotNull(model);
    var post = model.Post;
}

Next, the route definition for an individual post has to be updated in order to modify the url format as shown below:

routes.MapRoute("IndividualPost", "{url}.html/{status}",
                new { controller = "Home", action = "ViewPost", status = UrlParameter.Optional },
                new { url = @"\S+", status = @"[a-z\-]*" });

If you notice, the value for action has been changed to "ViewPost" from "View". Now the controller has to be updated to take care of these changes. To begin with I have change the method name to ViewPost. Then this action method is not going to receive the year and the month any more, but only the url (and optionally status). Here is the updated action method.

public ActionResult ViewPost(string url, string status)
{
    var allPosts = GetPostsInternal();
    var currentPost = allPosts.SingleOrDefault(p => p.PostUrl == url && p.EntryType == 1);
 
    if (currentPost == null)
    {
        throw new UrlNotFoundException("Unable to find a post w/ the url {0}", url);
    }

    // -- Cut for brevity --     

    return View(model);
}

The next step is to change the file name of sBlog.Net\Views\Home\View.cshtml to ViewPost.cshtml. And here is the updated content for this file.

@model sBlog.Net.Models.ViewPostOrPageModel
 
@if (Model.PreviousPost != null)
{
    <div style="float: left">
        @Html.RouteLink("<< Previous Post", "IndividualPost", new { url = Model.PreviousPost.PostUrl, status = string.Empty }, new { @title = Model.PreviousPost.PostTitle })
    </div>
}
 
@if (Model.NextPost != null)
{
    <div style="float: right">
        @Html.RouteLink("Next Post >>", "IndividualPost", new { url = Model.NextPost.PostUrl }, new { @title = Model.NextPost.PostTitle })
    </div>
}

Finally, update the sBlog.Net\Views\Shared\Post.cshtml file to present the new url format for the title link for the post.

<div class="post">
    @{
        var url = Url.RouteUrl("IndividualPost", new { url = Model.Post.PostUrl, status = string.Empty });
    }
    
    ....
    
</div>

Hope this post was interesting! If you do have any questions/ comments post them here!

Posted by admin under General  sBlog.Net  Disqus  sBlog.Net v2.0  on Feb 24 2013

To get started with this project, you need the following:

  • ASP.Net 4 Framework
  • Visual Studio 2010
  • ASP.Net MVC 3
  • MS SQL Server (or MS SQL Server Express)

Assuming, you satisfy the pre-requisites, follow the steps below to get started!

  • Download the sBlog.Net binaries zip file and extract the files.
  • Launch MS SQL server, create a new database for use by your blog - as an administrator or a user who has db_creator privileges. If the database was created by the user that is going to be used in the web.config file, skip the following steps to give db_owner access.
    • Then, if you don't already have a login, create a login
    • Now, you need to provide access to the newly created database for the user you created in the previous step
    • To do this, expand Security, then expand Logins, right click on the user your created, choose Properties
    • In the dialog that appears, choose User Mapping
    • In the right pane, select the database you created, check the checkbox corresponding to the new database
    • In the Database role membership section, choose db_owner, click on OK
  • Now (assuming your IIS directory is C:\inetpub\wwwroot), create a folder called sblog
  • Copy the contents of the folder extracted to the folder you created in the previous step
  • Now, right click on the "Uploads" folder, choose Properties. Then select the "Security" tab
  • Click on "Edit", if you do not find IIS_IUSRS add it. Then select the user, give "Full Control" for the Uploads folder, click on OK in the dialogs opened
  • Then, open the web.config file and modify the connection string to use the new database, user you created, copy this over since you require this while setting up the site!
  • Now open IIS manager, from the Start menu or by entering inetmgr in your Run dialog
  • Create a new website by right clicking on the Sites node and choosing Add Web Site
  • In the Add Web Site dialog,Now your website is all set to be used
    • Enter a site name
    • Select ASP.Net 4.0 application pool (or) create a new app pool that uses the ASP.Net 4.0 framework
    • In the Physical path text box, choose the folder (sblog), created in the previous step
    • Now select OK
  • In case you are using a website provider like godaddy, copy over the files using an ftp client of your choice.
  • To launch the web site, right click on it, choose "Manage Web Site" and then "Browse"
  • If you are using a provider like godaddy, go to the browser and enter your website address and follow the on-screen instructions.
Here is a blog post that might help you with the setup. In case you are hosting the blog using shared hosting, you may have to "bin-deploy" asp.net mvc 3 - refer to this blog post for more information!

For setup instructions using visual studio, click here! Now, you are all set to start using your instance of sBlog.Net!!

Tagged sblog.net  iis 
Posted by admin under General  sBlog.Net  sBlog.Net v2.0  on Feb 24 2013

To get started with this project, you need the following:

  • ASP.Net 4 Framework
  • Visual Studio 2010
  • ASP.Net MVC 3
  • MS SQL Server (or MS SQL Server Express)

Assuming, you satisfy the pre-requisites, follow the steps below to get started!

  • Download the sBlog.Net sources and open it in Visual Studio
  • Launch MS SQL server, create a new database for use by your blog - as an administrator or a user who has db_creator privileges. If the database was created by the user that is going to be used in the web.config file, skip the following steps to give db_owner access.
    • Then, if you don't already have a login, create a login
    • Now, you need to provide access to the newly created database for the user you created in the previous step
    • To do this, expand Security, then expand Logins, right click on the user your created, choose Properties
    • In the dialog that appears, choose User Mapping
    • In the right pane, select the database you created, check the checkbox corresponding to the new database
    • In the Database role membership section, choose db_owner, click on OK
  • Go to visual studio, expand the sBlog.Net project, open the web.config file and modify the connection string to use the new database, user you created
  • Hit on Ctrl + F5, you will get to the setup screen. Just follow the on-screen instructions from now on!
For instructions on setting up sBlog.Net using IIS click here!

Hope this post helped you in getting started with sBlog.Net!


<< Previous Page