I have a quick question and ask you all to answer soon.
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);
}
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.AllowAutoRedirect = false;
NetworkCredential credentials = new NetworkCredential("test", "test");
service.Credentials = credentials;
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.
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="%2fWebService1%2fLoginpage.aspx%3fReturnUrl %3d%252fWebService1%252fService1.asmx">here</a>.</h2>
</body></html>
Could you share your thoughts to fix this?