EPiServer Search

Also called the EPiServer Full Text Search/EPIServer FTS.

In web.config there should be something like this:

<add name=”localIndex” baseUri=”http://mysite.local/IndexingService/IndexingService.svc ” accessKey=”local” />

 

Be sure that the url contains your url.

Also there is a hidden url for updating the index:

http://www.xxxx.com/EPiServer/CMS/Admin/IndexContent.aspx

 

More info

http://sveinaandahl.blogspot.se/2013/06/how-to-install-episerver-search-for.html

Syntax highlighter in WordPress

 

If you need some code highligthning test this

[ sourcecode language=”csharp” ] (without spaces)
Your code
[ /sourcecode ] (without spaces)

This will make the code look similar to this:


public ActionResult SomePage()

{

var model = new SomePageModel();

return this.View(null, model);

}

You can also try:

[ code language=”csharp” ]
your code here
[ /code ]

This will make the code look similar to this:

public ActionResult SomePage() {
var model = new SomePageModel();
return this.View(null, model);
}

 

 

Read More

https://en.support.wordpress.com/code/posting-source-code/

Paging with filters in Umbraco 7

In the controller:

public ActionResult SomePage()
{
var model = new SomePageModel();

return this.View(null, model);
}

protected ViewResult View(string view, SomePageModel model)
{
var search = QueryString&amp;amp;amp;lt;Int32&amp;amp;amp;gt;.Value(&amp;amp;quot;search&amp;amp;quot;, 0);
var county = QueryString&amp;amp;amp;lt;string&amp;amp;amp;gt;.Value(&amp;amp;quot;county&amp;amp;quot;, string.Empty);

var result = base.View(view, model);

model.SearchFormVM = new SearchFormViewModel(CurrentPage, model, true);

if (search == 1)
{

IPublishedContent someContainer = model.Umbraco.TypedContent(model.RootModel.SomeContainer);

var nodes = someContainer.Descendants(&amp;amp;quot;Somepage&amp;amp;quot;).Where(x =&amp;amp;amp;gt; x.IsVisible());

var filteredNodes = nodes.Select(x =&amp;amp;amp;gt; new SomePageModel(x));

if (!string.IsNullOrEmpty(county))
{
filteredNodes = filteredNodes.Where(x =&amp;amp;amp;gt; x.County == county);
}

model.SearchFormVM.SomePages = filteredNodes.OrderByDescending(x =&amp;amp;amp;gt; x.CurrentPage.CreateDate).ToList();
}
else
{
model.ShowForm = true;
}

return result;
}

In the view:

<h1>@Model.Header</h1>
<div class="search-form">

@if (Model.ShowForm)
{
@Model.BodyText

using (Html.BeginUmbracoForm<Namepace.Controllers.SearchFormSurfaceController>("HandleFormPost", new { @role = "form" }))
{
<div class="form-group">
<label for="SearchFormVM.County">County</label>
@{
<select name="SearchFormVM.County" id="SearchFormVM.County" class="form-control">
<option value="">All</option>
@foreach (var item in @Model.SearchFormVM.CountyData)
{
<option value="@item.Id">@item.Value</option>
}
</select>
}
</div>
}

</div>
<button type="submit" class="btn btn-default btn-success">Search</button>
}
}
else
{
var pageSize = 20;
var page = 1;
int.TryParse(Request.QueryString["page"], out page);
var items = Model.SearchFormVM.SomePages;
var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);
<div class="search-result">

@if (items.Count < 1)
{
No result.
}
@foreach (var somePage in Model.SearchFormVM.SomePages.Skip((page - 1) * pageSize).Take(pageSize))
{
<div class="row search-result-row">
<div class="col-md-7">
some data

</div>
<div class="col-md-5">
<a href="@somePage.Url">
<h3>@somePage.Header</h3>
</a>
<h4>County:</h4>
@somePage.CountyString

</div>
</div>
}

@{
var nextPage = page + 1;
var queryStringsInPager = string.Empty;
foreach (string key in Request.QueryString)
{
string value = Request.QueryString[key];

if (!String.IsNullOrEmpty(value))
{

if (key.ToLower() != "page")
{
queryStringsInPager += "&" + key.ToLower() + "=" + value;
}
}
}

}
@if (items.Count > pageSize)
{
<ul class="pagination">
@if (page > 1)
{
	<li>
<a href="?page=@(page-1)@queryStringsInPager"><</a></li>
}
@for (int p = 1; p < totalPages + 1; p++)
{
var active = (p == page) ? " class=\"active\"" : string.Empty;
	<li @Html.Raw(active)>
<a href="?page=@p@queryStringsInPager">@p</a></li>
}
@if (page < totalPages)
{
	<li>
<a href="?page=@nextPage@queryStringsInPager">></a></li>
}</ul>
}



<a href="@Model.CurrentPage.Url">New search</a>
</div>
}
</div>

 

In the SurfaceController

[HttpPost]
public void HandleFormPost(SomePageModel model)
{
var page = QueryString<int>.Value(“page”, 1);

string longurl = CurrentPage.UrlAbsolute();
var uriBuilder = new UriBuilder(longurl);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);

query[“page”] = page.ToString();

query[“search”] = “1”;

if (!string.IsNullOrEmpty(model.SearchFormVM.County))
{
query[“county”] = model.SearchFormVM.County;
}

uriBuilder.Query = query.ToString();
longurl = uriBuilder.ToString();

Response.Redirect(longurl);
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Validate on client side that a user has checked the Google Recaptcha checkbox

This is just to see if the user has checked the check box for Google Recaptcha v2.0. You really need to have a better server side validation too!!

First set an id on your form (for example id google-response-form), then:

$(function () {
$(“#google-response-form”).submit(function (event) {

var $gcheck = $(‘#g-recaptcha-response’);
var googleResponse = $gcheck.val();
if (googleResponse === “”)
{
alert(“Verify that you’re not a robot”);
event.preventDefault();
}
});
});

 

More info

http://stackoverflow.com/questions/28602777/asp-net-mvc-4-set-onsubmit-on-form-submission

How to redirect non-www URLs to www

Write the following code in the web.config:

<system.webServer>
<rewrite>
<rules>
<rule name=”Redirect to www”>
<match url=”.*” />
<conditions logicalGrouping=”MatchAny”>
<add input=”{HTTP_HOST}” pattern=”^(www\.)(.*)$” negate=”true” />
</conditions>
<action type=”Redirect” url=”http://www.{HTTP_HOST}/{R:0}” redirectType=”Permanent”/>
</rule>
</rules>
</rewrite>
</system.webServer>

 

If you get an error it may be because the extension URL Rewrite 2.0 is not installed in the IIS. If so install it with for example Web Plattform Installer.

 

More info

http://www.dotnetexpertguide.com/2011/08/iis-7-redirect-domaincom-to.html

Importing a copy of a SQL Azure database to your local SQL Server Express

Use SqlPackage.exe by opening a command prompt and go to:

C:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin

Then write the following to get a bacpac-file from Azure:

sqlpackage /a:Export /ssn:"azure_db_server" /sdn:"azure_db_name" /su:"user_name" /sp:"password" /tf:"file.bacpac"

Now it’s time to import to your local SQL Server Express:

sqlpackage /a:Import /SourceFile:"file.bacpac" /TargetServerName:".\SQLEXPRESS" /TargetDatabaseName:CopyOfAzureDb

 

More info

http://stackoverflow.com/questions/5475306/how-do-i-copy-sql-azure-database-to-my-local-development-server

Seed data into an existing SQL Azure Database in ASP.NET 5.0

For this to work you should lalready have a database configured and I assume you also has the project configured as the starter project in VS 2015.

For this scenario let’s say you have one company class and one class for the companies business hours and you have created two database tables for these. Now you want to ensure you atleast have two companies with business hours in the database.

First create the class “ApplicationContextSeedData.cs”:

public class ApplicationContextSeedData
{
private ApplicationDbContext _context;

public ApplicationContextSeedData(ApplicationDbContext context)
{
_context = context;
}

public void EnsureSeedData()
{
if (!_context.Companies.Any())
{
var company1 = new Company()
{
Name = “Name 1”,
Latitude = 69.297169,
Longitude = 28.051686,
PostalCity = 1,
BusinessHours = new List<BusinessHour>()
{
new BusinessHour()
{
DayOfWeek = 1,
ClosingTime = new DateTime(1982, 12, 13, 5, 0, 0),
OpeningTime = new DateTime(1982, 12, 13, 23, 0, 0)
},
new BusinessHour()
{
DayOfWeek = 2,
ClosingTime = new DateTime(1982, 12, 13, 6, 0, 0),
OpeningTime = new DateTime(1982, 12, 13, 22, 0, 0)
}
}
};

var company2 = new Company()
{
Name = “Name2”,
Latitude = 69.300117,
Longitude = 28.032260,
PostalCity = 1,
BusinessHours = new List<BusinessHour>()
{
new BusinessHour()
{
DayOfWeek = 1,
OpeningTime = new DateTime(1982, 11, 13, 10, 0, 0),
ClosingTime = new DateTime(1982, 11, 13, 12, 0, 0)
},
new BusinessHour()
{
DayOfWeek = 2,
OpeningTime = new DateTime(1982, 12, 13, 8, 0, 0),
ClosingTime = new DateTime(1982, 12, 13, 21, 0, 0)
}
}
};

_context.Companies.Add(company1);
_context.BusinessHours.AddRange(company1.BusinessHours);

_context.Companies.Add(company2);
_context.BusinessHours.AddRange(company2.BusinessHours);

_context.SaveChanges();
}
}
}

Then in Startup.json in the end of the method ConfigureServices:

services.AddTransient<ApplicationContextSeedData>();

 

Now in the method configure add the new parameter “ApplicationContextSeedData seeder”, so it will look something similar to this:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ApplicationContextSeedData seeder)

Now it’s possible to use the seeder in the end of the Configuremethod:

seeder.EnsureSeedData();