session variables
WebMatrix Web ページ全体で使用したいと思います。
理由は不明ですが、not available accross the pages
(それらが定義されているページのみ) です。
ログインページのコードセクション:
if (WebSecurity.Login(userName, password, rememberMe)) {
// Session variable holding the UserType
var db = Database.Open("MyDatabase");
var userTypeData = db.QuerySingle("SELECT Name FROM UserTypes INNER JOIN UserProfiles ON UserProfiles.UserTypeId = UserTypes.UserTypeId WHERE UserId = @0",WebSecurity.CurrentUserId);
Session ["UserType"] = userTypeData.Name;
// Eventual redirection to the previous URL
var returnUrl = Request.QueryString["ReturnUrl"];
if (returnUrl.IsEmpty()) {
Response.Redirect("~/auth/authenticated");
}
else {
Context.RedirectLocal(returnUrl);
}
"Cannot perform runtime binding on a null reference"
したがって、UserType が常に存在する場合は、ここに到達します。これが最初の問題です。
リダイレクトされた「認証済み」ページで、まったく同じクエリとセッション変数の定義を使用すると、次のように表示できます。
You are a user of type: @Session["UserType"] -> HTML section
他のページでは、セッション変数を介して「表示または非表示 (更新) ボタン」を試みています。
@if (Session["UserType"]=="here the variable value; a string") {
<a class="linkbutton" href="condoedit?condoId=@condoData.CondoId">Update</a>
}
ボタンがsession variable appears to be empty
!!として表示されることはありません。