Example of a .Net6 Blazor WebAssembly application with authentication using local Sql Db? - asp.net-core

I'm trying to add authentication (with registration, password reset etc) to a .Net6 Blazor WebAssembly project. When creating the project include authentication for individual accounts (to local sql db), configure for HTTPS, Asp.Net Core hosted and Progressive Web Application. This is done in VS 2022.
The problem I'm facing is that each project I've created so far continues to crash as soon as I try to register or login.
similar to this thread: Blazor WebAssembly Hosted Proxy crash on successful authentication
I also looked at the link to https://github.com/dotnet/aspnetcore/issues/26635 but the issue was resolved. I'm currently running Chrome Version 99.0.4844.82 (Official Build) (64-bit).
I tried removing the autocomplete attribute on the server side cshtml pages but the project still random crashes.
Has anyone successfully implemented authentication (using local Sql) in a webAssebly project with .Net6?
I also tried to run the samples from the .NetCore git repo and the apps continue to crash.
This is the server console output:
fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0] DevToolsProxy::Run: Exception System.AggregateException: One or more errors occurred. (The remote party closed the WebSocket connection without completing the close handshake.) ---> System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake. ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request. at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.g__ThrowSocketException|5_0(SocketError e) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.GetResult(Int16 token) at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive() at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result) at System.IO.Pipelines.Pipe.GetReadAsyncResult() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1UpgradeMessageBody.ReadAsyncInternalAwaited(ValueTask1 readTask, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory1 destination, CancellationToken cancellationToken) at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken, Boolean throwOnPrematureClosure) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory1 payloadBuffer, CancellationToken cancellationToken) at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory1 payloadBuffer, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state) --- End of stack trace from previous location --- at Microsoft.WebAssembly.Diagnostics.DevToolsProxy.ReadOne(WebSocket socket, CancellationToken token) --- End of inner exception stack trace --- at Microsoft.WebAssembly.Diagnostics.DevToolsProxy.Run(Uri browserUri, WebSocket ideSocket)
This is the VS output screen details:
Exception thrown: 'System.Net.Sockets.SocketException' in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll
Exception thrown: 'System.Net.Sockets.SocketException' in Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.dll
The program '' has exited with code 4294967295 (0xffffffff).
Exception thrown: 'Microsoft.AspNetCore.Connections.ConnectionResetException' in System.Private.CoreLib.dll
Exception thrown: '' in Unknown Module.
The thread 0x1 has exited with code 0 (0x0).
The program 'service-worker.js' has exited with code 4294967295 (0xffffffff).
The program '[25288] Chatter.Server.exe' has exited with code 4294967295 (0xffffffff).
The thread 0x0 has exited with code 0 (0x0).
The program 'localhost:7151' has exited with code 4294967295 (0xffffffff).
Any advise will be greatly appreciated.
Thanx
Riaan

fail: Microsoft.WebAssembly.Diagnostics.DevToolsProxy[0]
DevToolsProxy::Run: Exception System.AggregateException: One or more
errors occurred. (The remote party closed the WebSocket connection
without completing the close handshake.)
To the above error, as far as I know, after update to VS 2022 17.1, it will show the websocket error. And, if check the console output, you will find the above error.
To solve the above error, you can try to use the VS 2022 17.2.0 Preview 2.0 version, this issue has been fixed in this version. Or you can try to install the earlier VS 2022 version, refer this link. I also check it using VS 2022 17.0.4 version, it doesn't have this error, you can try to use this version.
To the Local SQL Server error, I guess you are meeting the following error, right?
To solve the above error, you can use the following migration commands to generate the DataBase first (Or you can use the existing database), then the above error will disappear when you run the application.
add-migration generateDatabase
Update-Database
More detail information about migration, see Migrations Overview.

Related

[WebException: The request failed with HTTP status 404: Not Found.]

I am working in two environments, staging and production. In stage, my site pulls up correctly, however, when I publish to production, I receive the following error:
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.WebException: The request failed with HTTP status 404: Not Found.
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.
The back end is Visual Basic.
[NullReferenceException: Object reference not set to an instance of an object.]
Navigation.EstablishContext(HttpRequest Request) +492
Navigation..ctor() +79
[Exception: Error creating Navigation object]
Navigation..ctor() +269
UrlRewriteModule.Application_BeginRequest(Object source, EventArgs e) +262
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +1513
Please add your code for a better answer.
You are attempting to access a resource that is not specified in your path, you want to:
check your url,and identify what is not properly formatted,
verify your web.config
verify the permission on the file you are trying to access on production environment.
99% sure, 404 Not Found = resource not properly accessed.

Web Deploy - DACPAC / XML Output

I'm trying to deploy a web application. I can deploy the website portion just fine, however the SQL database won't deploy. The error I receive in VS2012 on my development machine is:
Error 24 Web deployment task failed. ((5/6/2014 1:36:23 PM) An error occurred when the request was processed on the remote computer.)
(5/6/2014 1:36:23 PM) An error occurred when the request was processed on the remote computer.
The server experienced an issue processing the request. Contact the server administrator for more information.
On the web/sql server, the event logs give this:
*User:
Client IP: 192.168.254.122
Content-Type: application/msdeploy
Version: 9.0.0.0
MSDeploy.VersionMin: 7.1.600.0
MSDeploy.VersionMax: 9.0.1762.0
MSDeploy.Method: Sync
MSDeploy.RequestId: ea61751c-29cf-4764-8ad3-210cedc8fa53
MSDeploy.RequestCulture: en-US
MSDeploy.RequestUICulture: en-US
ServerVersion: 9.0.1762.0
Skip: objectName="^configProtectedData$"
Provider: auto, Path:
A tracing deployment agent exception occurred that was propagated to the client. Request ID 'ea61751c-29cf-4764-8ad3-210cedc8fa53'. Request Timestamp: '5/6/2014 1:36:13 PM'. Error Details:
ERROR_CANNOT_PROCESS_DACPAC_OUTPUT Microsoft.Web.Deployment.DeploymentDetailedException: The output received from executing dacpac in a seperate process was not valid xml. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_CANNOT_PROCESS_DACPAC_OUTPUT. --->
System.Xml.XmlException: Data at the root level is invalid. Line 19, position 10.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
at Microsoft.Web.Deployment.SqlDacPacProvider.ProcessExeOutput()
--- End of inner exception stack trace ---
at Microsoft.Web.Deployment.SqlDacPacProvider.ProcessExeOutput()
at Microsoft.Web.Deployment.SqlDacPacProvider.RunExecutableAsync(String exeName, String arguments, Int32 waitInterval, Int32 retryAttempts)
at Microsoft.Web.Deployment.SqlDacPacProvider.Add(DeploymentObject source, Boolean whatIf)
at Microsoft.Web.Deployment.DeploymentObject.Add(DeploymentObject source, DeploymentSyncContext syncContext)
at Microsoft.Web.Deployment.DeploymentSyncContext.HandleAdd(DeploymentObject destObject, DeploymentObject sourceObject)
at Microsoft.Web.Deployment.DeploymentSyncContext.SyncChildren(DeploymentObject dest, DeploymentObject source)
at Microsoft.Web.Deployment.DeploymentSyncContext.SyncChildrenOrder(DeploymentObject dest, DeploymentObject source)
at Microsoft.Web.Deployment.DeploymentSyncContext.ProcessSync(DeploymentObject destinationObject, DeploymentObject sourceObject)
at Microsoft.Web.Deployment.DeploymentObject.SyncToInternal(DeploymentObject destObject, DeploymentSyncOptions syncOptions, PayloadTable payloadTable, ContentRootTable contentRootTable, Nullable`1 syncPassId, String syncSessionId)
at Microsoft.Web.Deployment.DeploymentAgent.HandleSync(DeploymentAgentAsyncData asyncData, Nullable`1 passId)
at Microsoft.Web.Deployment.DeploymentAgent.HandleRequestWorker(DeploymentAgentAsyncData asyncData)
at Microsoft.Web.Deployment.DeploymentAgent.HandleRequest(DeploymentAgentAsyncData asyncData)*
When I "test connection" for the SQL Database from VS2012 it works just fine, so I know it's not a connection/authentication issue. It looks like the dacpac file is using the wrong version of XML maybe? If nobody has a way to fix the error given, is there a way for me to manually deploy the database?
I had this problem, and it ended up being a permissions issue.
The user only had db_datareader, db_datawriter, and execute.
I needed to give the SSDT user db_owner, then I was able to get past this error.

Exposing wcf service in BizTalk 2010

I have ran into this issue the past few weeks ago and I still can not figure out why.
I have a BizTalk orchestration that receives a BizTalk message, processes it and eventually writes it to a file. For simplicity sake, let say, our goal is to take the message (which is actually a survey) and save it to a folder as is. I have created a public receive port to catch the msg and a send port to write the result out to disk.
I have successfully deployed the project and have successfully published it to IIS. I was able to see the WCF service in IIS and have set it to use Framework 4.0. I have set up all the relevant receive and send ports and have started the application successfully from BizTalk management console. (The receive location was automatically created when I published the wcf service, the send location is a type FILE located in a folder in the computer)
From DefaultSite in IIS, I could see my WCF. However, when I tried http://localhost/TestSurvey/TestSurvey_Orchestration_1_getSurveyPort.svc,
I got the following error:
Server Error in '/TestSurvey' Application.
--------------------------------------------------------------------------------
Login failed for user 'Domain\ComputerName$'.
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.Data.SqlClient.SqlException: Login failed for user 'ACAD1\DENBIZDEV$'.
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:
[SqlException (0x80131904): Login failed for user 'Domain\ComputeName$'.]
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
Microsoft.BizTalk.TransportProxy.Interop.IBTTransportProxy.RegisterIsolatedReceiver(String url, IBTTransportConfig callback) +0
Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfIsolatedReceiver`2.RegisterIsolatedReceiver(Uri uri) +1028
Microsoft.BizTalk.Adapter.Wcf.Runtime.WebServiceHostFactory`3.CreateServiceHost(String constructorString, Uri[] baseAddresses) +363
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1413
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +50
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1172
[ServiceActivationException: The service '/TestSurvey/TestSurvey_Orchestration_1_getSurveyPort.svc' cannot be activated due to an exception during compilation. The exception message is: Exception has been thrown by the target of an invocation..]
System.Runtime.AsyncResult.End(IAsyncResult result) +901424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178638
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +107
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
My question is: what is it that BizTalk was trying to login? Domain\ComputerName$ is definitely not a user. I have not tried to access any database from the orchestration. I believe my IIS was set up correctly as I have created a quick and dirty wcf service test from VS2010 and published it to my IIS, then have successfully created a simple client to consume the wcf service test. I did not encounter the same issue when I created the wcf service test directly.
Any help or hint is highly appreciated!
EDIT
I managed to fix this: it was not the web config as it was created by BizTalk. I had to create a special app pool and tied my application to using it. In the app pool I have to use the custom credential that BizTalk is using. Using the built in credentials caused the issue I experienced. My rookie error! Once BizTalk login credential was used, everything went smoothly.
The database which is throwing the SQL exception is one of the BizTalk databases, probably the management or SSO DB.
The error is almost certainly being caused by the setup of IIS, whether the app pool identity or the web site security settings.
What is hapenning is that when you call the service for the first time IIS is compiling your service, and to do this it obviously needs access to one of the BizTalk databases, but this call is not authenticated for some reason.
This could be because the app pool user must be a member of the BizTalk Isolated Host Users group (which may be called something different depending on how BizTalk was set up.

Cassia Library giving exception when calling any methods

I am trying to run the Cassia library on a remote Windows Server 2008 Terminal Server. Any methods I call I get the response below.
No more data is available
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.ComponentModel.Win32Exception: No more data is available
Stack Trace:
[Win32Exception (0x80004005): No more data is available]
Cassia.Impl.NativeMethodsHelper.GetSessionInfos(ITerminalServerHandle server) +159
Cassia.Impl.TerminalServer.GetSessions() +103
I was getting this error as well. Turns out that if there are no sessions for the given server it throws this exception.
Try running qwinsta /server <servername> in a WCP shell. It should return "No session exists for *".
I worked around this by checking exception message for "no more data" and don't throw it if so. It's gross but it's an open source dll.

WCF service hosted in IIS throws 'Failed to access IIS metabase' error

Deployed a WCF service in IIS 6.0 gave NETWORK_sERVICE user read/write privileges.
When tries to brows to .SVC file i get below error
Failed to access IIS metabase.
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.Web.Hosting.HostingEnvironmentException: Failed to access IIS metabase.
The process account used to run ASP.NET must have read access to the IIS metabase (e.g. IIS://servername/W3SVC). For information on modifying metabase permissions, please see http://support.microsoft.com/?kbid=267904.
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:
[HostingEnvironmentException: Failed to access IIS metabase.]
System.Web.Configuration.MetabaseServerConfig.MapPathCaching(String siteID, VirtualPath path) +637
System.Web.Configuration.MetabaseServerConfig.System.Web.Configuration.IConfigMapPath2.MapPath(String siteID, VirtualPath vpath) +9
System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath virtualPath, Boolean permitNull) +174
System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath, Boolean permitNull) +51
System.Web.CachedPathData.GetConfigPathData(String configPath) +341
System.Web.CachedPathData.GetConfigPathData(String configPath) +234
System.Web.CachedPathData.GetApplicationPathData() +38
System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp) +8806383
System.Web.Configuration.RuntimeConfig.GetLKGRuntimeConfig(VirtualPath path) +117
Any thoughts?
Was told that we get 'Failed to access IIS metabase' error if we install IIS after intalling .NET Framework, and remedy is to re-install ASP.NET.
To resolve this error I have followed below steps
1. Stopped IIS
2. Ran below command in command prompt to re-install aspnet.
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i
Result:
Start installing ASP.NET (2.0.50727).
..................................................................
Finished installing ASP.NET (2.0.50727).
3. Re-started IIS and WCF service is responding without any issues.