Surendra Sharma

Surendra Sharma

Search This Blog

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, January 12, 2017

How to publish a single file in Visual Studio



I just learn a new secret of Visual Studio.

There are almost 10 projects in my single solution in Visual Studio. Every time if I make the changes in any file I have to build and publish it again to verify the changes on browser. If some code file is there than it’s understood that we have to build the solution and publish it. 

However if some static file is there like HTML, ASPX, XML, JS, CSS etc., still I was build the whole project and publish it where no code changes are involved. Ultimately to test the page I have to reload my web application which take enough time.

But Visual Studio provide a nice feature of publishing only a single file. This feature is very useful if file is static like HTML, aspx, XML, JS, CSS, image etc. You can also publish the code file as well.

You can use any of the mentioned way to use this feature

  • Just right click on file in Solution Explorer and select "Publish <FileName>".

  • Shortcut command is "Alt+; Alt+P".


Publish File from Solution Explorer
Publish File from Solution Explorer



  • Project Menu -> "Publish <FileName>".


Publish File from Project Menu
Publish File from Project Menu

It publish the single file within a fraction of second and now if you reload the page it will load quickly in browser.

I hope you like this hidden secret of Visual Studio. Stay tuned for more articles.

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