我正在將我的sitefinity網站項目轉換爲Web應用程序。當前上下文中不存在「電子郵件」名稱(Web應用程序)
我們有一個最初在網站上工作的用戶控件,但現在我們在構建Web應用程序時出現以下錯誤。
「電子郵件」並不在當前環境中存在的名稱(線104)
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Web.Security;
using System.Net.Mail;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;
using Telerik.Sitefinity.Model;
namespace UserControls.Saville
{
public partial class CustomUserRegistration : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Url.Query.Contains("?registered"))
{
userRegistration.Visible = false;
RegSuccess.Text = "We have emailed you an account activation link. Please check your emails.";
}
}
protected void btnRegister_OnClick(object sender, EventArgs e)
{
Match emailValid = Regex.Match(tbxRegEmail.Text, @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$");
if (tbxFirstName.Text != String.Empty &&
tbxSurname.Text != String.Empty &&
tbxJobTitle.Text != String.Empty &&
tbxOrganisation.Text != String.Empty &&
tbxTelephone.Text != String.Empty &&
tbxAddressLine1.Text != String.Empty &&
tbxAddressCity.Text != String.Empty &&
tbxAddressPostcode.Text != String.Empty &&
tbxAddressCounty.Text != String.Empty &&
tbxAddressCountry.Text != String.Empty &&
tbxRegEmail.Text != String.Empty &&
tbxRegUsername.Text != String.Empty &&
tbxRegPassword.Text != String.Empty &&
tbxCPassword.Text != String.Empty &&
emailValid.Success &&
tbxRegPassword.Text.Length > 5 &&
tbxRegPassword.Text == tbxCPassword.Text)
{
var manager = UserManager.GetManager("AspNetSqlMembershipProvider");
manager.Provider.SuppressSecurityChecks = true;
if (manager.UserExists(tbxRegUsername.Text))
{
RegError.Text = "Username already in use.";
}
else
{
if (manager.EmailExists(tbxRegEmail.Text))
{
RegError.Text = "Email Address is already registered";
}
else
{
MembershipCreateStatus status;
User user = manager.CreateUser(tbxRegUsername.Text, tbxRegPassword.Text, tbxRegEmail.Text, "Question", "Answer", false, null, out status);
manager.SaveChanges();
if (status == MembershipCreateStatus.Success)
{
UserProfileManager profileManager = UserProfileManager.GetManager();
profileManager.Provider.SuppressSecurityChecks = true;
SitefinityProfile userProfile = profileManager.CreateProfile(user, Guid.NewGuid(), typeof(SitefinityProfile)) as SitefinityProfile;
if (userProfile != null)
{
userProfile.SetValue("Title", ddlTitle.SelectedItem.Text);
userProfile.FirstName = tbxFirstName.Text;
userProfile.LastName = tbxSurname.Text;
userProfile.SetValue("JobTitle", tbxJobTitle.Text);
userProfile.SetValue("Organisation", tbxOrganisation.Text);
userProfile.SetValue("MainPhone", tbxTelephone.Text);
userProfile.SetValue("MobilePhone", tbxMobileTelephone.Text);
userProfile.SetValue("Address_Street_1", tbxAddressLine1.Text);
userProfile.SetValue("Address_Street_2", tbxAddressLine2.Text);
userProfile.SetValue("Address_City", tbxAddressCity.Text);
userProfile.SetValue("Address_PostcodeZIP", tbxAddressPostcode.Text);
userProfile.SetValue("Address_CountyState", tbxAddressCounty.Text);
userProfile.SetValue("Address_Country", tbxAddressCountry.Text);
userProfile.SetValue("Registration_Code", tbxRegCode.Text);
userProfile.SetValue("SendMarketing", chkbxMaterials.Checked);
profileManager.SaveChanges();
RoleManager roleManager = RoleManager.GetManager("AspNetSqlRoleProvider");
roleManager.Provider.SuppressSecurityChecks = true;
Role untrained = roleManager.GetRole("Untrained");
roleManager.AddUserToRole(user, untrained);
roleManager.SaveChanges();
String emailContent = String.Format("{1}, <br/><br/>Your registration is nearly complete.<br/><br/>Please follow this link to activate your account:<br/><a href='{2}/login?ID={3}'>{2}/login?ID={3}</a>", Environment.NewLine, tbxFirstName.Text, Request.Url.GetLeftPart(UriPartial.Authority), user.Id.ToString());
Email.Send(tbxRegEmail.Text, "[email protected]*****.com", "*****", emailContent);
Response.Redirect("~/login?registered");
}
RegError.Text = "An error occurred whilst registering. If problem persists please contact [email protected]*****.com";
}
}
}
}
else
{
RegError.Text = "Please check all required fields have been filled and are valid.";
}
}
}
}
本來我們有項目中的不同的文件夾內的Email.cs文件,但似乎是Web應用程序無法找到此。
添加一個完全Quilified名稱的電子郵件類像Mynamespace.Email.Send(.....) – JSJ 2013-03-14 11:55:39
不幸的是,我已經嘗試過這一點,但我們只是得到同樣的錯誤,但這次是'MYnamespace'.Email。發送(... – LaurenceP 2013-03-14 12:05:07
只需確認:您是否驗證過電子郵件的名稱空間(在Email.cs中)是否正確,並且該類是公共的? – Kjartan 2013-03-14 12:26:24