2013-05-04 64 views
0

只是一個小的查詢System.Web.Services:有沒有在Context.User.Identity密碼財產

使用.NET Web服務,並創建了簡單的登錄方法

[WebMethod] 
    public bool Login(string sUsername, string sPwd) 
    { 
     if (sUsername == Context.User.Identity.Name && **sPwd == "123456"**) 
     { 
      FormsAuthentication.SetAuthCookie(sUsername, true); 
      return true; 
     } 
     else 
      return false; 

    } 

IM有任何密碼財產比如「Context.User.Identity.Name」。或任何其他可替代

請建議,如果我失去了一些東西

+0

你想完成windows驗證?而且沒有這種靈活的上下文.user.identity.password – 2013-05-04 13:11:15

+0

ASMX是一項傳統技術,不應該用於新開發。 WCF應該用於Web服務客戶端和服務器的所有新開發。一個暗示:微軟已經在MSDN上退役了[ASMX Forum](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads)。 – 2013-05-04 13:50:09

回答

0

你的做法是沒有意義的。 Context.User由Forms Authentication模塊設置,該模塊依賴於表單cookie的信息。另一方面,您嘗試使用這些信息來實際發佈cookie。

這意味着您實際上需要cookie來發出cookie。這不起作用。

嘗試重新思考該方法 - 您可能需要外部數據源(如數據庫或其他)來驗證您的用戶。在數據庫中,您將以某種方式存儲用戶名和密碼。