ServiceStack'访问权限再次被拒绝,以及其他问题(ServiceStack 'Access is denied' again, and other issues

编程入门 行业动态 更新时间:2024-10-27 07:31:03
ServiceStack'访问权限再次被拒绝,以及其他问题(ServiceStack 'Access is denied' again, and other issues)

我想我已经在这个问题中解决了我的ServiceStack Web服务的访问问题,但是我现在得到了相同的“访问被拒绝”错误,即使在该解决方案中找到了修复程序并且无法在我的解决方案中解决它们拥有。

这就是我所处的位置:我有一个Web服务,我使用POST方法发送数据。 我也有一个GET方法返回与POST相同的响应类型,并且工作正常。 据我所知,该请求在失败之前甚至没有到达ServiceStack。 即使我在响应标头中使用CorsFeature插件,响应中也没有Access-Control标头。 我无法弄清楚为什么它没有得到任何ServiceStack代码虽然......一切似乎都设置正确。 顺便说一句,当我尝试DELETE操作时,我从服务器获得“403 Forbidden,Write access is denied”错误,如果这有用的话?

这是我的Global.asax(相关部分):

public class AppHost : AppHostBase { public AppHost() : base("RMS Citations Web Service", typeof(CitationService).Assembly) { } public override void Configure(Container container) { SetConfig(new EndpointHostConfig { DefaultContentType = ContentType.Json, ReturnsInnerException = true, WsdlServiceNamespace = "http://www.servicestack.net/types" }); Plugins.Add(new CorsFeature()); RequestFilters.Add((httpReq, httpRes, requestDto) => { if (httpReq.HttpMethod == "OPTIONS") httpRes.EndRequestWithNoContent(); // extension method }); container.RegisterAutoWired<CitationRequest>(); // Not sure I need this - is it necessary for the Funq container? using (var addCitation = container.Resolve<CitationService>()) { addCitation.Post(container.Resolve<CitationRequest>()); addCitation.Get(container.Resolve<CitationRequest>()); addCitation.Delete(container.Resolve<CitationRequest>()); } } } protected void Application_Start(object sender, EventArgs e) { new AppHost().Init(); }

这是我的请求和响应类:

[Route("/citations", "POST, OPTIONS")] [Route("/citations/{ReportNumber_Prefix}/{ReportNumber}/{AgencyId}", "GET, DELETE, OPTIONS")] public class CitationRequest : RmsData.Citation, IReturn<CitationResponse> { public CitationStatus Status { get; set; } } public enum CitationStatus { COMP, HOLD } public class CitationResponse { public bool Accepted { get; set; } public string ActivityId { get; set; } public int ParticipantId { get; set; } public string Message { get; set; } public Exception RmsException { get; set; } }

这是我的服务类:

public class CitationService : Service { public Repository Repository { get { return new Repository(); } } public CitationResponse Post(CitationRequest citation) { var response = new CitationResponse { Accepted = false }; if (string.IsNullOrEmpty(citation.ReportNumber)) { response.Accepted = false; response.Message = "Report number was empty, so no data was sent to the web service."; return response; } try { response.ActivityId = Repository.CreateCitation(citation.ReportNumber, citation.ReportNumber_Prefix, citation.ViolationDateTime, citation.AgencyId, citation.Status); response.Accepted = true; } catch (Exception ex) { response.Accepted = false; response.Message = ex.Message; response.RmsException = ex; } return response; } public CitationResponse Get(CitationRequest citation) { var citationResponse = new CitationResponse(); if (string.IsNullOrEmpty(citation.ReportNumber)) { citationResponse.Accepted = false; citationResponse.Message = "Error occurred passing citation data to web service."; return citationResponse; } var isDuplicate = Repository.IsDuplicateReportNumber(citation.AgencyId, citation.ReportNumber, citation.ReportNumber_Prefix); citationResponse = new CitationResponse { Accepted = isDuplicate, Message = isDuplicate ? "Report Number already exists in database." : "Report Number has not yet been used." }; return citationResponse; } public CitationResponse Delete(CitationRequest citation) { var citationResponse = new CitationResponse(); try { if (Repository.DeleteCitation(citation.ReportNumber, citation.AgencyId, citation.ReportNumber_Prefix)) { citationResponse.Accepted = true; citationResponse.Message = "Citation removed from RMS successfully."; } else { citationResponse.Accepted = false; citationResponse.Message = "Citation NOT deleted from RMS. Check exception for details."; } } catch (Exception ex) { citationResponse.Accepted = false; citationResponse.Message = ex.Message; citationResponse.RmsException = new Exception(ex.Message); throw; } return citationResponse; } }

最后,这是我如何将数据发送到Web服务。 它始终适用于错误块:

SendCitationToDb: function (cit, callback) { $.ajax({ type: "POST", url: Citations.DataServiceUrl + "citations", data: JSON.stringify(cit), contentType: "application/json", dataType: "json", success: function(data) { if (!data.Accepted) { Citations.ShowMessage('Citation not added', 'Citation not added. Error was: ' + data.Message, 'error'); } else { ActivityId = data.ActivityId; callback(data); } }, error: function(errMsg) { Citations.ShowMessage('Citation not added', 'Citation not added. Error was: ' + errMsg.statusText, 'error'); } }); }

以下是Chrome开发工具的示例输出。 首先是这项服务的良好反应(GET):

在IIS ::中添加aspnet_isapi.dll路径到通配符后更新的响应(删除屏幕截图)

更新2 - 这是POST响应。 请求显示它是POST方法,但代码跳转到jQuery ajax函数中的错误块。 在开发工具中,我看到这一行:

然后我点击它并获取这些请求和响应标头:

不知道还有什么要寻找的 - 我知道它说状态代码200好了,但我认为那只是飞行前的OPTIONS ......? 不确定,但它没有从服务返回有效的响应。

非常感谢您的帮助!

I thought I had resolved my access issues to my ServiceStack web service in this question, but I'm now getting the same 'Access is denied' errors even with the fixes found in that solution and haven't been able to resolve them on my own.

Here's where I'm at with this: I've got a web service that I am sending data to using a POST method. I also have a GET method that returns the same response type as the POST, and that works fine. As far as I can tell, the request isn't even getting to ServiceStack before it fails. There are no Access-Control headers in the response, even though I'm using the CorsFeature plugin in my response headers. I can't figure out why it's not getting to any ServiceStack code though... Everything seems to be setup correctly. BTW, when I try the DELETE action I get a "403 Forbidden, Write access is denied" error from the server, if that's helpful at all?

Here's my Global.asax (pertinent sections):

public class AppHost : AppHostBase { public AppHost() : base("RMS Citations Web Service", typeof(CitationService).Assembly) { } public override void Configure(Container container) { SetConfig(new EndpointHostConfig { DefaultContentType = ContentType.Json, ReturnsInnerException = true, WsdlServiceNamespace = "http://www.servicestack.net/types" }); Plugins.Add(new CorsFeature()); RequestFilters.Add((httpReq, httpRes, requestDto) => { if (httpReq.HttpMethod == "OPTIONS") httpRes.EndRequestWithNoContent(); // extension method }); container.RegisterAutoWired<CitationRequest>(); // Not sure I need this - is it necessary for the Funq container? using (var addCitation = container.Resolve<CitationService>()) { addCitation.Post(container.Resolve<CitationRequest>()); addCitation.Get(container.Resolve<CitationRequest>()); addCitation.Delete(container.Resolve<CitationRequest>()); } } } protected void Application_Start(object sender, EventArgs e) { new AppHost().Init(); }

Here's my request and response classes:

[Route("/citations", "POST, OPTIONS")] [Route("/citations/{ReportNumber_Prefix}/{ReportNumber}/{AgencyId}", "GET, DELETE, OPTIONS")] public class CitationRequest : RmsData.Citation, IReturn<CitationResponse> { public CitationStatus Status { get; set; } } public enum CitationStatus { COMP, HOLD } public class CitationResponse { public bool Accepted { get; set; } public string ActivityId { get; set; } public int ParticipantId { get; set; } public string Message { get; set; } public Exception RmsException { get; set; } }

Here's my Service class:

public class CitationService : Service { public Repository Repository { get { return new Repository(); } } public CitationResponse Post(CitationRequest citation) { var response = new CitationResponse { Accepted = false }; if (string.IsNullOrEmpty(citation.ReportNumber)) { response.Accepted = false; response.Message = "Report number was empty, so no data was sent to the web service."; return response; } try { response.ActivityId = Repository.CreateCitation(citation.ReportNumber, citation.ReportNumber_Prefix, citation.ViolationDateTime, citation.AgencyId, citation.Status); response.Accepted = true; } catch (Exception ex) { response.Accepted = false; response.Message = ex.Message; response.RmsException = ex; } return response; } public CitationResponse Get(CitationRequest citation) { var citationResponse = new CitationResponse(); if (string.IsNullOrEmpty(citation.ReportNumber)) { citationResponse.Accepted = false; citationResponse.Message = "Error occurred passing citation data to web service."; return citationResponse; } var isDuplicate = Repository.IsDuplicateReportNumber(citation.AgencyId, citation.ReportNumber, citation.ReportNumber_Prefix); citationResponse = new CitationResponse { Accepted = isDuplicate, Message = isDuplicate ? "Report Number already exists in database." : "Report Number has not yet been used." }; return citationResponse; } public CitationResponse Delete(CitationRequest citation) { var citationResponse = new CitationResponse(); try { if (Repository.DeleteCitation(citation.ReportNumber, citation.AgencyId, citation.ReportNumber_Prefix)) { citationResponse.Accepted = true; citationResponse.Message = "Citation removed from RMS successfully."; } else { citationResponse.Accepted = false; citationResponse.Message = "Citation NOT deleted from RMS. Check exception for details."; } } catch (Exception ex) { citationResponse.Accepted = false; citationResponse.Message = ex.Message; citationResponse.RmsException = new Exception(ex.Message); throw; } return citationResponse; } }

Finally, here's how I send the data to the web service. It always goes right to the error block:

SendCitationToDb: function (cit, callback) { $.ajax({ type: "POST", url: Citations.DataServiceUrl + "citations", data: JSON.stringify(cit), contentType: "application/json", dataType: "json", success: function(data) { if (!data.Accepted) { Citations.ShowMessage('Citation not added', 'Citation not added. Error was: ' + data.Message, 'error'); } else { ActivityId = data.ActivityId; callback(data); } }, error: function(errMsg) { Citations.ShowMessage('Citation not added', 'Citation not added. Error was: ' + errMsg.statusText, 'error'); } }); }

Here's a sample output from Chrome dev tools. First a good response from this service (GET):

Updated response after adding aspnet_isapi.dll path to wildcards in IIS:: (removed screenshot)

Update 2 - That is the POST response. The request shows it's the POST method, but the code jumps right into the error block in the jQuery ajax function. In the dev tools I see this line:

Then I click it and get these request and response headers:

Not sure what else to look for - I know it says Status Code 200 OK, but I think that's just for the pre-flight OPTIONS...? Not sure, but it doesn't return a valid response from the service.

Your help is greatly appreciated!

最满意答案

看起来WebDav正在处理和拒绝您的请求。 您可以尝试禁用WebDav以查看它是否有帮助。

It looks like WebDav is handling and rejecting your request. You can try disabling WebDav to see if it helps.

更多推荐

response,public,POST,响应,电脑培训,计算机培训,IT培训"/> <meta name="descr

本文发布于:2023-07-30 11:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337877.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:以及其他   被拒   访问权限   ServiceStack   denied

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!