gpt4 book ai didi

json - Azure 应用服务中的授权规则不起作用

转载 作者:行者123 更新时间:2023-12-04 12:49:35 24 4
gpt4 key购买 nike

我按照 this blog post 上的说明进行操作尝试启用对主页的匿名访问,并在使用此authorization.json 访问/Admin 页面时重定向到Google。

{
"routes": [
{
"path_prefix": "/",
"policies": { "unauthenticated_action": "AllowAnonymous" }
},
{
"path_prefix": "/Admin",
"policies": { "unauthenticated_action": "RedirectToLoginPage" }
}
]
}

当我访问主页@ http://mysite.azurewebsites.net/时它总是引导我进入登录页面。在我登录然后发布重定向后,我在日志流中收到以下错误。

2016-12-02T04:30:44  PID[11016] Verbose     [Routes(Preview)] Attempting to load configuration from 'D:\home\site\wwwroot\authorization.json'.
2016-12-02T04:30:44 PID[11016] Critical System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type Microsoft.Azure.AppService.Routes.RoutesConfig. Encountered unexpected character 'ï'. ---> System.Xml.XmlException: Encountered unexpected character 'ï'.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception)
at System.Runtime.Serialization.Json.XmlJsonReader.ReadAttributes()
at System.Runtime.Serialization.Json.XmlJsonReader.ReadNonExistentElementName(StringHandleConstStringType elementName)
at System.Runtime.Serialization.Json.XmlJsonReader.Read()
at System.Xml.XmlBaseReader.IsStartElement()
at System.Xml.XmlBaseReader.IsStartElement(XmlDictionaryString localName, XmlDictionaryString namespaceUri)
at System.Runtime.Serialization.XmlReaderDelegator.IsStartElement(XmlDictionaryString localname, XmlDictionaryString ns)
at System.Runtime.Serialization.XmlObjectSerializer.IsRootElement(XmlReaderDelegator reader, DataContract contract, XmlDictionaryString name, XmlDictionaryString ns)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalIsStartObject(XmlReaderDelegator reader)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
--- End of inner exception stack trace ---
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader)
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(Stream stream)
at Microsoft.Azure.AppService.Authentication.ModuleUtils.DecodeJson[T](Stream jsonStream)
at Microsoft.Azure.AppService.Routes.RoutesConfig.TryLoadFromFile(String configFilePath, Func`2 deserializer, RoutesConfig& config)
at Microsoft.Azure.AppService.Routes.RoutesConfig.TryLoadFromJsonFile(String configFilePath, RoutesConfig& config)
at Microsoft.Azure.AppService.Routes.RoutesModule.TryLoadRoutesConfig(HttpContextBase context)
at Microsoft.Azure.AppService.Routes.RoutesModule.<OnPostAuthenticateRequestAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.AppService.Authentication.HttpModuleDispatcher.<DispatchAsync>d__13.MoveNext()
2016-12-02T04:30:44 PID[11016] Information Sending response: 500.79 Internal Server Error

其他详细信息。1.如上所述从 Visual Studio 发布后重新启动网站。2. 我在 AdminController 中拥有的那些/Admin 路径。3.authorization.json位于站点的根目录下。如果我导航到 PS D:\home\site\wwwroot>,我可以看到authorization.json 文件。

我不知道我在文件语法方面犯了什么错误。

最佳答案

根据你的描述,我关注了URL Authorization Rules并在我的 Visual Studio 中创建了authorization.json。我可以让它在我的 Azure Web 应用程序上按预期工作。

https://bruce-chen-001.azurewebsites.net/

https://bruce-chen-001.azurewebsites.net/admin/admin.html

我认为您的authorization.json 文件有问题。我发现了关于 Encountered unexpected character ‘ï’ error serializing JSON 的类似问题,你可以引用一下。

已更新

这是我的authorization.json 文件:

请确保您已在 Azure 门户上应用服务的身份验证/授权边栏选项卡中的“请求未经身份验证时采取的操作”下选择允许匿名请求(无操作)

关于json - Azure 应用服务中的授权规则不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40924945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com