2016-12-02 86 views
0

我遵循关于this blog post的说明,尝试为主页启用匿名访问,并在使用此authorization.json访问/ Admin页面时重定向到Google。Azure App Service中的授权规则不起作用

{ 
    "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文件。

我不知道我在错误的文件的语法。

回答

2

根据你的描述,我跟着URL Authorization Rules在我的Visual Studio中创建了authorization.json。我可以在我的Azure Web App上按预期工作。

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门户上应用服务的身份验证/授权刀片中。

+0

您可以更新您的答案,包括你在网站上使用authorization.json文件?我跟着msdn的文章来清除这些字符,然后再次尝试并重新启动了该网站,但仍在导航到/它不允许匿名登录。 – Mitul

+0

@Mitul我已经更新了我的答案。请看我的更新。 –

+0

请求未通过身份验证时,我必须执行“采用Google登录”时采取的操作。将其更改为允许匿名请求(无操作)并且它可以工作。谢谢。 – Mitul