Object Moved Here error

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, // Ticket version

                txtUserName.Text,// Username to be associated with this ticket

                DateTime.Now, // Date/time ticket was issued

                DateTime.Now.AddMinutes(50), // Date and time the cookie will expire

                false, // if user has chcked rememebr me then create persistent cookie

                "", // store the user data, in this case roles of the user

                FormsAuthentication.FormsCookiePath); // Cookie path specified in the web.config file in <Forms> tag if any.

            string hashCookies = FormsAuthentication.Encrypt(ticket);

            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies); // Hashed ticket

            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.

+3
source share
1 answer

You must specifically allow access to the login page, or no one will be able to read it, who has not logged in yet.

. ASP.NET - <deny users="?"/> .

+1

Source: https://habr.com/ru/post/1757132/


All Articles