![](/img/trans.png)
[英]Property Gets The Default Value After Calling PropertyInfo.SetValue
[英]How the `IsAuthenticated` property gets true value by default?
在Page_Load事件處理程序函數中,我嘗試了以下操作:
protected void Page_Load(object sender, EventArgs e)
{
if (Context.User.Identity.IsAuthenticated)
{
Response.Write("Hello World");
}
}
而且有效! 瀏覽器顯示“ Hello World”! 但是IsAuthenticated
屬性如何默認情況下獲得真值?
我的web.config文件如下:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="arsenicDesktopConnectionString" connectionString="Data Source=localhost\sqlexpress;Initial Catalog=arsenicDesktop;Persist Security Info=True;User ID=sa;Password=1234"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<!--LOCAL APPLICATION SETTINGS-->
<appSettings>
<add key="Accounts_SettingsFile" value="C:\Users\user\Documents\Visual Studio 2010\WebSites\UserAuthenticationSystem\Config\Accounts.Config"/>
</appSettings>
</configuration>
它取決於<authentication />
元素的mode屬性。 如果是Windows,它將使用當前的Windows用戶將其設置為true; 如果是表格,則必須登錄。
在此處設置表單身份驗證的指南: http : //msdn.microsoft.com/zh-cn/library/ff647070.aspx
添加以下內容:
<authentication mode="Windows"/>
<system.web>
部分中的某處,例如:
<configuration>
<system.web>
<authentication mode="Windows"/>
<system.web>
</configuration>
更新您的示例:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="arsenicDesktopConnectionString" connectionString="Data Source=localhost\sqlexpress;Initial Catalog=arsenicDesktop;Persist Security Info=True;User ID=sa;Password=1234"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0" />
<authentication mode="Windows"/>
</system.web>
<!--LOCAL APPLICATION SETTINGS-->
<appSettings>
<add key="Accounts_SettingsFile" value="C:\Users\user\Documents\Visual Studio 2010\WebSites\UserAuthenticationSystem\Config\Accounts.Config"/>
</appSettings>
</configuration>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.