3

Language culture such as 'en' or 'en-gb' was initially present with a sitecore url. But after a post back, page returns with some validation errors and language culture is missing from url.

What may be the possible reason ?

I checked the link manager config. It is like below

 addAspxExtension="false" alwaysIncludeServerUrl="false"
 encodeNames="true" languageEmbedding="always"
 languageLocation="filePath" lowercaseUrls="true" 
 shortenUrls="false" useDisplayName="true"
 ignoreForSites="shell,login,admin" forceFriendlyUrl="true" 
 trailingSlash="false" onlyApplyForSiteContent="true" 
 resolve="true" previewSearchIndexName="sitecore_master_index" 
 liveSearchIndexName="sitecore_master_index"

Mind that languageEmbedding is true.

And the view is below

    @model ChangePasswordViewModel
@using Foundation.Dictionary.Extensions
@using Foundation.SitecoreExtensions.Extensions
@using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post))

    @Html.AddUniqueFormId()
    @Html.AntiForgeryToken()
    @Html.HiddenFor(model => model.UserName);
    <div class="form-horizontal my-5">
        <div class="form-group">
            <div class="row">
                <div class="col-md-10">
                    <label class="control-label">Change Password</label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-7">
                @Html.PasswordFor(model => model.OldPassword, new { @class = "form-control" })

            </div>
        </div>

        <div class="form-group">
            <div class="col-md-7">
                @Html.PasswordFor(model => model.NewPassword, new { @class = "form-control" })

            </div>
        </div>

        <div class="form-group">
            <div class="col-md-7">
                @Html.PasswordFor(model => model.ConfirmPassword, new { @class = "form-control" })

            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-5 col-md-10">
                <input type="submit" value="Update" class="btn btn-gradient-3" />
            </div>
        </div>
        @Html.ValidationSummary(false, "", new { @class = "text-danger" })
        <div class="form-group">
            <div class="row">
                <div class="col-md-10">
                    @if (ViewBag.ChangePasswordMessage != null)
                    {
                        <div class="alert alert-success">
                            @ViewBag.ChangePasswordMessage
                        </div>
                    }
                </div>
            </div>
        </div>

    </div>
  • Are you sure the config is not patched by some other config file? Please navigate to /sitecore/admin/showconfig.aspx page and check what is effective config there – Peter Procházka Nov 22 '18 at 5:58
  • We are using a patch file. I checked in the showconfig.aspx and languageEmbedding="always" there. – Hrishikesh T T Nov 22 '18 at 6:51
  • WebForms or MVC? Are you posting a custom form to a controller? Post up code of the form on the razor view – jammykam Nov 22 '18 at 7:29
  • We are using MVC @using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post)) { – Hrishikesh T T Nov 22 '18 at 8:19
  • I cant post the whole razor view because of size limitations. It has 3 text boxes for old password, new password, confirm new pass word with an update button – Hrishikesh T T Nov 22 '18 at 8:22
1

Instead of using Html.BeginRouteForm, try using Html.BeginForm without any parameters like this:

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    ....
}

This will set the action attribute of your form tag to the url of your current page.

  • It worked, when using Html.BeginForm language culture is appended to form tag's action attribute.What may be the possible differences between the two? – Hrishikesh T T Nov 23 '18 at 12:43
0

There are two places were the original setting for LinkManager can be overwritten:

1. By having a patch config file in your solution

Check whether you don't have <linkManager> element somewhere in your custom patch config files.

It should look something like this:

<linkManager defaultProvider="sitecore">
    <providers>
        <clear/>
        <add name="sitecore" ... languageEmbedding="never" ... />
    </providers>
</linkManager>

The languageEmbedding options are:

asNeeded
always
never

Changing the config to use languageEmbedding="never" will stop the language from showing up in the URL, and likewise languageEmbedding="always" will force the language to always show up in the URL.

Probably you have it set to never.

Check it also by navigating to {your_sitecore_instance_url}/sitecore/admin/showconfig.aspx and how linkManager is configured effectively there.

2. By changing this setting for link itself in your code

You can override config settings from code when you are generating link.

Try to find similar code around code where LinkManager generates links in your question. It should be something similar:

var options = Sitecore.Links.LinkManager.GetDefaultUrlOptions(); 
options.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Never; 
Sitecore.Links.LinkManager.GetItemUrl(item, options);

Try to search for LanguageEmbedding and maybe you will be lucky

(3.) languageEmbedding needs to be set

Make sure languageEmbedding is set to either always or never. Don't leave it set to asNeeded cause this could also cause you trouble! Learnt hard way...

  • I checked these, But LanguageEmbedding is no where set as Never – Hrishikesh T T Nov 22 '18 at 8:27
  • Is languageEmbedding set to Always or AsNeeded? – Peter Procházka Nov 22 '18 at 8:53
  • It is set to Always – Hrishikesh T T Nov 22 '18 at 9:23
  • We checked the scenario in habitat solution, there also it showing same behaviour. – Hrishikesh T T Nov 22 '18 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.