Unable to load shared library 'urlmon.dll' on linux environment - asp.net-core

ASP .NET Core 3.1
System.DllNotFoundException: Unable to load shared library 'urlmon.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liburlmon.dll: cannot open shared object file: No such file or directory
at FindMimeFromData(IntPtr pBC, String pwzUrl, Byte[] pBuffer, Int32 cbSize, String pwzMimeProposed, Int32 dwMimeFlags, IntPtr& ppwzMimeOut, Int32 dwReserved)
at ValidateMimeType(List`1 colBytesFile, htconstructorparams htConstructorParams) in \Share.cs:line 5048
at ValidateFileMimeType(HttpRequest request, htconstructorparams htConstructorParams) in \Share.cs:line 5019
at FileMiddleware.Invoke(HttpContext context) in ''\FileMiddleware.cs:line 43
at JwtMiddleware.Invoke(HttpContext context, IUserSessionService _userSessionService) in ''\JwtMiddleware.cs:line 79
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at ErrorHandlerMiddleware.Invoke(HttpContext context, hk_log_dbcontext logDbContext)

urlmon.dll is a Windows component.
ASP.NET Core is cross-platform, but when you run it on Linux, you can't access any libraries, features or files that are Windows specific, such as urlmon.dll.
If you want to find out the mime type of a file on Linux, you might have to use a Linux-specific solution such as How can I find out a file's MIME type (Content-Type)?.

Related

An error occurred while accessing the Microsoft.Extensions.Hosting services. No application service provider was found

I am trying to script/export Entity Framework Core code-first migrations in Azure DevOps CI pipeline but having an error. The below command runs fine in my Visual Studio locally and generates an sql file and the command work was also working fine a few months ago in DevOps too (not sure if update related).
dotnet ef migrations script --project Booking.Core
--startup-project Booking.Management --idempotent
--output $(build.artifactstagingdirectory)/migrate.sql --verbose
My project is using .NET Core 3.1.5 version and also in pipeline I make sure dotnet-ef command is available like
dotnet tool install --global dotnet-ef --version 3.1.5
But I still keep getting this error:
2020-12-13T09:13:27.8973893Z ##[section]Starting: EF Core Migrations SQL Export
2020-12-13T09:13:27.9112206Z ==============================================================================
2020-12-13T09:13:27.9112480Z Task : PowerShell
2020-12-13T09:13:27.9112737Z Description : Run a PowerShell script on Linux, macOS, or Windows
2020-12-13T09:13:27.9112956Z Version : 2.179.1
2020-12-13T09:13:27.9113144Z Author : Microsoft Corporation
2020-12-13T09:13:27.9113446Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2020-12-13T09:13:27.9113759Z ==============================================================================
2020-12-13T09:13:28.8144250Z Generating script.
2020-12-13T09:13:28.8694723Z ========================== Starting Command Output ===========================
2020-12-13T09:13:28.8987598Z ##[command]"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\fa82967e-1e57-4dba-932d-1453e98ef510.ps1'"
2020-12-13T09:13:29.4639310Z Using project 'Booking.Core\Booking.Core.csproj'.
2020-12-13T09:13:29.4640261Z Using startup project 'Booking.Management\Booking.Management.csproj'.
2020-12-13T09:13:29.4661731Z Writing 'Booking.Core\obj\Booking.Core.csproj.EntityFrameworkCore.targets'...
2020-12-13T09:13:29.4713085Z dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmpBC2B.tmp /verbosity:quiet /nologo Booking.Core\Booking.Core.csproj
2020-12-13T09:13:30.5894726Z Writing 'Booking.Management\obj\Booking.Management.csproj.EntityFrameworkCore.targets'...
2020-12-13T09:13:30.5904170Z dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmpC091.tmp /verbosity:quiet /nologo Booking.Management\Booking.Management.csproj
2020-12-13T09:13:31.4844212Z Build started...
2020-12-13T09:13:31.4848105Z dotnet build Booking.Management\Booking.Management.csproj /verbosity:quiet /nologo
2020-12-13T09:13:39.4566730Z
2020-12-13T09:13:39.4680169Z Build succeeded.
2020-12-13T09:13:39.4681347Z 0 Warning(s)
2020-12-13T09:13:39.4681964Z 0 Error(s)
2020-12-13T09:13:39.4682460Z
2020-12-13T09:13:39.4683029Z Time Elapsed 00:00:07.53
2020-12-13T09:13:39.5195940Z Build succeeded.
2020-12-13T09:13:39.5465861Z dotnet exec --depsfile D:\a\1\s\Booking.Management\bin\Debug\netcoreapp3.1\Booking.Management.deps.json --additionalprobingpath C:\Users\VssAdministrator\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\a\1\s\Booking.Management\bin\Debug\netcoreapp3.1\Booking.Management.runtimeconfig.json C:\Users\VssAdministrator\.dotnet\tools\.store\dotnet-ef\3.1.5\dotnet-ef\3.1.5\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations script --idempotent --output D:\a\1\a/migrate.sql --assembly D:\a\1\s\Booking.Management\bin\Debug\netcoreapp3.1\Booking.Core.dll --startup-assembly D:\a\1\s\Booking.Management\bin\Debug\netcoreapp3.1\Booking.Management.dll --project-dir D:\a\1\s\Booking.Core\ --language C# --working-dir D:\a\1\s --verbose --root-namespace Booking.Core
2020-12-13T09:13:39.7619178Z Using assembly 'Booking.Core'.
2020-12-13T09:13:39.7621486Z Using startup assembly 'Booking.Management'.
2020-12-13T09:13:39.7623162Z Using application base 'D:\a\1\s\Booking.Management\bin\Debug\netcoreapp3.1'.
2020-12-13T09:13:39.7624489Z Using working directory 'D:\a\1\s\Booking.Management'.
2020-12-13T09:13:39.7627735Z Using root namespace 'Booking.Core'.
2020-12-13T09:13:39.7628656Z Using project directory 'D:\a\1\s\Booking.Core\'.
2020-12-13T09:13:40.0447318Z Finding DbContext classes...
2020-12-13T09:13:40.0448237Z Finding IDesignTimeDbContextFactory implementations...
2020-12-13T09:13:40.1345335Z Finding application service provider...
2020-12-13T09:13:40.1352141Z Finding Microsoft.Extensions.Hosting service provider...
2020-12-13T09:13:40.1387349Z Using environment 'Development'.
2020-12-13T09:13:41.3123215Z Rollbar.RollbarException: Failed to configure using invalid configuration prototype!
2020-12-13T09:13:41.3123976Z at Rollbar.RollbarLogger.ValidateConfiguration(IRollbarConfig rollbarConfig)
2020-12-13T09:13:41.3124504Z at Rollbar.RollbarLogger.Configure(IRollbarConfig settings)
2020-12-13T09:13:41.3125776Z at Rollbar.RollbarLogger.Rollbar.IRollbar.Configure(IRollbarConfig settings)
2020-12-13T09:13:41.3127983Z at Booking.Management.Startup.ConfigureServices(IServiceCollection services) in D:\a\1\s\Booking.Management\Startup.cs:line 136
2020-12-13T09:13:41.3128521Z at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
2020-12-13T09:13:41.3129014Z at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2020-12-13T09:13:41.3129472Z at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
2020-12-13T09:13:41.3129921Z at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
2020-12-13T09:13:41.3130590Z at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
2020-12-13T09:13:41.3131087Z at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
2020-12-13T09:13:41.3131685Z at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
2020-12-13T09:13:41.3132193Z at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
2020-12-13T09:13:41.3132570Z at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
2020-12-13T09:13:41.3132842Z at Microsoft.Extensions.Hosting.HostBuilder.Build()
2020-12-13T09:13:41.3133338Z An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Failed to configure using invalid configuration prototype!
2020-12-13T09:13:41.3133808Z No application service provider was found.
2020-12-13T09:13:41.3309579Z Finding DbContext classes in the project...
2020-12-13T09:13:41.3402462Z Found DbContext 'ApplicationDbContext'.
2020-12-13T09:13:41.3673060Z Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
2020-12-13T09:13:41.3674225Z ---> System.MissingMethodException: No parameterless constructor defined for type 'Booking.Core.Data.ApplicationDbContext'.
2020-12-13T09:13:41.3674932Z at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
2020-12-13T09:13:41.3675640Z at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
2020-12-13T09:13:41.3676267Z at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
2020-12-13T09:13:41.3676691Z at System.Activator.CreateInstance(Type type)
2020-12-13T09:13:41.3677358Z at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_3.<FindContextTypes>b__13()
2020-12-13T09:13:41.3677798Z --- End of inner exception stack trace ---
2020-12-13T09:13:41.3678247Z at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass13_3.<FindContextTypes>b__13()
2020-12-13T09:13:41.3678609Z at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
2020-12-13T09:13:41.3678993Z at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
2020-12-13T09:13:41.3681847Z at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.ScriptMigration(String fromMigration, String toMigration, Boolean idempotent, String contextType)
2020-12-13T09:13:41.3682773Z at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScriptMigrationImpl(String fromMigration, String toMigration, Boolean idempotent, String contextType)
2020-12-13T09:13:41.3683262Z at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScriptMigration.<>c__DisplayClass0_0.<.ctor>b__0()
2020-12-13T09:13:41.3683647Z at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
2020-12-13T09:13:41.3684014Z at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
2020-12-13T09:13:41.3684531Z Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
2020-12-13T09:13:41.6277035Z ##[error]PowerShell exited with code '1'.
2020-12-13T09:13:41.6727543Z ##[section]Finishing: EF Core Migrations SQL Export
My Program.cs file looks like this:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
My ApplicationDbContext has constructors like:
protected ApplicationDbContext() {}
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, IHttpContextAccessor contextAccessor) : base(options)
{
_contextAccessor = contextAccessor;
}
My Startup.cs file looks like:
public Startup(IWebHostEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)standard environment name (e.g: Local).
.AddUserSecrets<Startup>()
.AddEnvironmentVariables();
Configuration = builder.Build();
Environment = env;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<User, Role>(
config => {...})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddUserValidator<IdendityUserValidator<User>>();
}
Rollbar configuration was failing because for access token it was expecting a string that was not null/empty. Since I store Rollbar access token in Azure AppService Configuration and appsettings.json did not have access token listed, error was happening. So I added access token to appsettings.json with a dummy non-empty string value. That helps Rollbar to configure itself and not fail.

IdentityServer4, WindowsCryptographicException: The system cannot find the file specified

I create an IdentityServer4 project with several client apps. I use a self-signed certificate file my_certificate.pfx to generate login token. It works fine on localhost.
However, it does not work when employing it to a shared web hosting server.
The app that hosts the IdentityServer4 works fine, indicating that the server app can access the certificate file. However, it generates the following error when trying to log in from a client app:
WindowsCryptographicException: The system cannot find the file specified.
System.Security.Cryptography.CngKey.Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions)
System.Security.Cryptography.CngKey.Open(string keyName, CngProvider provider)
Internal.Cryptography.Pal.CertificatePal.GetPrivateKey<T>(Func<CspParameters, T> createCsp, Func<CngKey, T> createCng)
Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey()
System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKey()
Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKeyStatus()
Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider.FoundPrivateKey(SecurityKey key)
Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(SecurityKey key, string algorithm, bool willCreateSignatures)
Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(SecurityKey key, string algorithm, bool willCreateSignatures, CryptoProviderFactory cryptoProviderFactory)
Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateSignatureProvider(SecurityKey key, string algorithm, bool willCreateSignatures)
Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateForSigning(SecurityKey key, string algorithm)
Microsoft.IdentityModel.JsonWebTokens.JwtTokenUtilities.CreateEncodedSignature(string input, SigningCredentials signingCredentials)
System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken token)
IdentityServer4.Services.DefaultTokenCreationService.CreateJwtAsync(JwtSecurityToken jwt)
IdentityServer4.Services.DefaultTokenCreationService.CreateTokenAsync(Token token)
IdentityServer4.Services.DefaultTokenService.CreateSecurityTokenAsync(Token token)
IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateImplicitFlowResponseAsync(ValidatedAuthorizeRequest request, string authorizationCode)
IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateHybridFlowResponseAsync(ValidatedAuthorizeRequest request)
IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest request)
IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, ConsentResponse consent)
IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext context)
IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
How to make the client app works?
Thanks
I ran into this when setting up IdentityServer on AWS ElasticBeanstalk infrastructure and using a local file, rather than the certificate store - however the solution in my case is the same. I found that the app pools on the EC2 instances did not have Load User Profile set true. When set, the permissions model changes and allows the process to load in the cert. You can enable through the IIS management UI on the app pool details, or use a version of the script below.
Import-Module WebAdministration
Set-ItemProperty "IIS:\AppPools\DefaultAppPool" -Name "processModel.loadUserProfile" -Value "True"

.NET Core SignalR 3.0 Exception

NOTE: This is SignalR for .NET Core 3.
I saw a couple of other stackoverflow suggestions (similar but not exact) for the applicationUrl modification which I have tried. I am getting:
Unhandled exception. System.InvalidOperationException: A path base can only be configured using IApplicationBuilder.UsePathBase().
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.ParseAddress(String address, Boolean& https)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func2 createBinding)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication1 application, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at cRioSaturnSignalRHub.Program.RunDefaultWebHostBuilder(String[] args, IConfigurationRoot config) in C:\Workspace\software\DataTier\dotNetCore\v3.x\Daemons\cRioSaturnSignalRHub\cRioSaturnSignalRHub\Program.cs:line 83
at cRioSaturnSignalRHub.Program.RunProcess(String[] args) in C:\Workspace\software\DataTier\dotNetCore\v3.x\Daemons\cRioSaturnSignalRHub\cRioSaturnSignalRHub\Program.cs:line 50
at cRioSaturnSignalRHub.Program.Main(String[] args) in C:\Workspace\software\DataTier\dotNetCore\v3.x\Daemons\cRioSaturnSignalRHub\cRioSaturnSignalRHub\Program.cs:line 27
The launch settings have applicationUrl = "http://localhost:5000" & the endpoint name is not on it as suggested in other stackoverflow related issue.
Any suggestions?
The problem is not at all related to the applicationUrl. Instead I tried the EnvironmentalVariables approach with the ASPNETCORE_URLS="http://*:5000" To do this I added .AddEnvironmentVariables() with the ConfigurationBuilder. & with WebHost.CreateDefaultBuilder(), I added .UseConfiguration(config). After this little change everything works when I publish & run.

How to use the Rotativa.aspnetcore package in Linux Ubuntu OS (asp.net Core 2.1)

Using the Rotativa.aspnetcore package in Ubuntu doesn't know what's wrong?
I use the Visual Studio 2017 MVC Default Template.
Using nuget Rotativa.aspnetcore (https://www.nuget.org/packages/Rotativa.AspNetCore/)
Install-Package Rotativa.AspNetCore -Version 1.1.1
Perform sudo apt-get install Xvfb libfontconfig wkhtmltopdf in Linux Ubuntu OS. wkhtmltopdf and wkhtmltoimage copy it to Web MVC project wwwroot/Rotativa.
According to Rotativa.aspnetcore Git (https://github.com/webgio/Rotativa.AspNetCore) file Needs configuration settings
configuration done in Startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Faceapirequestrecords}/{action=Index}/{id?}");
});
RotativaConfiguration.Setup(env, "/usr/bin");
}
HomeController program code :
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult DemoViewAsPDF()
{
return new ViewAsPdf("Index");
}
}
Deploy and execute MVC applications.
URL : http://localhost:5000/Home/DemoViewAsPDF
Error Message:
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.Exception: QXcbConnection: Could not connect to display
at Rotativa.AspNetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html, String wkhtmlExe)
at Rotativa.AspNetCore.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html)
at Rotativa.AspNetCore.ViewAsPdf.CallTheDriver(ActionContext context)
at Rotativa.AspNetCore.AsResultBase.BuildFile(ActionContext context)
at Rotativa.AspNetCore.AsResultBase.ExecuteResultAsync(ActionContext
context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult
result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsyncTFilter,TFilterAsync
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext
context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State&
next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext
context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next,
Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext
httpContext)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext
context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext
context)
In advance: I didn't test it.
You are trying to call http://localhost:5000/Home/DemoViewAsPDF with port 5000. Rotativa tries to redirect to http***s***://localhost:5000/Home/DemoViewAsPDF. The Port for https is different. Therefore you don't get a result.
Try to use https from the start. This might solve your problem.
You can test if Rotativa works as intended by accessing the program via the command prompt:
wkhtmltopdf.exe www.samplewebsite.com outputfolder+filename+extension

RavenDB Embedded on Azure Websites - Access Denied

I get an Access denied message when I try to deploy my MVC4 site with an Embedded instance of RavenDB to the new Azure Websites preview feature. The site works fine locally.
Here is how I configure Raven:
//Initialize the RavenDB Data Store
Raven.Database.Server.NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8887);
var documentStore = new EmbeddableDocumentStore()
{
DataDirectory = "~\\App_Data",
UseEmbeddedHttpServer = true,
Configuration = { Port = 8887 }
};
documentStore.Initialize();
And here is the stack trace when I browse to the site:
Access is denied
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.NetworkInformation.NetworkInformationException: Access is denied
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NetworkInformationException (0x5): Access is denied]
System.Net.NetworkInformation.SystemIPGlobalProperties.GetAllTcpConnections() +1570717
System.Net.NetworkInformation.SystemIPGlobalProperties.GetActiveTcpListeners() +74
Raven.Database.Util.PortUtil.FindPort() in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Util\PortUtil.cs:110
Raven.Database.Util.PortUtil.GetPort(String portStr) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Util\PortUtil.cs:44
Raven.Database.Config.InMemoryRavenConfiguration.Initialize() in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Config\InMemoryRavenConfiguration.cs:170
Raven.Database.Config.RavenConfiguration.LoadConfigurationAndInitialize(IEnumerable`1 values) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Config\RavenConfiguration.cs:28
Raven.Database.Config.RavenConfiguration..ctor() in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Config\RavenConfiguration.cs:17
Raven.Client.Embedded.EmbeddableDocumentStore.get_Configuration() in c:\Builds\RavenDB-Unstable-v1.2\Raven.Client.Embedded\EmbeddableDocumentStore.cs:63
Raven.Client.Embedded.EmbeddableDocumentStore.set_DataDirectory(String value) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Client.Embedded\EmbeddableDocumentStore.cs:90
Solarity.DesignSearch.Website.Bootstrapper.BuildUnityContainer() in c:\a\src\Solarity.DesignSearch\Solarity.DesignSearch.Website\Bootstrapper.cs:35
Solarity.DesignSearch.Website.Bootstrapper.Initialise() in c:\a\src\Solarity.DesignSearch\Solarity.DesignSearch.Website\Bootstrapper.cs:20
Solarity.DesignSearch.Website.MvcApplication.Application_Start() in c:\a\src\Solarity.DesignSearch\Solarity.DesignSearch.Website\Global.asax.cs:23
[HttpException (0x80004005): Access is denied]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9859725
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Access is denied]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
I managed to get it to work, although it is not ideal. You may notice in my original post that I am setting the UseEmbeddedHttpServer = true. This is so that I can browse to http:[MyUrl]:8081 and get the RavendDB Management Studio so that I can browse my data. For some reason, RavenDB wants to do the same kind of port check when this property is set as it does when you set the Port setting to automatic (Port=*).
I believe that RavenDB may need a fix so that it honors the Port setting when UseEmbeddedHttpServer is True and also let you set the Configuration property of the EmbeddedDocumentStore upon creation.
But in the meantime, you can truly get your MVC4 site to work with an EmbeddedDocumentStore on Azure Websites simply by specifying a port. Also, you do indeed have to use the AppSettings configuration rather than setting the Configuration property of the EmbeddedDocumentStore upon creation (like I tried to do above). This post (stackoverflow.com/questions/11529159/) shows how to do it.
Unfortunately, I still haven't found a way to run the EmbeddedHttpServer so I can use the Raven Management Studio. If I figure out how, I will post a solution here.
Hi this was answered on RavenDb on Azure Websites - Access Denied
Basically you need to configure the port in Web.config