I need to publish a demo website to the web. I need to secure access to the site.
The live site with use SQL Server as the membership provider. However, for the demo site I can only publish to a simple web host and have no access to SQL Server.
I need only a single user, and they don't need option to change password etc. Therefore, I thought easiest way to achieve this would be to use the member of within the web.config. I have created as follows:
<?xml version="1.0"?>
<configuration xmlns="http://sch开发者_如何学Pythonemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<authentication mode="Forms">
<forms name="ProjectApple" loginUrl="~Login.aspx">
<credentials passwordFormat="Clear">
<user name="lawyer" password="Super12."/>
</credentials>
</forms>
</authentication>
<compilation debug="true"/>
</system.web>
</configuration>
I will use SHA1 hash when I can get this working. Problem is, it recognises when I've entered an invalid password. However, when I enter the correct password I get the following:
Cannot open user default database. Login failed.
Login failed for user 'RB-T510\Rob'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open user default database. Login failed.
Login failed for user 'RB-T510\Rob'.
I don't know why it's looking for SQL? Can anyone help please?
I'm using VS2010 and .Net 3.5
Many thanks,
Rob
To use forms authentication with credentials in web.config you must use FormsAuthentication.Authenticate method. Looks like you have default Login control that is trying to access membership class.
I am going to guess, based on the format of the user name in the error, that you still have a connection string in your web.config with Integrated Security=True
and there is some control on the page that is opening that is requesting data from SQL.
First Check out your Authentication mode. if SQLAuthentication, Give UserId,and Password in your Connection String. Example:
<"Data source="";Initial Catalog="Dbname";UserId=sa;Password=1234">
精彩评论