How to run an aspnet core website built in Release locally with https - c#

I am developing an asp net core website and using app.UseHttpsRedirection();
When I start the website in debug from VS, I can browse it fine in https from https://localhost:5001/.
However, if I build it in Release and then run the executable, when I try to browse the website from https://localhost:5001/ I am getting this, certainly related to a certificate problem:
System.Security.Cryptography.CryptographicException: The payload was invalid.
at Microsoft.AspNetCore.DataProtection.Cng.CbcAuthenticatedEncryptor.DecryptImpl(Byte* pbCiphertext, UInt32 cbCiphertext, Byte* pbAdditionalAuthenticatedData, UInt32 cbAdditionalAuthenticatedData)
at Microsoft.AspNetCore.DataProtection.Cng.Internal.CngAuthenticatedEncryptorBase.Decrypt(ArraySegment`1 ciphertext, ArraySegment`1 additionalAuthenticatedData)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
at Microsoft.AspNetCore.Session.CookieProtection.Unprotect(IDataProtector protector, String protectedText, ILogger logger)
10:40:47||0HM8IV1M7U2V2:00000005|Microsoft.AspNetCore.Session.SessionMiddleware|WRN|Error unprotecting the session cookie.
What do I have to do to be able to browse my website locally while running the executable compiled in Release?

Related

Issue accessing GCP secrets manager using dotnet 5

I am using Google.Cloud.SecretManager.V1 in my .NET 5 aspnet core application. I am containerizing application to run as linux container on GCP Cloud run. I get following exception while creating SecretManagerServiceClient
//call SDK
SecretManagerServiceClient client = SecretManagerServiceClient.Create();
System.DllNotFoundException: Unable to load shared library 'libdl.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl.so: cannot open shared object file: No such file or directory
at Grpc.Core.Internal.UnmanagedLibrary.Linux.dlopen(String filename, Int32 flags)
at Grpc.Core.Internal.UnmanagedLibrary.LoadLibraryPosix(Func`3 dlopenFunc, Func`1 dlerrorFunc, String libraryPath, String& errorMsg)
at Grpc.Core.Internal.UnmanagedLibrary.PlatformSpecificLoadLibrary(String libraryPath, String& errorMsg)
at Grpc.Core.Internal.UnmanagedLibrary..ctor(String[] libraryPathAlternatives)
at Grpc.Core.Internal.NativeExtension.LoadUnmanagedLibrary()
at Grpc.Core.Internal.NativeExtension.LoadNativeMethods()
at Grpc.Core.Internal.NativeExtension..ctor()
at Grpc.Core.Internal.NativeExtension.Get()
at Grpc.Core.Internal.NativeMethods.Get()
at Grpc.Core.GrpcEnvironment.GrpcNativeInit()
at Grpc.Core.GrpcEnvironment..ctor()
at Grpc.Core.GrpcEnvironment.AddRef()
at Grpc.Core.Channel..ctor(String target, ChannelCredentials credentials, IEnumerable`1 options)
at Google.Api.Gax.Grpc.GrpcCore.GrpcCoreAdapter.CreateChannelImpl(String endpoint, ChannelCredentials credentials, GrpcChannelOptions options)
at Google.Api.Gax.Grpc.GrpcAdapter.CreateChannel(String endpoint, ChannelCredentials credentials, GrpcChannelOptions options)
at Google.Api.Gax.Grpc.ChannelPool.GetChannel(GrpcAdapter grpcAdapter, String endpoint, GrpcChannelOptions channelOptions, ChannelCredentials credentials)
at Google.Api.Gax.Grpc.ChannelPool.GetChannel(GrpcAdapter grpcAdapter, String endpoint, GrpcChannelOptions channelOptions)
at Google.Api.Gax.Grpc.ClientBuilderBase`1.CreateCallInvoker()
at Google.Cloud.SecretManager.V1.SecretManagerServiceClientBuilder.BuildImpl()
at Google.Cloud.SecretManager.V1.SecretManagerServiceClientBuilder.Build()
at Google.Cloud.SecretManager.V1.SecretManagerServiceClient.Create()
Same code works fine if I use aspnetcore 3.1 image. NET 5 is supposed to be upgrade of .NET core 3.1 and backward compatible. So, I am curious and what could be done to make this code work on .NET 5
I posted this answer to make a solution from the comment section more visible.
As it was suggested by #John Hanley and confirmed by #SmartCoder this issue was solved by adding to the Docker file lines below:
RUN apt-get update -y
RUN apt-get install -y libc6-dev

.exe file not recognized after resigning the manifest on ClickOnce Publish

I am using MVS 2015 with .Net Framework 4.5.
I publish my C# WF Application, everything is fine, but I have to obfuscate the .exe from Application Files.
After I do it, obviously, the setup does not recognize anymore the .exe, the hashes are different and so on.
I resign the new .exe added file with Signtool providing the necessary .pfx and password, then I use Mage to update the .manifest and the .application according to the second part of this MSDN documentation.
Everything is successful, but when I run the setup and I hit install, after a while (around 80% of the installation progress) I receive an error that says that there is something wrong with the new .exe file:
PLATFORM VERSION INFO
Windows : 10.0.16299.0 (Win32NT)
Common Language Runtime : 4.0.30319.42000
System.Deployment.dll : 4.7.2556.0 built by: NET471REL1
clr.dll : 4.7.2633.0 built by: NET471REL1LAST_C
dfdll.dll : 4.7.2556.0 built by: NET471REL1
dfshim.dll : 10.0.16299.15 (WinBuild.160101.0800)
SOURCES
Deployment url : file:///E:/share/myApp.application
Application url : file:///E:/share/myApp.exe.manifest
IDENTITIES
Deployment Identity : myApp.exe.application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6500754c4a44ec95, processorArchitecture=msil
Application Identity : myApp.exe, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6500754c4a44ec95, processorArchitecture=msil, type=win32
APPLICATION SUMMARY
* Installable application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of E:\share\myApp.application resulted in exception. Following failure messages were detected:
+ Exception occurred loading manifest from file myApp.exe: the manifest may not be valid or the file could not be opened.
+ Cannot load internal manifest from component file.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [24.03.2018 11:03:32] : Activation of E:\share\myApp.application has started.
* [24.03.2018 11:03:32] : Processing of deployment manifest has successfully completed.
* [24.03.2018 11:03:32] : Installation of the application has started.
* [24.03.2018 11:03:33] : Processing of application manifest has successfully completed.
* [24.03.2018 11:03:35] : Found compatible runtime version 4.0.30319.
* [24.03.2018 11:03:35] : Request of trust and detection of platform is complete.
ERROR DETAILS
Following errors were detected during this operation.
* [24.03.2018 11:03:43] System.Deployment.Application.InvalidDeploymentException (ManifestLoad)
- Exception occurred loading manifest from file myApp.exe: the manifest may not be valid or the file could not be opened.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.Manifest.AssemblyManifest.ManifestLoadExceptionHelper(Exception exception, String filePath)
at System.Deployment.Application.Manifest.AssemblyManifest.LoadFromInternalManifestFile(String filePath)
at System.Deployment.Application.DownloadManager.ProcessDownloadedFile(Object sender, DownloadEventArgs e)
at System.Deployment.Application.FileDownloader.DownloadModifiedEventHandler.Invoke(Object sender, DownloadEventArgs e)
at System.Deployment.Application.FileDownloader.OnModified()
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState, X509Certificate2 clientCertificate)
at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification notification, DownloadOptions options)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl, Uri& deploymentUri)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivationWithRetry(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
What am I doing wrong? What am I missing? :(
I have investigated Marko application, and if you have in use .NET Refactor and have a problem from above here is workaround for get it working:
.Net Reactor has a Visual Studio Add-In that needs installed and configured in the project
Anti ILDASM from .Net Reactor (option that's enabled by default) has to be disabled when obfuscating so that MVS could do the proper packing process
Anyway, if you gonna modify your assemblies after publish you need to recompute hash anyway. How it's possible:
Don't use a Visual Studio publish engine and generate you
application by "mage.exe". It's let to you prepare you source
application first and create ClickOnce application after.
Download utility from second download link [here]. Execute and [Choose] your folder > Change action to [Update] > and [Build]. No more actions required. Update operation will recompute hashs.
If your obfuscator software supports command line parameters then you can add "Post-build event" script in your .exe VS project properties and it will be executed before clickonce build.
"Deploying Obfuscated Assemblies" article you can found here: Securing ClickOnce Applications

Client Version Error after installing Azure 1.8

I recently installed the Azure SDK 1.8 on my machine but am still using a project that is running version 1.7.1 (June 2012 SP1 for VS2012). Since I did this, every time I try to run my project I get the following error:
ErrorCode<ERRCA0019>:SubStatus<ES0001>:Check the client version. It should be within the allowed version range on the server. If necessary, upgrade the client to the allowed version.
[DataCacheException: ErrorCode<ERRCA0019>:SubStatus<ES0001>:Check the client version. It should be within the allowed version range on the server. If necessary, upgrade the client to the allowed version.]
Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ErrStatus errStatus, Guid trackingId, Exception responseException, Byte[][] payload, EndpointID destination) +767
Microsoft.ApplicationServer.Caching.DataCache.ThrowException(ResponseBody respBody, EndpointID destination) +149
Microsoft.ApplicationServer.Caching.DataCacheFactory.EstablishConnection(IEnumerable`1 servers, RequestBody request, Func`3 sendMessageDelegate, DataCacheReadyRetryPolicy retryPolicy) +967
Microsoft.ApplicationServer.Caching.WcfClientProtocol.Initialize(IEnumerable`1 servers) +606
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName, CreateNewCacheDelegate cacheCreationDelegate, DataCacheInitializationViaCopyDelegate initializeDelegate) +1103
Microsoft.ApplicationServer.Caching.DataCacheFactory.GetCache(String cacheName) +131
Microsoft.Web.DistributedCache.DataCacheFactoryWrapper.CreateDataCacheFromFactory(DataCacheFactory factory, String cacheName) +63
Microsoft.Web.DistributedCache.CacheHelpers.RunCacheCreationHooks(CacheConnectingEventArgs fetchingEventArgs, IDataCacheFactory dataCacheFactory, Object sender, EventHandler`1 fetchingHandler, EventHandler`1 fetchedHandler) +356
Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider.CreateInternalProvider(IHttpRuntime httpRuntime, SessionInitializationData initData, IDataCacheFactory dataCacheFactory, EventHandler`1 cacheFetching, EventHandler`1 cacheFetched) +447
Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider.GetInternalProvider() +315
Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider.ResetItemTimeout(HttpContext context, String id) +59
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +707
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12600474
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
I have not had much luck finding a solution. Some forums have mentioned using a different AppFabric version, but they all seem to be referring to running it in the actual Azure cloud service and I can't even get it to run on my local machine.
Any thoughts?
I ran into a similar problem while upgrading to the October 2012 release. I resolved it by removing all the caching references in my project, and then installing the Windows Azure Shared Caching package from NuGet.
I'm not sure if the resulting project will still run with the June 2012 SDK. But it's worth a try.

Application cannot be started error in ClickOnce deployment

I have an application created in Visual C# using ClickOnce.
I send this application to users via a zipped ClickOnce publish folder, however I (the developer) cannot install it, while others have no problems.
I do the following steps:
- In VS 2010, Project settings, Publish tab, click button 'Publish Now'
- In the created directory I run setup (this is the created ClickOnce Setup file)
- I get the error dialog: Application cannot be started. Contact the application vendor.
Btw, I have not signed my application and assigned the application as a Full Trust application.
What I already tried (also according comments):
- When run as administrator (RMB on setup in clickonce in local folder), I get the same error.
- When running it directly from the bin directory, it works ok.
- When adding a sleep for attaching a debugger, it immediately gives the same error.
- I cleared the cache but it does not help.
And below are the complete details:
PLATFORM VERSION INFO
Windows : 6.1.7601.65536 (Win32NT)
Common Language Runtime : 4.0.30319.261
System.Deployment.dll : 4.0.30319.245 (RTMGDR.030319-2400)
clr.dll : 4.0.30319.261 (RTMGDR.030319-2600)
dfdll.dll : 4.0.30319.1 (RTMRel.030319-0100)
dfshim.dll : 4.0.31106.0 (Main.031106-0000)
SOURCES
Deployment url : file:///D:/PcgTools%20Publish2/PcgTools.application
Application url : file:///D:/PcgTools%20Publish2/Application%20Files/PcgTools_0_5_0_149/PcgTools.exe.manifest
IDENTITIES
Deployment Identity : PcgTools.application, Version=0.5.0.149, Culture=neutral, PublicKeyToken=0000000000000000, processorArchitecture=msil
APPLICATION SUMMARY
* Installable application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of D:\PcgTools Publish2\PcgTools.application resulted in exception. Following failure messages were detected:
+ Specified cast is not valid.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
* The manifest for this application does not have a signature. Signature validation will be ignored.
* The manifest for this application does not have a signature. Signature validation will be ignored.
OPERATION PROGRESS STATUS
* [12-3-2012 2:18:04] : Activation of D:\PcgTools Publish2\PcgTools.application has started.
* [12-3-2012 2:18:04] : Processing of deployment manifest has successfully completed.
* [12-3-2012 2:18:04] : Installation of the application has started.
ERROR DETAILS
Following errors were detected during this operation.
* [12-3-2012 2:18:04] System.InvalidCastException
- Specified cast is not valid.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.DownloadManager.VerifyRequestedPrivilegesSupport(String requestedExecutionLevel)
at System.Deployment.Application.DownloadManager.DownloadApplicationManifest(AssemblyManifest deploymentManifest, String targetDir, Uri deploymentUri, IDownloadNotification notification, DownloadOptions options, Uri& appSourceUri, String& appManifestPath)
at System.Deployment.Application.DownloadManager.DownloadApplicationManifest(AssemblyManifest deploymentManifest, String targetDir, Uri deploymentUri, Uri& appSourceUri, String& appManifestPath)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.

Failed to map the path '/'. .net 4.0

I have a .net app that I just opened on in visual studio 2010 and converted to 4.0 when it asked me on start-up. I go to try to build the site, and I get this error:
Failed to map the path '/'.
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.
[InvalidOperationException: Failed to map the path '/'.]
System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +8804446
System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath) +42
System.Web.VirtualPath.MapPathInternal() +4
System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) +107
System.Web.HttpRequest.MapPath(VirtualPath virtualPath) +37
System.Web.HttpServerUtility.MapPath(String path) +99
NU.WorkManagement.Lookup.Lookups..ctor() +82
NU.WorkManagement.Engine.GlobalModule.Init(HttpApplication application) +624
System.Web.HttpApplication.InitModulesCommon() +80
System.Web.HttpApplication.InitModules() +43
System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +828
System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +304
System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +327
I tried the most popular solution I found vis google (replace and ../ with ~/ but there wern't any...)
Update:
Lookups constructor:
public Lookups()
{
_dirPath = System.Web.HttpContext.Current.Server.MapPath("/") + _xmlPath;
}
I know it's and old question, but for the record if you are running against IIS then
'iisreset' in the console may help resolving "Failed to map the path '/'." issue. I had this problem after renaming the sites in IIS.
I was just trying to go through an exercise in a Microsoft Step By Step book and I hit this problem when trying to precompile an ASP.NET appliction.
Here's how I got past this - and it took me a day to figure out!
When you open the Visual Studio Command Prompt to do your build/precompile, you must right-click and choose "Run As Administrator".
That's all it took for me when trying to run this aspnet_compiler -v DeployThis C:\DeployThis -f -u
Try System.Web.HttpContext.Current.Server.MapPath("~/"). Notice the ~.
We had the same problem, IISRESET didn't do it.
It turned out that the Virtual Directory we trying to map has a double backslash (d:\folder\\subfolder\) in the naming (IIS virtual directory was created with powershell script). Removing the extra backslash made HostingEnvironment.MapPath stop throwing exceptions.
Just in the case this could help somebody :-)

Categories