Wenn Unittests nicht gefunden oder ausgeführt werden, kann es helfen, in der SLN die Eigenschaften zu öffnen und dann unter Konfiguration zu prüfen, ob "Erstellen" beim Testprojekt aktiv ist.
Ist das der Fall, über NuGet MsTest und den TestAdapter neu installieren.
7/13/2023 10:44:19 AM
by Chris 573
SEO Urls in ASP.NET Core sind extrem simpel, alles was man braucht ist eine Route an der Action. Bei Interesse kann man die URL auch auswerten, muss man aber nicht.
``` C#
[Route("/Blog/ViewPosting/{id}")]
[Route("/Blog/ViewPosting/{id}/{title}")]
public IActionResult ViewPosting(int id)
{
[...]
return View(posting);
}
```
... <a href="/Blog/ViewPosting/19/seo-urls">(Weiterlesen)</a>
12/21/2022 5:16:40 PM
by Chris 665
Quellen:
* https://andrewlock.net/adding-cache-control-headers-to-static-files-in-asp-net-core/
* https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-7.0
* https://stackoverflow.com/questions/37706370/how-to-cache-css-js-or-images-files-to-asp-net-core
Heute hab ich ein wenig Caching in den Blog eingebaut, als Inspiration hatte ich die Links oben.
Zuerst wird die Program.cs angepasst
``` csharp
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddResponseCaching();
var app = builder.Build();
app.UseStaticFiles(new StaticFileOptions
{
OnPrepareResponse = ctx =>
{
string path = ctx.File.Name.ToLower();
if (path.EndsWith(".css")
|| path.EndsWith(".js")
|| path.EndsWith(".gif")
|| path.EndsWith(".jpg")
|| path.EndsWith(".png")
|| path.EndsWith(".ico")
|| path.EndsWith(".woff2")
|| path.Contains("/blog/getimage/"))
{
var maxAge = new TimeSpan(7, 0, 0, 0);
ctx.Context.Response.Headers.Append("Cache-Control", "max-age=" + maxAge.TotalSeconds.ToString("0"));
}
else
{
//Request for views fall here.
ctx.Context.Response.Headers.Append("Cache-Control", "no-cache");
ctx.Context.Response.Headers.Append("Cache-Control", "private, no-store");
}
}
});
```
Und nun pass wir wir noch die GetImage Funktion an
``` csha
```
... <a href="/Blog/ViewPosting/17/caching-in-asp.net-core">(Weiterlesen)</a>
12/21/2022 5:09:18 PM
by Chris 885
--> https://www.roundthecode.com/dotnet/asp-net-core-web-hosting/how-to-install-an-asp-net-core-in-net-5-app-on-ubuntu-20-04
https://www.how2shout.com/linux/3-ways-to-install-net-6-dotnet-on-ubuntu-20-04-lts-focal-fossa/
``` Bash
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
aptitude update
aptitude install -y apt-transport-https && aspnetcore-runtime-5.0
aptitude install Apache2
a2enmod rewrite && a2enmod proxy && a2enmod proxy_http && a2enmod headers && a2enmod ssl
nano /etc/apache2/sites-enabled/dotNet5.conf
```
```
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
</VirtualHost>
<VirtualHost cschmidt.eu:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName cschmidt.eu
ServerAlias cschmidt.eu
ErrorLog ${APACHE_LOG_DIR}api-error.log
CustomLog ${APACHE_LOG_DIR}api-access.log common
</VirtualHost>
```
asp-net core web app erstellen und per ftp in /var/www/cschmidt-cms publishen
``` Bash
nano /etc/systemd/system/cschmidt-cms.service
```
```
[Unit]
Description=cschmidt-cms
[Service]
WorkingDirectory=/var/www/cschmidt-cms/
ExecStart=/usr/bin/dotnet /var/www/cschmidt-cms/cschmidt-cms.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentif
```
... <a href="/Blog/ViewPosting/2/dotnet-unter-linux">(Weiterlesen)</a>
7/1/2022 10:22:21 PM
by Chris 1060