+
Skip to content

Get page URL by PageId #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Mix.Cms.Lib/Helpers/MixCmsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,25 @@ public static string TranslateUrl(string url, string srcCulture, string destCult
: $"/{destCulture}{url}";
}

public static string GetUrlByPageId(int pageId, string culture)
{
using var context = new MixCmsContext();
var seoName = context.MixPage.Where(p => p.Id == pageId && p.Specificulture == culture).Select(p => p.SeoName).FirstOrDefault();
if (seoName == null)
{
return $"/{culture}";
}

string seoUrl = $"/{culture}/{seoName}";
var urlAlias = context.MixUrlAlias.Where(m => m.SourceId == pageId.ToString() && m.Specificulture == culture).Select(p => p.Alias).FirstOrDefault();
if (urlAlias == null)
{
return seoUrl;
}

return urlAlias;
}

public static string BuildUrl(HttpContext context, string key, string value)
{
var nameValueCollection = new NameValueCollection
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载