gpt4 book ai didi

c# - 对象移至此处错误

转载 作者:行者123 更新时间:2023-11-30 18:08:17 25 4
gpt4 key购买 nike

我开发了一个基于表单的身份验证的 Web 服务,如下所示。

1.web.config 中的条目如下。

<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.在登录页面中,用户按如下方式验证按钮单击事件。

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有一个默认的webmethod。

[网络方法]

    public string HelloWorld()

{

return "Hello World";

}

4.在添加上述 web 服务的 web 引用后,我通过创建代理来从 web 应用程序调用 web 服务。

          localhost.Service1 service = new localhost.Service1();           


service.Credentials = ystem.Net.CredentialCache.DefaultNetworkCredentials;;


string hello = service.HelloWorld();

Response.Write(hello);

在 Web 应用程序中使用它时,Web 服务代理抛出了以下异常。

--物体移动

对象移动到这里。

最佳答案

您必须特别允许访问登录页面,否则没有登录的人无法阅读它。

参见 ASP.NET Authorization - <deny users="?"/>拒绝所有匿名用户。

关于c# - 对象移至此处错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3362324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com