2016-12-02 90 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