Ubuntu上的Asp Net Core - 访问被拒绝

时间:2016-10-30 22:48:05

标签: asp.net asp.net-core ubuntu-14.04 hosting

安装库 MailKit 并调用new SmtpClient().ConnectAsync(_settings.Server, _settings.Port, _settings.SSL);后,我收到此错误:

  

访问路径' /var/www/.dotnet/corefx/cryptography/crls'被拒绝。

顺便说一句,我的项目位于 / media / ProjectName 。 我尝试执行此操作:sudo chmod -R 755 /var但我得到了权限错误。

这里是stacktrace:

  

at System.IO.UnixFileSystem.CreateDirectory(String fullPath)↵at System.IO.Directory.CreateDirectory(String path)↵在Internal.Cryptography.Pal.CrlCache.GetCachedCrlPath(X509Certificate2 cert,Boolean mkDir)↵at Internal。 Cryptography.Pal.CrlCache.DownloadAndAddCrl(X509Certificate2 cert,SafeX509StoreHandle store,TimeSpan& remainingDownloadTime)↵在Internal.Cryptography.Pal.CrlCache.AddCrlForCertificate(X509Certificate2 cert,SafeX509StoreHandle store,X509RevocationMode revocationMode,DateTime verificationTime,TimeSpan& remainingDownloadTime)↵在Internal。 Cryptography.Pal.OpenSslX509ChainProcessor.BuildChain(X509Certificate2 leaf,HashSet 1 candidates, HashSet 1已下载,HashSet 1 systemTrusted, OidCollection applicationPolicy, OidCollection certificatePolicy, X509RevocationMode revocationMode, X509RevocationFlag revocationFlag, DateTime verificationTime, TimeSpan& remainingDownloadTime)↵ at Internal.Cryptography.Pal.ChainPal.BuildChain(Boolean useMachineContext, ICertificatePal cert, X509Certificate2Collection extraStore, OidCollection applicationPolicy, OidCollection certificatePolicy, X509RevocationMode revocationMode, X509RevocationFlag revocationFlag, DateTime verificationTime, TimeSpan timeout)↵ at System.Security.Cryptography.X509Certificates.X509Chain.Build(X509Certificate2 certificate)↵ at System.Net.Security.CertificateValidation.BuildChainAndVerifyProperties(X509Chain chain, X509Certificate2 remoteCertificate, Boolean checkCertName, String hostName)↵ at System.Net.Security.SecureChannel.VerifyRemoteCertificate(RemoteCertValidationCallback remoteCertValidationCallback)↵ at System.Net.Security.SslState.CompleteHandshake()↵ at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)↵ at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)↵ at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)↵ at System.Net.Security.SslState.ReadFrameCallback(AsyncProtocolRequest asyncRequest)↵--- End of stack trace from previous location where exception was thrown ---↵ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()↵ at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)↵ at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)↵ at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)↵ at System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic(IAsyncResult iar,Func 2 endFunction, Action 1 endAction,Task`1 promise,Boolean requiresSynchronization) ↵---从抛出异常的先前位置开始的堆栈跟踪结束---↵在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)↵在System.Ru在MailKit.MailService的MailKit.Net.Smtp.SmtpClient.Connect(字符串主机,Int32端口,SecureSocketOptions选项,CancellationToken cancellationToken)上的ntime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)&<> c__DisplayClass41_0.b__0() ↵在System.Threading.Tasks.Task.Execute()↵---从抛出异常的先前位置开始的堆栈跟踪结束---↵在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)↵在System。 MyProject.Services.MessageService.d__4.MoveNext()中的Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)↵---从抛出异常的上一个位置的堆栈跟踪结束--- System在System.Runtime.CompilerServices。 TaskAwaiter.ThrowForNonSuccess(任务任务)↵在MyProject.Services.MessageService.d__5.MoveNext()

的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)↵

2 个答案:

答案 0 :(得分:4)

Lex Li发布创建目录/var/www/.dotnet/corefx/cryptography/crls并授予www-data组权限(如果这是运行您服务的组)

sudo chgrp www-data /var/www/.dotnet/corefx/cryptography/crls

答案 1 :(得分:0)

我指的是guide。在kestrel-hellomvc.service文件中,用User = my-root-username替换了User = www-data,它工作正常。 希望它可以帮助某人。