我遇到的問題是FormatException錯誤在mscorlib.dll中發生類型:'System.FormatException'的異常,但未在用戶代碼中處理 其他信息:Guid應該包含32個數字,並帶有4個破折號(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。因此Guid在返回URL被註釋掉時正在工作,但當我出於某種原因包含Guid時,Guid全部爲零。 這裏是代碼從配置文件頁面登錄時嘗試獲取返回URL
if (Request.QueryString["userId"] != null)
{
MasterPage masterpage = Page.Master;
HtmlAnchor anchor = (HtmlAnchor)masterpage.FindControl("ancLogin");
Guid userId = new Guid(Request.QueryString["userId"]);
User user = new User();
user = user.GetById(userId);
lblUserName.Text = user.UserName;
imgProfile.ImageUrl = "~/" + user.ProfilePic;
PostList posts = new PostList();
posts = posts.GetByUserId(userId);
CommentsList comments = new CommentsList();
comments = comments.GetByUserId(userId);
rptPost.DataSource = posts.List;
rptPost.DataBind();
rptComments.DataSource = comments.List;
rptComments.DataBind();
anchor.HRef = "/Account/Login.aspx?returnURL=/Account/Profile.aspx?userId=" + userId;
if (Session["User"] != null)
{
if (((User)Session["User"]).Id == userId)
{
btnChangePicture.Enabled = true;
fuChangeProfileImage.Enabled = true;
fuChangeProfileImage.Visible = true;
btnChangePicture.Visible = true;
}
}
}
else
{
Response.Redirect("Default.aspx");
}
這是我遇到的時候添加到代碼我得到的格式異常麻煩就行了。 anchor.HRef =「/Account/Login.aspx?returnURL=/Account/Profile.aspx?userId=」+ userId; 此外,這就像我第二次問這裏的問題,讓我知道如果我格式化代碼錯誤或任何感謝!
編輯我修復了這個問題我在登錄頁面中發生了一些其他的連接,並且它添加了userId兩次。感謝大家的幫助。
錯誤消息告訴你什麼是錯誤的:'userId' GUID格式錯誤。 – Steve
這就是爲什麼它是一個奇怪的錯誤,因爲格式是正確的,我使用相同的Guid通過我的存儲過程搜索數據庫,例如這是一個用戶配置文件,它正在加載評論和他們的帖子由同一個userId 。當我將錨點href添加回代碼時,它變爲全零。 – Chase