有很多类似的问题,我已经查看了所有可以找到的问题,但没有发现解决方法。
我将 Google+ 认证的 API 密钥存储在一个 .config 文件中,这个文件位于我的解决方案之外(与解决方案文件夹处于相同级别)。
我试图在 Startup.Auth.cs 中读取这些值,代码如下:
public void ConfigureAuth(IAppBuilder app)
{
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = WebConfigurationManager.AppSettings.Get("GoogleClientId"),
ClientSecret = WebConfigurationManager.AppSettings.Get("GoogleClientSecret")
});
}
根 Web.config:
<appSettings file="..\Secrets.config"> <!-- Path is correct, relative to Web.config -->
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
Secrets.config:
<configuration>
<appSettings>
<add key="GoogleClientId" value="shh" />
<add key="GoogleClientSecret" value="shh" />
</appSettings>
</configuration>