C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to Hide a WebMethod for only some people


Posted Date: 16 Oct 2008      Total Responses: 2

Posted By: bharath       Member Level: Bronze     Points: 1


Hi,
i've 2 webmethods in my webservice out of which i need to give access to one user and the other webmethod to another.. i was really embarassed with the question in an interview i pretended saying like u can use roles based authentication.. blah blah blah... but it is not correct i think... kindly work out on this n let everybody know what shud we do with this

thanks in advance




Responses

Author: Kiran Kumar Raju    22 Oct 2008Member Level: SilverRating:     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 2008Member Level: SilverRating:     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
{
}
}



Post Reply
You must Sign In to post a response.
Next : General Question
Previous : Project About On-Line Exam
Return to Discussion Forum
Post New Message
Category: Webservices

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

email fax service

Contact Us    Privacy Policy    Terms Of Use