I'm trying to have the following urls
v1/$metadata
v1/se/companies
v1/se/addresses
v1/no/companies
v1/no/addresses
But if i use [ODataRoutePrefix("se/Companies")] i get the following error
System.InvalidOperationException: The path template 'se/Companies({companyNumber})' on the action 'Get' in controller 'SwedishCompany' is not a valid OData path template. Resource not found for the segment 'se'.
at Microsoft.AspNet.OData.Routing.Conventions.AttributeRoutingConvention.GetODataPathTemplate(String prefix, String pathTemplate, IServiceProvider requestContainer, String controllerName, String actionName)
at Microsoft.AspNet.OData.Routing.Conventions.AttributeRoutingConvention.<>c__DisplayClass11_0.<GetODataPathTemplates>b__1(ODataRouteAttribute route)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at Microsoft.AspNet.OData.Routing.Conventions.AttributeRoutingConvention.BuildAttributeMappings(IEnumerable`1 controllerActions)
at Microsoft.AspNet.OData.Routing.Conventions.AttributeRoutingConvention.get_AttributeMappings()
at Microsoft.AspNet.OData.Routing.Conventions.AttributeRoutingConvention.SelectAction(RouteContext routeContext)
at Microsoft.AspNet.OData.Routing.ODataActionSelector.SelectCandidates(RouteContext context)
at Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler.RouteAsync(RouteContext context)
at Microsoft.AspNetCore.Routing.Route.OnRouteMatched(RouteContext context)
at Microsoft.AspNetCore.Routing.RouteBase.RouteAsync(RouteContext context)
at Microsoft.AspNetCore.Routing.RouteCollection.RouteAsync(RouteContext context)
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
Is there some way to add a prefix with a /?
Related
We configured user flow with Google as identity provider. Followed the Azure-Sample repository on GitHub in building one ASP.NET Core webapp with .NET6.
appsettings.json:-
"AzureAdB2C": {
"Instance": "https://b2ctenant.b2clogin.com",
"ClientId": "3ae27e38-90a3-43c7-9bac-8d3bf33227f9",
"Domain": "b2ctenant.b2clogin.com",
"SignedOutCallbackPath": "/signout/B2C_1_susi",
"SignUpSignInPolicyId": "b2c_1_susi",
"ResetPasswordPolicyId": "b2c_1_reset",
"EditProfilePolicyId": "b2c_1_edit_profile" // Optional profile editing policy
//"CallbackPath": "/signin/B2C_1_sign_up_in" // defaults to /signin-oidc
https://localhost:44316
Getting exception when users select Sign Up/In option
IOException: IDX20807: Unable to retrieve document from: '[PII of type 'System.String' is hidden. For more details, see
https://aka.ms/IdentityModel/PII.]'. HttpResponseMessage: '[PII of
type 'System.Net.Http.HttpResponseMessage' is hidden. For more
details, see https://aka.ms/IdentityModel/PII.]',
HttpResponseMessage.Content: '[PII of type 'System.String' is hidden.
For more details, see https://aka.ms/IdentityModel/PII.]'.
Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string
address, CancellationToken cancel)
Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(string
address, IDocumentRetriever retriever, CancellationToken cancel)
Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken
cancel)
nvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII of type 'System.String' is hidden. For more
details, see https://aka.ms/IdentityModel/PII.]'.
Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken
cancel)
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleChallengeAsyncInternal(AuthenticationProperties
properties)
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleChallengeAsync(AuthenticationProperties
properties)
Microsoft.AspNetCore.Authentication.AuthenticationHandler.ChallengeAsync(AuthenticationProperties
properties)
Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext
context, string scheme, AuthenticationProperties properties)
Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync(ActionContext
context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0<TFilter,
TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next,
Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed
context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter,
TFilterAsync>(ref State next, ref Scope scope, ref object state, ref
bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|28_0(ResourceInvoker
invoker, Task lastTask, State next, Scope scope, object state, bool
isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker
invoker, Task lastTask, State next, Scope scope, object state, bool
isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed
context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State
next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker
invoker, Task lastTask, State next, Scope scope, object state, bool
isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker
invoker)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker
invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint
endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext
context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext
context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext
context)
I tried to reproduce the same in my environment and got below results:
I registered one application and granted API permissions like below:
I cloned the same GitHub sample and updated appsettings.json file same as you like below:
I ran the above sample and got below screen:
When I clicked on Sign Up/In button, I got same error as you like below:
Note that, you are giving wrong value to your Domain parameter in your appsettings.json file. You need to change value of Domain parameter that can be found here:
To resolve the error, I changed value of Domain parameter in my
appsettings.json file like below:
When I clicked on Sign Up/In button now by running the sample, I got the login screen with Google successfully like below:
Reference: Configure authentication using Azure Active Directory B2C | Microsoft
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)?.
I am getting following error:
Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(System.String, Int32)' on type 'AerospikeClient'.
Following is the stacktrace of autofac:
at Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate()
at
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext
context, IEnumerable1 parameters) at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action1 next) at
Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext
context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next) at
Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext
ctxt) at
Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext
context, Action1 next) --- End of inner exception stack trace --- at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) at
Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext
ctxt) at
Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext
ctxt) at
Autofac.Core.Resolving.Middleware.RegistrationPipelineInvokeMiddleware.Execute(ResolveRequestContext
context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next) at
Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext
ctxt) at
Autofac.Core.Resolving.Middleware.ScopeSelectionMiddleware.Execute(ResolveRequestContext
context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) at
Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.b__1(ResolveRequestContext
ctxt) at
Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext
ctxt) at
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope
currentOperationScope, ResolveRequest request) at
Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest
request) at
Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest
request) at
Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest
request) at
Autofac.ResolutionExtensions.TryResolveService(IComponentContext
context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable1 parameters) at
Autofac.ResolutionExtensions.ResolveOptional(IComponentContext
context, Type serviceType, IEnumerable`1 parameters) at
Autofac.ResolutionExtensions.ResolveOptional(IComponentContext
context, Type serviceType) at
Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetService(Type
serviceType) at
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider
sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
Following is my registration:
builder.RegisterType<AerospikeClient>().As<IAerospikeClient>()
.WithParameter("hostname", _configuration["AerospikeHostName"])
.WithParameter("port", int.Parse(_configuration["AerospikePort"]))
.SingleInstance();
_configuration is getting passed to my autofac module and it is of type IConfigurationRoot. I am doing this so that I can pass values from outside.
If I change the above registration to:
builder.RegisterType<AerospikeClient>().As<IAerospikeClient>()
.WithParameter("hostname", "172.27.159.44")
.WithParameter("port", 3000)
.SingleInstance();
then it starts working. However I don't want to hardcode my values like that. Then I lose my chance of overriding them based on different environments.
What am I doing wrong here?
Check the actual type returned from _configuration["AerospikeHostName"]. Is it actually string, or is it something that happens to be assignable to string?
Equally, check the actual value used is valid, because Autofac should be fine expecting that string value.
Also, in future, consider using the built-in diagnostics to get a clearer picture of what exceptions are being thrown during resolve operations.
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.
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