I developed a web service with form-based authentication as shown below.
1. Enter the web.config file as shown below.
<authentication mode="Forms">
<forms loginUrl="Loginpage.aspx" name=".AuthAspx">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<authentication mode="Forms">
<forms loginUrl="Loginpage.aspx" name=".AuthAspx"/></authentication>
<authorization><deny users="?"/> </authorization>
2. The user of the login page is checked for the button click event as follows.
if (txtUserName.Text == "test" && txtPassword.Text == "test")
{
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
txtUserName.Text,
DateTime.Now,
DateTime.Now.AddMinutes(50),
false,
"",
FormsAuthentication.FormsCookiePath);
string hashCookies = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
Response.Cookies.Add(cookie);
string returnUrl = Request.QueryString["ReturnUrl"];
if (returnUrl == null) returnUrl = "~/Default.aspx";
Response.Redirect(returnUrl, false);
}
3.Webservice has a default web method.
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
4. From a web application, I make a webservice call, creating a proxy server after adding a web link to the aforementioned web service.
localhost.Service1 service = new localhost.Service1();
service.Credentials = ystem.Net.CredentialCache.DefaultNetworkCredentials;;
string hello = service.HelloWorld();
Response.Write(hello);
and here, while consuming it in a web application, the exception below is thrown from the webservice proxy.
- Object moved
The object has moved here.
source
share