Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label Tech Tips. Show all posts
Showing posts with label Tech Tips. Show all posts

Saturday, January 21, 2017

How to avoid “api/sitecore” from Sitecore MVC link URL


There was one Logout link which is working fine in our application, but its URL was looking very weird as http://sitecorelessons/api/sitecore/account/logout.

Client told us to remove that “/api/sitecore” part, even we are also thinking why this “api/sitecore” is coming in URL?

Why “api/sitecore” is coming?

We are generating hyper link with MVC ActionLink() method as 

@Html.ActionLink("Logout", "Logout", "Account", null, new { @class = "btn btn-logout" })

We had used View Rendering for logout section which uses the SitecoreController to render itself and that’s why URL is generated with the default route of Sitecore which ultimately include "api/sitecore" part.

How to solve this?

     1. Create map route for logout action method as

using Sitecore.Pipelines;

public class ConfigureRoutes
{
    public virtual void Process(PipelineArgs args)
    {
        RouteTable.Routes.MapRoute(
            name: "Accountlogout",
            url: "Account/Logout/{id}",
            defaults: new { controller = "Account", action = "Logout", id = UrlParameter.Optional }
            );
    }
}

    2. Point your Controller to move two folder up as

@Html.ActionLink("Logout", "Logout", "../../Account", null, new { @class = "btn btn-logout" })

That’s it. Now when I checked the link on page, it created correctly and working fine as

I hope you like this Sitecore tip. Stay tuned for more Sitecore related articles.

Till that happy sitecoring :)

Please leave your comments or share this article if it’s useful for you.

Thursday, November 17, 2016

How to add task page in Sitecore Control Panel



This article is about adding task link and option in Sitecore control panel.

Here are quick steps 


  •  Login to Sitecore Desktop mode.
  • Select CORE Database
  • Open Content Editor
  • Add a new task page “My Task Page” under item “/sitecore/content/Applications/Control Panel” which is inherited from “/sitecore/templates/Sitecore Client/Tasks/Task page”.
o    Task page has two fields
§  Header – Enter text of Task page section
§  Icon – Specify path of icon image

  •  You can add Task Link and Task Option under Task page.
  • Add a new task link “My Task Link” under item “/sitecore/content/Applications/Control Panel/My Task page” which is inherited from “/sitecore/templates/Sitecore Client/Tasks/Task link”.
o    Task Link has three fields
§  Click – Specify verb name
§  Header – Enter text of Task link section
§  Icon – Specify path of icon image

  • Add a new Task Option “My Task Option” under item “/sitecore/content/Applications/Control Panel/My Task page” which is inherited from “/sitecore/templates/Sitecore Client/Tasks/Task option”.
o    Task Link has four fields
§  Click – Specify verb name
§  Header – Enter text of Task link section
§  ID – Specified ID of this task option
§  URL – Specify link

 
I added 2 items under task page for testing as

task page
Task Page


and that’s it.

So after adding task link and task option, my Sitecore Control Panel looks as

control panel
Control Panel


As you can notice, there is vacant space in My Task Page region. So to remove this, I just move down “My Task Page” under “Reports” item in CORE database content tree.

By moving position of an item, my Sitecore Control Panel looks much better now as

updated control panel
Updated Control Panel


I hope you like this quick Sitecore lesson. Stay tuned for more Sitecore related articles.

Till that happy sitecoring :)

Please leave your comments or share this article if it’s useful for you.