추적 할 수없는 문제가 있습니다. 내 WebMatrix 사이트를 통해 등록한 후 로그온 할 수 없습니다. 이메일에 확인 토큰을 보내도록 등록을 시작하기 전에 잘 로그인 할 수있었습니다. 여기에 내가 점점 오전 YSOD 오류 (오류는 로그인 파일의 21 행에 특히 발생)입니다 :내 WebMatrix 면도칼 C# 사이트에 새로 등록한 사용자로 로그인하면 오류가 발생합니다.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot implicitly convert type 'WebMatrix.Data.DynamicRecord' to 'string'
Source Error:
Line 19: {
Line 20: var db = Database.Open("Users");
Line 21: user = db.QuerySingle("SELECT firstName FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", username);
Line 22:
Line 23: AppState["gActionMessage"] = "Hello, " + user + "!";
Source File: c:\Users\cradebaugh\Documents\My Web Sites\Persons Of Interest\Account\Login.cshtml Line: 21
그리고 여기에있는 관련된 파일 :
REGISTER 페이지 :
@{
var email = "";
var firstName = "";
var lastName = "";
var password = "";
var confirmPassword ="";
var errorMessage = "";
AppState["gActionMessage"] = "";
if(IsPost)
{
email = Request.Form["email"];
firstName = Request.Form["firstName"];
lastName = Request.Form["lastName"];
password = Request.Form["password"];
confirmPassword = Request.Form["confirmPassword"];
if(email.IsEmpty() || password.IsEmpty())
{
errorMessage = "You must specify both an email address and a password";
}
if(password != confirmPassword)
{
errorMessage = "The password and the confirmation password do not match.";
}
if(!EmailValidator.IsEmailAdress(email))
{
errorMessage = "The email you entered is not a valid email address.";
}
if(firstName=="" || lastName=="")
{
errorMessage = "You must provide both a first and last name";
}
if(errorMessage=="")
{
var db = Database.Open("Users");
var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", email);
if(user==null)
{
WebSecurity.Logout();
db.Execute("INSERT INTO UserProfile (Email, IPAddress, firstName, lastName) VALUES (@0, @1, @2, @3)", email, Request.UserHostAddress, firstName, lastName);
var token = WebSecurity.CreateAccount(email, password, true);
var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
var confirmationUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Confirm?confirmationCode=" + HttpUtility.UrlEncode(token) + "&firstName=" + firstName);
WebMail.Send(
to: email,
subject: "Please confirm your account",
body: "Your confirmation code is: " + token + ". Visit <a href=\"" + confirmationUrl + "\">" + confirmationUrl + "</a> to activate your account."
);
AppState["gActionMessage"] = "An email to confirm your account has been emailed to you.";
AppState["gActionMessageDisplayed"] = "not";
Response.Redirect("~/IntroPage.cshtml");
}
else
{
errorMessage = "That email address is already in use.";
}
}
}
}
@RenderPage("~/Shared/HeaderLayout.cshtml")
<div style="color: #808080;">
<span class="heading">Register</span>
<span style="font-size: 3em;">________________________________________________</span></br></br></br>
</div>
@{
if (errorMessage != "")
{
<div class="errorMessageWrapper">@errorMessage</div><br/>
}
}
<div class="accInterfaceWrapper">
<form class="accInterfaceForm" method="post" action="">
<table class="accInterfaceTable">
<tr>
<td class="accInterfaceLabelCell">
<label for="email">Email Address:</label>
</td>
<td class="accInterfaceInputCell">
<input type="text" id="email" name="email" value="@email" /><br/><br/>
</td>
</tr>
<tr>
<td class="accInterfaceLabelCell">
<label for="firstName">First Name:</label>
</td>
<td class="accInterfaceInputCell">
<input type="text" id="firstName" name="firstName" value="@firstName" /><br/><br/>
</td>
</tr>
<tr>
<td class="accInterfaceLabelCell">
<label for="lastName">Last Name:</label>
</td>
<td class="accInterfaceInputCell">
<input type="text" id="lastName" name="lastName" value="@lastName" /><br/><br/>
</td>
</tr>
<tr>
<td class="accInterfaceLabelCell">
<label for="password">Create Password:</label>
</td>
<td>
<input type="password" id="password" name="password" /><br/><br/>
</td>
</tr>
<tr>
<td class="accInterfaceLabelCell">
<label for="confirmPassword">Confirm Password:</label>
</td>
<td>
<input type="password" id="confirmPassword" name="confirmPassword" /><br/><br/>
</td>
</tr>
</table><br/><br/>
<button type="button" class="btn" onclick="location.href='/IntroPage.cshtml'">Main Page</button><input class="btn" type="submit" value="Register" />
</form>
</div>
@RenderPage("~/Shared/FooterLayout.cshtml")
@{
var errorMessage = "";
var confirmationToken = Request["confirmationCode"];
var firstName = Request["firstName"];
WebSecurity.Logout();
if (!confirmationToken.IsEmpty())
{
if(WebSecurity.ConfirmAccount(confirmationToken))
{
AppState["gActionMessage"] = "Welcome to the POI Database, " + firstName + "!";
AppState["gActionMessageDisplayed"] = "not";
Response.Redirect("~/");
}
else
{
errorMessage = "An error occurred while trying to confirm your account. " +
"Please try again.";
}
}
}
@RenderPage("~/Shared/HeaderLayout.cshtml")
<div style="color: #808080;">
<span class="heading">Confirm Account</span>
<span style="font-size: 3em;">________________________________________________</span></br></br></br>
</div>
@if (errorMessage != "")
{
<div class="errorMessageWrapper">@errorMessage</div><br/>
}
@RenderPage("~/Shared/FooterLayout.cshtml")
: 여기
은 확인 페이지이다
그리고, 마지막으로, 로그인 페이지 :
@{
var username = "";
var user = "";
var password = "";
var errorMessage = "";
AppState["gActionMessage"] = "";
if(IsPost)
{
username = Request.Form["username"];
password = Request.Form["password"];
if(username.IsEmpty() || password.IsEmpty())
{
errorMessage = "You must specify both a username and password.";
}
else
{
if(WebSecurity.Login(username, password, false))
{
var db = Database.Open("Users");
user = db.QuerySingle("SELECT firstName FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", username);
AppState["gActionMessage"] = "Hello, " + user + "!";
AppState["gActionMessageDisplayed"] = "not";
Response.Redirect("~/");
}
else
{
errorMessage = "Login failed";
}
}
}
}
@RenderPage("~/Shared/HeaderLayout.cshtml")
<div style="color: #808080;">
<span class="heading">Please Log In</span>
<span style="font-size: 3em;">________________________________________________</span></br></br></br>
</div>
@{
if (errorMessage != "")
{
<div class="errorMessageWrapper">@errorMessage</div><br/>
}
}
<div class="accInterfaceWrapper">
<form class="accInterfaceForm" method="post" action="">
<table class="accInterfaceTable">
<tr>
<td class="accInterfaceLabelCell">
<label for="username">Email Address:</label>
</td>
<td class="accInterfaceInputCell">
<input type="text" id="username" name="username" value="@username" /><br/><br/>
</td>
</tr>
<tr>
<td class="accInterfaceLabelCell">
<label for="password">Password:</label>
</td>
<td>
<input type="password" id="password" name="password" /><br/><br/>
</td>
</tr>
</table><br/><br/>
<button type="button" class="btn" onclick="location.href='/IntroPage.cshtml'">Main Page</button><input class="btn" type="submit" value="Log In" />
</form>
<a href="~/Account/Register.cshtml">Don't have a Account?</a><br/><br/>
<a href="~/Account/ForgotPassword.cshtml">Forgot your password?</a>
</div>
@RenderPage("~/Shared/FooterLayout.cshtml")
다시, 나는 로그인을 시도하고 확인이 데이터베이스에 true로 설정되어있는, 그래서 그들이 성공적으로 등록받을 알고있을 때 실제로 발생됩니다 오류, 로그인 파일의 내용을 변경하지 않고 등록/확인 파일을 변경 한 후에 만 오류가 발생하기 시작했습니다.
많은 코드로 인해 불편을 끼쳐 드려 죄송합니다. 문제는이 세 페이지 사이에서 발생할 수 있습니다. 누구에게 더 많은 정보 나 다른 파일이 필요한지 알려주세요. 즉시 응답 해 드리겠습니다. 모든 도움을 미리 감사드립니다.
코드를 디버그 할 수 있습니까? 'username' 변수가 문자열 값으로 설정되어 있습니까? –