2013-06-25 36 views
0

我有一個使用web表單和MVC的web應用程序。我有一個web表單的功能,工作正常。現在我想引用它的MVC控制器如何將Web窗體功能傳遞給MVC控制器?

這是我在網絡表單中使用的功能:

public string getClaimValue() 
{ 
    string claimvalue = null; 
    var claimsId = Page.User.Identity as IClaimsIdentity; 
    if (claimsId != null) 
    { 
     var claims = claimsId.Claims; 
     foreach (var claim in claims) 
     { 
      string claimtype = claim.ClaimType.ToString(); 
      int index = claimtype.IndexOf("MBUN"); 
      if (index > 0) 
      { 
       claimvalue = claim.Value; 
      } 
     } 
    } 
    return claimvalue; 
} 

但是,當我把這個功能下MVC控制器,我得到了在「頁面」紅線說: '這個名字在當前的情況下不存在'。刪除「網頁」後,但我沒有在網絡表單中期望的值。 需要你的幫助。 謝謝。

回答

1

頁面是webforms特定的對象。

System.Web.HttpContext.Current.User.Identity 
+0

+1良好的工作:

與更換。兩者都很常見。 –

+0

我之前嘗試過,它不起作用。同樣的功能,在網頁形式中,我可以獲得claimtype相等的'MBUN'。但在MVC中,如果我使用System.Web.HttpContext.Current.User.Identity作爲claimid,我無法獲得claimtype'MBUN'。我可以在Web窗體和MVC中找到不同的值,Web窗體中的計數值是4,但在MVC中是0。不知道爲什麼。 – howexg9

+0

那麼Page.User.Identity只是System.Web.HttpContext.Current.User.Identity的一個快捷方式。 看來你的webforms應用程序正確地設置了User.Identity對象(可能在頁面的基類中),但它並沒有在你的MVC控制器中設置。 –

相關問題