問題出在這裏,我想要使用內置的成員函數來處理用戶,特別是使用Oracle.Web.Security.OracleMembershipProvider。我有提供者在.aspx文件中工作,正確地將新用戶插入到相應的Oracle表中並處理登錄。但是,我在解決方案的網站組件旁邊有一個web服務。我只需要通過網站註冊的用戶,並且可以通過網絡請求發送有效的用戶名/密碼以便能夠訪問數據。如何在C#類(.cs文件)和ASP.NET .aspx文件中使用相同的OracleMembershipProvider?
不管怎麼說,在cs文件我這樣做:
OracleMembershipProvider provider = new OracleMembershipProvider();
if (!provider.ValidateUser(username, password))
{
return null;
}
到的ValidateUser調用拋出一個異常,細節: 「OracleConnection.ConnectionString是無效的」。
我想認爲連接字符串在.aspx頁面上工作的事實足以確認連接字符串是有效的。
下面是它看起來像在.aspx文件,關鍵是第二行的MembershipProvider =「MyOracleMembershipProvider」
<asp:Login ID="LoginUser" runat="server" EnableViewState="false"
RenderOuterTable="false" MembershipProvider="MyOracleMembershipProvider">
<LayoutTemplate>
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="LoginUserValidationGroup"/>
<div class="accountInfo">
<fieldset class="login">
<legend>Account Information</legend>
<p>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
//blah blah blah, code removed for length.
</fieldset>
<p class="submitButton">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/>
</p>
</div>
</LayoutTemplate>
</asp:Login>
查看一些的「供應商」的細節揭示基本上都空/默認值,表明它沒有正確初始化。我印象中的構造應該利用我的默認成員資格提供,按我的web.config文件,主要內容如下初始化成員提供:
<configuration>
<system.data>
<DbProviderFactories>
<clear />
<add name="xxxOracleDataProvider" invariant="Oracle.DataAccess.Client" description=".Net Framework Data Provider for Oracle"
type="Oracle.DataAccess.Client.OracleClientFactory,
Oracle.DataAccess,
Version=4.112.2.0,
Culture=neutral,
PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="MEMBERSHIP_PROVIDER"
connectionString="
Persist Security Info=True;
user id = xxxxxx;
password = xxxxxx;
data source=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = xxxxxxx)
(PORT = xxxxxxxx)
)
)
(CONNECT_DATA =
(SERVICE_NAME = xxxxx)
(SERVER = DEDICATED)
)
);"
providerName="Oracle.DataAccess"
/>
</connectionStrings>
<system.web>
<customErrors mode="Off"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
<compilation debug="true"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership defaultProvider="MyOracleMembershipProvider" hashAlgorithmType="SHA1">
<providers>
<clear />
<add name="MyOracleMembershipProvider"
type="Oracle.Web.Security.OracleMembershipProvider,
Oracle.Web, Version=4.112.1.2, Culture=neutral,
PublicKeyToken=89b483f429c47342"
connectionStringName="MEMBERSHIP_PROVIDER"
applicationName="xxx_xxxx_xxxxxx"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
passwordFormat="Hashed"
minRequiredNonalphanumericCharacters="0"
maxInvalidPasswordAttempts="7"
minRequiredPasswordLength="12"
passwordAttemptWindow="8"
/>
</providers>
</membership>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
我已經試過:
Membership.Provider.ValidateUser(username, password)
還有
。它總是返回false,並且Providers屬性與我的默認提供程序的屬性不匹配(當我設置斷點並觀察對象時)。
任何人有任何想法如何解決這個問題?我覺得應該很簡單,因爲數據提供者在.aspx頁面上工作正常,但是我不能在我的生活中獲得一個.cs文件來使用相同的提供程序,甚至看不到提供程序存在。