私は最近、実際のサイトと同じサーバー上に個人の Web サイトの新しいインスタンスをセットアップしました。新しいインスタンスは「最新」の構成であるため、現在取り組んでいる最新のビルドの新機能がすべて含まれています。最新のビルドでは、ターゲット フレームワークを 2.0 から 3.5 に切り替えました。これは、コンパイルされたアイテムと同じくらい大きな変更のみです。
すべてのメンバー ページ、その他のページ、および一部のユーザー コントロールで、これら 2 つの項目のいずれかまたは両方を呼び出しましたが、それぞれが失敗しObject reference not set to an instance of an object、エラーが発生しています。しかし、すべてのページではありません!
public static string CurrentUserName
{
get
{
string userName = "";
if (HttpContext.Current.User.Identity.IsAuthenticated)
userName = HttpContext.Current.User.Identity.Name;
return userName;
}
}
public static string CurrentUserID
{
get
{
string userID = "";
if (HttpContext.Current.User.Identity.IsAuthenticated) //Line 39
{
MembershipUser user = Membership.GetUser();
userID = user.ProviderUserKey.ToString();
}
return userID;
}
}
スタック トレースは次のとおりです。
[NullReferenceException: Object reference not set to an instance of an object.]
isClasses.BizObjects.get_CurrentUserID() in C:\My Dropbox\Trunk\Classes\BizObjects.cs:39
TheImageStore_Profile..ctor() in w:\dev\Member\Profile.aspx.cs:9
ASP.member_profile_aspx..ctor() in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\faba6118\7249af47\App_Web_profile.aspx.48943a5b.w8t4pvz5.0.cs:0
__ASP.FastObjectFactory_app_web_profile_aspx_48943a5b_w8t4pvz5.Create_ASP_member_profile_aspx() in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\faba6118\7249af47\App_Web_profile.aspx.48943a5b.w8t4pvz5.2.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +119
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +37
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +307
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
ただし、これは Server 2008 の IIS 7 でのみ発生していることに注意してください。サイトは Visual Studio 2008 から完全に機能しています。IIS のメイン Web サイトをこのディレクトリに接続しても、同じことが行われます。これはどのように発生する可能性があり、何が原因である可能性がありますか?
キックのために、Target Framework を 2.0 に戻しましたが、それでも同じ問題が発生します。また、これは、メンバーページだけでなく、訪問者がログインしているかどうかに関係なく発生しているようです.