| Author: Kiran Kumar Raju 22 Oct 2008 | Member Level: Silver | Rating: Points: 6 |
Hi Bharath,
We can call this as "Pre-Method Authetication (using SQL)". To implement this, you have to maintain user credentials in Database. Then add username and password to each of your web methods and authenticate the user before executing a method.
I am not able to giving full length of code, but I am providing you a sample code for reference,
public class CustomAuth : System.Web.Services.WebServices { public CustomAuth() {}
[WebMethod (Description="Returns one value"] { // Authenticate the user if (!Authenticate(username, password) { throw new Exception("Invalid Username / Password"); } return i; }
private bool Authenticate(String user, String Password) { bool retAuth = false; try { //Connect to Database and check the username and password //write the functionality to provide permissions based on //your own constraints ............................... ............................... ...............................
In the above code you can define the constraints - based on role of a user, based on domain etc.
Thanks Kiran Kumar Raju
|
| Author: Natchatraa 25 Nov 2008 | Member Level: Silver | Rating: Points: 6 |
In Web.Config add your Particular access UserID and password
<appSettings> <add key="CUSTOMER" value="cuspass"/> </appSettings> Create one IsAuth.cs and write the following code public bool IsAuth(string UserId, string Password) { bool bResult = false; string strPWD = string.Empty; strPWD = ConfigurationManager.AppSettings[UserId].ToString(); try { if (strPWD == Password) { bResult = true; } return bResult; } catch (Exception ex) { return bResult; } } In WebMethod [WebMethod] public string GetForm(string strFormInfo, string UserId, string Password) { try { if (!IsAuth(UserId, Password)) //IsAuth method called to verify the Userid and password { ...... } catch (Exception ex) { } finally { } }
|