2012-06-27 22 views
5

Tôi có một trang web có chứa điều khiển createuserwizard. Và khi tạo tài khoản, email xác minh cùng với URL xác minh sẽ được gửi đến địa chỉ email của người dùng.Hướng dẫn phải chứa 32 chữ số với 4 dấu gạch ngang

Tuy nhiên, khi tôi có một chạy thử, khi cách nhấp vào URL trong email, lỗi này xuất hiện:

Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). 


Source Error: 

Line 17:   { 
Line 18:    //store the user id 
*Line 19:    Guid userId = new Guid(Request.QueryString["ID"]);* 
Line 20: 
Error appeared on LINE 19. 

Một điều thú vị là, các URL xác minh trong tôi chạy thử trông lạ:

http://localhost:4635/WebSite2/Verify.aspx?ID=System.Security.Principal.GenericPrincipal 

Thông thường, URL nên như thế này (mà là một toàn bộ rất nhiều nhân vật ở phần cuối của URL:

http://localhost:2180/LoginPage/EmailConfirmation.aspx?ID=204696d6-0255-41a7-bb0f-4d7851bf7200 

Tôi đã thực sự nghĩ rằng, nó có một kết nối với sự kết thúc của URL với vấn đề của tôi về lỗi (Guid nên chứa 32 chữ số với 4 dấu gạch ngang) ..

Mã tạo URL như sau:

protected void CreateUserWizard1_SendingMail(object sender,MailMessageEventArgs e) 
{ 
    string domainName = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath; 
    string confirmationPage = "/Verify.aspx?ID=" + User.ToString(); 
    string url = domainName + confirmationPage; 
    e.Message.Body = e.Message.Body.Replace("<%VerificationUrl%>", url); 
} 

Vui lòng cho tôi đề xuất và những gì tôi nên làm để giải quyết vấn đề này.

Xin cảm ơn trước.

UPDATE:

protected void CreateUserWizard1_SendingMail(object sender,MailMessageEventArgs e) 
{ 
    MembershipUser userInfo = Membership.GetUser(CreateUserWizard1.UserName); 
    Guid userInfoId = (Guid)userInfo.ProviderUserKey; 

    string domainName = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath; 
    string confirmationPage = "/Verify.aspx?ID=" + userInfo.ToString(); 
    string url = domainName + confirmationPage; 

    e.Message.Body = e.Message.Body.Replace("<%VerificationUrl%>", url); 

} 

Bây giờ URL của tôi liên kết cái nhìn như thế này:

http://localhost:4635/WebSite2/Verify.aspx?ID=username 

Nhưng lỗi "Guid nên chứa 32 chữ số với 4 dấu gạch ngang (xxxxxxxx-xxxxxxxx-xxxx -xxxxxxxxxxxx "vẫn được giữ nguyên là

+1

Làm thế nào để hiển thị cho chúng tôi mã tạo liên kết? Đó rõ ràng là vấn đề nằm ở đâu. – spender

+0

đây là mã để tạo URL: bảo vệ void CreateUserWizard1_SendingMail (đối tượng người gửi, MailMessageEventArgs e) { // MembershipUser userInfo = Membership.GetUser (CreateUserWizard1.UserName); // Hướng dẫn sử dụngInfoId = (Hướng dẫn) userInfo.ProviderUserKey; string domainName = Request.Url.GetLeftPart (UriPartial.Authority) + Request.ApplicationPath; xác nhận chuỗiPage = "/Verify.aspx?ID=" + User.ToString(); string url = domainName + confirmationPage; e.Message.Body = e.Message.Body.Replace ("<% VerificationUrl%>", url); } – user1467175

Trả lời

4

Bạn đã có một dòng nói rằng:

Guid userInfoId = (Guid)userInfo.ProviderUserKey; 

Chắc chắn đây là những gì bạn nên cung cấp trong URL?

string confirmationPage = "/Verify.aspx?ID=" + userInfoId.ToString(); 
+0

Vâng, dòng này là mặt sau của URL – user1467175

+0

Có, nhưng phiên bản của tôi khác với phiên bản của bạn. Tôi đã sử dụng 'userInfoId.ToString()'. Bạn đã sử dụng 'userInfo.ToString()' –

+0

Bạn đã đúng, tôi đã thay đổi nó thành userInfoId, và nó đã giải quyết được lỗi! cảm ơn (: – user1467175

3

Bạn đang đặt ID là:

User.ToString() 

này giải quyết cho chuỗi:

"System.Security.Principal.GenericPrincipal" 

Tôi không thấy một GUID bất cứ nơi nào, do đó, nó bất kỳ ai đoán như thế nào bạn muốn tạo này.

+0

Tôi nên đặt "System.Security.Principal.GenericPrincipal" ở đâu? như một không gian tên? – user1467175

0

Bạn chưa đi qua ID đó là trong trường hợp của bạn GUID, Bạn đang cố gắng để vượt qua ID value=User.Tostring().

0

Bạn nên thực hiện hai thay đổi. Thứ nhất, như đã đề cập, User.ToString() sẽ luôn sản xuất "System.Security.Principal.GenericPrincipal". Bạn nên thay đổi này để:

User.Guid.ToString() 

Thứ hai, trang web của bạn nên mã phòng thủ và sử dụng TryParse như trong:

Guid g; 
    if (Guid.TryParse(Request.QueryString["ID"], out g)) 
    // its a good Guid 
    else 
    // its not a valid Guid 
Các vấn đề liên quan