MVC :: Internationalize DataAnnotations Error Messages Using A Custom Resource Provider?
Mar 18, 2010
Is there a way to use DataAnnotations for validation, particulary in MVC, while relying on a custom resource provider ?
I built a custom SQL based resource provider for the asp.net side of my MVC application. At this point I'm down in the model section and want to use DataAnnotations for validation. Something like ...
[code]....
View 5 Replies
Similar Messages:
Mar 4, 2010
I am working on a new project using ASP.NET 4 and I have a few Resource Files.However, I also have resources on a SQL database. I would like to somehow create a common resource provider.I would like to be able to use:
Resources.Labels.Email > This would take the resource Email from file Labels.
Resources.Database("Email") > This would take the resource with name "Email" from the database.When I get a resource from the database I always return the Name, Content and MimeType.To avoid multiple requests I could even have another method like:
Resources.Database(new List<String> { "Email", "Address" }) > This would take the resources with name "Email" and "Address" from the database in one request.I am not sure if this would be possible ... Basically I would need to have something like:
Resources.Database.Load(new List<String> { "Email", "Address" }); And then use: Resources.Database("Email");
And even have one more:Resources.Config("Email") > This would take the resource with name "Email" from th web.config file. Always a String.I have all the code with communication with the database and web.config.The main problem is really how to create this resource interface.
View 1 Replies
Apr 10, 2010
i created a view using html.editorformodel() and created a buddy class for validation. the buddy class is as below;
[Code]....
Now , i know that the view recognized the buddy class because the display name above showed in the create form.
The problem now is that when i click on the submit button, i dont get that error messsage, saying that LineManagerEmail is required.
It simply goes to the httppost create action (which has no logic in it for now and simply redirects to the index action.
My view is as below.
[Code]....
View 3 Replies
May 13, 2010
I was referred here by MSDN forums hope this is the right place - I have a custom control (:WebControl) that renders web.sitemap in a specific way. While it runs error free and produces the expected result, at Design-Time it complains
[Code]....
and have tried the SiteMapDataProvider Tag with and without the SiteMapProvider
attribute.Does anybody have (a) any experience with this, or (b) any suggestions as to how to track down the problem?
View 3 Replies
Jan 26, 2010
For error messages, validation faults etc you have
ModelState.AddErrorMessage("Fool!");
But, where do you put success responses like "You successfully transfered alot of money to your ex." + "Your balance is now zero". I still want to set it at the controller level and preferably in key-value way, the same way as errormessages but without invalidating the modelstate.
View 3 Replies
Jan 5, 2011
I am implementing a custom role provider in my nhibernate application I have a repository that I call whenever I want to access the nhibernate session. So when my role provider initializes itself
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) {
base.Initialize(name, config);
Repository = new Repository();
[code]...
View 1 Replies
May 12, 2010
I have created custome Membership Role and Profile provider using INGRES db. Now I can see my IngresMembership and IngresRole provider in the Provider tab(Select a different provider for each feature (advanced) ) of WSAT but when I clik on security tab I get this error:
"There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Object reference not set to an instance of an object."
What am I missing? Do I need to add code for all override methods for Role provider? I have just written code for the Initialize and GetRolesForUser functions.
View 1 Replies
Jun 3, 2010
I'm still trying to learn how all of this works, and I apologize if this is a simple fix, but I'm getting frustrated and I could use some help.
I found an XML profile provider that I'm trying to use, and when I set it up, it works fine on my local machine. However when I upload it to the server, I get an error and I don't really know what it means:
Server Error in '/' Application.
Configuration Error
Description:
An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: CustomProviders.XmlProfileProvider..ctor()
Source Error:
[Code]....
Source File: E:kundenhomepages28d241331304web.config Line:
38
The full profile section from the web.config file is:
<profile enabled="true" defaultProvider="XmlProfileProvider">
<providers>
<clear/>
<add applicationName="FamilySite" name="XmlProfileProvider" type="CustomProviders.XmlProfileProvider"/>
</providers>
<properties>
<add name="FirstName" />
<add name="LastName" />
<add name="HomeTown" />
<add name="ShowEmail" type="System.Boolean"/>
</properties>
</profile>
View 2 Replies
Jun 2, 2010
I will be setting the current thread's culture at the beginning of the request lifecycle.
Does it make sense if I create my own resource.xml to store things like strings/labels/messages that will be used in the web application?
or are their drawbacks and its better if I just use the Global resources .resx files that are 'built-in' ?
View 2 Replies
Jul 19, 2010
I use custom session state provider (appfabric). I marked my pagecontroller class with [Serializable]. When i redirect a page i get error HttpContext is not marked as serializable. I have a property in pagecontroller class;
[Code]....
Is this piece of code may be the main reason for serialization error ? I use the it nearly everywhere, so i can not simply detach and test it.
View 3 Replies
Mar 11, 2010
I've create a custom membership provider
[Code]....
and on web.cofig file
[Code]....
and I tried also
[Code]....
View 4 Replies
Jan 5, 2011
This is my first membership provider; I converted the sample provider [URL] to SQL. I created a vb class provider and put it into the App_Code folder. After it was created I tried to modify my webconfig but the error pops up. I don't know what else to try, I don't know if I have missed something
webconfig:
[code]....
View 1 Replies
Jan 11, 2010
I'm having problems with getting my custom dataannotations to work, I'm trying to add a validation-attribute that validates that the UsergroupName for a Customer (CustomerID) is unique.
[Code]....
the IsValid should return false if the "count >0". How do I fix this one so it works. GetUsergroups() returns IQueryable<Usergroup>.
View 8 Replies
Mar 8, 2010
I'm not able to set errorMessage for DataType attribute.
Here is sample code :
[DataType(DataType.Currency, ErrorMessage = "Please enter a number")]
But in the ValidationSummary it is displayed:
The value 'sdf' is not valid for StartPrice. Other attributes like Required, StringLength or Range work fine.
I had to remove validationSummary and display messages with <%= Html.ValidationMessageFor() %> nearby input fileds but it is not the solution.
View 3 Replies
Sep 27, 2010
I have watched the how to video on Creating a Custom Membership provider. So far it works great. My login control interacts well with it etc. Now i've created a Custom Role Provider. I've created a class that inherits the RoleProvider base class and i've added code to each Sub. My question is, what is the best way to implement the role provider, considering I get the Roles etc from the database?
View 11 Replies
Apr 16, 2010
I try to get the user profile settings with this code. But all items in it are empty, in the database they are not empty. So there is going something wrong. First of oll how can i add a provider to the ProfileCommon ? Maybe i'm there then... the usrInfo is filled well...
MembershipUser usrInfo = Membership.Providers["MyMembershipProvider"].GetUser(UserName,false);
ProfileCommon prf = (ProfileCommon)Profile.GetProfile(UserName);
LitNaam.Text = prf.Voorletters.ToString() + " " + prf.Achternaam.ToString();
View 2 Replies
Dec 1, 2010
i have implemented custom role provider and membership provider .
login page : SignIn.aspx
on successful login it redirects to (index-Homepage.aspx)
now PROBLEM is when it successfully logged in ,and redirects to 'index-Homepage.aspx' it gives Anornymoustemplate ..while its verifying the role correctly in index-Homepage.aspx.cs
View 1 Replies
Mar 27, 2010
i'm building an application and i need to manage roles, users and more things so i tought to use the membership provider but i have some questions about it: can i full extend it and can i override the functions to use a database table to store infos about config or i need to build my own provider?
View 4 Replies
Dec 16, 2010
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
<properties>
<add name="FirstName"/>
<add name="LastName"/>
</properties>
</profile>
I have the code snippet above in my webconfig file. I am attempting to set the FirstName property in codebehind on a register.aspx page. Like this:
Profile.FirstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;
VS says Profile is in System.Web.Profile Namespace. I then use it like this "System.Web.Profile.FirstName", but says first name does not exist in System.Web.Profile.FirstName namespace.
How do I set the property and later retrieve it?
View 3 Replies
Feb 17, 2010
I have a problem with server-side validation in xVal. I'm using the RequiredAttribute from DataAnnotations.
I would like to change error message from:
The field is required.
to:
Polje je obvezno.
My current solution is this: [Required(ErrorMessage = "Polje je obvezno.")]
But I was wondering if it's possible just to write [Required] and to override error message in one place? (like there is a localization file for client-side validation in xVal)
View 2 Replies
Oct 13, 2010
I create custom principal for implement logic for users. In identity I store Id, Name. But it abnormally - this classes must use for authenticate and authorize.
I can implement custom MembershipUser, custom Roles and Membership provider.
How to do it? What best practices are?
View 5 Replies
Apr 21, 2010
I have created my own custom role provider class "SGI_RoleProvider" and configured properly.
Everything is working fine.
Suppose that I have added a public method say "SayHello()", then how can i call that. Because if i am using Roles then the method is not displayed. If i am forcefully using that Roles.SayHello() then compiler gives the error.
how can i call this. Because creating a new instance of SGI_RoleProvider is meaningless.
View 1 Replies
Mar 21, 2010
I'm new to ASP.NET and I don't exactly understand some features.
I have a custom membership provider TestMembershipProvider which inherits from MembershipProvider. It has the following CreateUser method:
[Code]....
It's absolutely simple code.Then I have two text boxes (login, password) and the button to register a new user. I thas a following code:
[Code]....
[Code]....
Authentication in web.config is set like this:
[Code]....
No matter what I write into textboxes, following error is being returned:
The password retrieval question provided is invalid.
I don't know why. Either in web.config or in get RequiresQuestionAndAnswer I have false value. When I instantiate my TestMembershipProvider and call CreateUser directly instead of using static Membership.CreateUser, it works fine. Do I have to use instance of my TestMembershipProvider or did I missed anything?
View 1 Replies
Apr 16, 2010
I have created my custom MembershipProvider. I have used an instance of the class DBConnect within this provider to handle database functions. Please look at the code below:
public class SGIMembershipProvider : MembershipProvider
{
#region "[ Property Variables ]"
private int newPasswordLength = 8;
private string connectionString;
private string applicationName;
private bool enablePasswordReset;
private bool enablePasswordRetrieval;
private bool requiresQuestionAndAnswer;
private bool requiresUniqueEmail;
private int maxInvalidPasswordAttempts;
private int passwordAttemptWindow;
private MembershipPasswordFormat passwordFormat;
private int minRequiredNonAlphanumericCharacters;
private int minRequiredPasswordLength;
private string passwordStrengthRegularExpression;
private MachineKeySection machineKey;
**private DBConnect dbConn;**
#endregion
.......
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
if (!ValidateUser(username, oldPassword))
return false;
ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, true);
OnValidatingPassword(args);
if (args.Cancel)
{
if (args.FailureInformation != null)
{
throw args.FailureInformation;
}
else
{
throw new Exception("Change password canceled due to new password validation failure.");
}
}
SqlParameter[] p = new SqlParameter[3];
p[0] = new SqlParameter("@applicationName", applicationName);
p[1] = new SqlParameter("@username", username);
p[2] = new SqlParameter("@password", EncodePassword(newPassword));
bool retval = **dbConn.ExecuteSP("User_ChangePassword", p);**
return retval;
} //ChangePassword
public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
{
throw new ArgumentNullException("config");
}
......
ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
if ((ConnectionStringSettings == null) || (ConnectionStringSettings.ConnectionString.Trim() == String.Empty))
{
throw new ProviderException("Connection string cannot be blank.");
}
connectionString = ConnectionStringSettings.ConnectionString;
**dbConn = new DBConnect(connectionString);
dbConn.ConnectToDB();**
......
} //Initialize
......
} // SGIMembershipProvider
I have instantiated dbConn object within Initialize() event. My problem is that how could i dispose off this object when object of SGIMembershipProvider is disposed off. I know the GC will do this all for me, but I need to explicitly dispose off that object. Even I tried to override Finalize() but there is no such overridable method. I have also tried to create destructor for SGIMembershipProvider.
View 2 Replies
Feb 7, 2011
I was made a custom membership provider.
All works good. My problem is Logs.
[Code]....
[Code]....
I dont know how to get user's ip.
I tried these methods...
Dim req as httprequest
ip = req.servervariables("remote_host") 'result = nothing
Dim req as new httprequest
ip = req.servervariables("remote_host") 'result = nothing
Dim req as requestcontext
ip = req.request.servervariables("remote_host") 'result = nothing...
View 2 Replies