我正在使用 ASP.NET 登录控件进行身份验证。
我有一些用户,他们能够成功登录。 经过身份验证后,我重定向到页面 helloworld.aspx。 在 Page_Load 方法中,我首先调用 Membership.GetUser()。 这将正确返回经过身份验证的用户。 然后,我调用驻留在同一 Web 应用程序中的简单 WCF Web 服务。 我的 WebService 调用的第一行是相同的 Membership.GetUser()。 但这一次它返回 NULL。
有什么想法吗?
谢谢,
Justin
这里是一些代码片段
JustinPage.aspx
public partial class JustinPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MembershipUser user = Membership.GetUser();
// user is a valid user
JustinService.JustinTestServiceClient justin = new CMS.WEB.JustinService.JustinTestServiceClient();
justin.DoWork();
}
}
JustinTestService.svc.cs
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class JustinTestService
{
[OperationContract]
public void DoWork()
{
MembershipUser user = Membership.GetUser();
// user is NULL ??? Why?
return;
}
}
正如前面提到的,服务源代码位于与 Justin.aspx 相同的 Web 应用程序中,正如您可以通过端点看到的那样(注意我的应用程序固定在端口 19003 上)...
端点地址=“http://localhost:19003/Services/JustinTestService.svc”
绑定=“basicHttpBinding”绑定配置=“BasicHttpBinding_JustinTestService”
Contract="JustinService.JustinTestService" name="BasicHttpBinding_JustinTestService" /
绑定看起来像这样...
<安全模式=“无”>
也许它与 有关。 ???
I am using the ASP.NET Login Control for authentication.
I have some users and they are able to login successfully. When authenticated I redirect to a page helloworld.aspx. In the Page_Load method I first make a call to Membership.GetUser(). This returns the authenticated user properly. I then make a call to a simple WCF web service that resides in the same WebApplication. The first line of my WebService call's the same Membership.GetUser(). This time though it returns NULL.
Any thoughts?
Thanks,
Justin
Here is some code snippets
JustinPage.aspx
public partial class JustinPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MembershipUser user = Membership.GetUser();
// user is a valid user
JustinService.JustinTestServiceClient justin = new CMS.WEB.JustinService.JustinTestServiceClient();
justin.DoWork();
}
}
JustinTestService.svc.cs
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class JustinTestService
{
[OperationContract]
public void DoWork()
{
MembershipUser user = Membership.GetUser();
// user is NULL ??? Why?
return;
}
}
As mentioned earlier the Service source code is in the Same WebApplication as Justin.aspx as you can see by the endpoint (note my app is fixed on port 19003)...
endpoint address="http://localhost:19003/Services/JustinTestService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_JustinTestService"
contract="JustinService.JustinTestService" name="BasicHttpBinding_JustinTestService" /
Also the binding looks like this...
<binding name="BasicHttpBinding_JustinTestService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
</security>
</binding>
Maybe it has something to do with the <security mode="None"> ???
发布评论
评论(2)
问题在于 Web 服务调用并非源自用户进行身份验证的浏览器。 相反,您从应用程序发起 Web 服务调用(您的 Web 服务器正在向您的 Web 服务器创建 HTTP 请求!)。
The problem is that the web service call is not originating from the browser, where the user authenticated. Instead, you are originating the web service call from your application (your web server is creating an HTTP request to your web server!).
获取 fiddler 并查看身份验证 cookie 是否正在通过网络发送。
如果不是,您可能需要将其捆绑在您对服务的请求中。
像这样的东西
Get fiddler and see if the the authentication cookie is being sent across the wire.
If it isn't you might need to bundle it up in your request to the service.
Something like this