I was wondering if it is somehow possible to retrieve a certain parameter from a membership provider in the Web.config?
I've been looking around and found how to get items from appSettings but not this...
What I basically want to do is fetch the parameter allowedRoles so I can use it in my Razor. Why do I want to fetch it from the Web.config? Because the needed values are already there and doesn't have to be written / changed on multiple places.
Thanks for your reply!
I already knew about this snippet as I told in my start post. Even though this isn't exactly what I'm looking for, I've tried this snippet with a newly added line in the appSettings but it didn't seem to be able to find the newly added line.
Using the code above, it doesn't show anything, and when adding .ToString() to the Razor code it gives me an error Object reference not set to an instance of an object.
Sadly that didn't made any changes to the result I had before.
Which is kinda obvious as adding @using System.Configuration; wouldn't make any changes because I'm adding it directly in my Razor snippet that I gave.
It has probably something to do with the way I added it to the Web.config... Do I have to add it somewhere else as well?
I don't know, it works with the appSetting values that were already in Web.config but not for the one that I just added.
I even tried to give the number of the place in the appSettings like this
But that gives me an index out of bounce exception, so I assume it didn't found the needed item.
Edit: weird... somehow after reopening the project it did work this way.
Yet I would still like to being able to access the items from the membership provider to avoid duplicate values and having to change them on multiple places. Is this possible?
You can access values of the default membership provider (UmbracoMembershipProvider) via the Membership singleton that should be exposed in Razor views.
I had tried something alike earlier which didn't worked, and just tried this as well, but also didn't worked:
@{
var provider = Membership.Providers["BackofficeMembershipProvider"];
<p>@provider.allowedRoles</p>
}
Gives:
'System.Web.Security.MembershipProvider' does not contain a
definition for 'allowedRoles' and no extension method 'allowedRoles'
accepting a first argument of type
'System.Web.Security.MembershipProvider' could be found (are you
missing a using directive or an assembly reference?)
I have tried as you said, sadly still the same issue...
Might be because it's a custom property on a custom membership provider?
I feel like I have to edit the membership provider and add an override get property in the library from it?
Razor membership from web.config
Hi there
I was wondering if it is somehow possible to retrieve a certain parameter from a membership provider in the Web.config?
I've been looking around and found how to get items from appSettings but not this...
What I basically want to do is fetch the parameter allowedRoles so I can use it in my Razor. Why do I want to fetch it from the Web.config? Because the needed values are already there and doesn't have to be written / changed on multiple places.
Anyone knows if this is possible, and how
Thanks in advance!
var variable = WebConfigurationManager.AppSettings["mykey"].ToString();
var var1 =ConfigurationManager.AppSettings["TestConfig"];
Hi there,
Thanks for your reply! I already knew about this snippet as I told in my start post. Even though this isn't exactly what I'm looking for, I've tried this snippet with a newly added line in the appSettings but it didn't seem to be able to find the newly added line.
Razor:
Web.config appsetting:
Using the code above, it doesn't show anything, and when adding
.ToString()
to the Razor code it gives me an errorObject reference not set to an instance of an object.
@using System.Configuration;
Sadly that didn't made any changes to the result I had before. Which is kinda obvious as adding
@using System.Configuration;
wouldn't make any changes because I'm adding it directly in my Razor snippet that I gave.It has probably something to do with the way I added it to the Web.config... Do I have to add it somewhere else as well? I don't know, it works with the appSetting values that were already in Web.config but not for the one that I just added.
I even tried to give the number of the place in the appSettings like this
But that gives me an index out of bounce exception, so I assume it didn't found the needed item.
Edit: weird... somehow after reopening the project it did work this way.
My suggestion is to create a node in CMS let give it name "Settings" and take all things from there so it would also be easy to access and change.
So I assume it's not possible to access the membership providers part from Web.access in Razor
You can access values of the default membership provider (UmbracoMembershipProvider) via the Membership singleton that should be exposed in Razor views.
eg.
or
If you want to reference a specific provider (eg. users), then you can access it by name like this:
Sorry for my late reply.
I had tried something alike earlier which didn't worked, and just tried this as well, but also didn't worked:
Gives:
I think you must be missing a reference to the
System.Web.ApplicationServices.dll
Can you add that and try again?Some docs...
https://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.aspx
https://msdn.microsoft.com/en-us/library/wkze6zky.aspx
Thanks,
Isn't there a possibility to manually download the dll as im using Webmatrix
Sorry, I'm not sure about how you add references via WebMatrix as I don't use it. I'm sure there must be a way, though.
You can also download Visual Studio 2017 community edition for free, you know - https://www.visualstudio.com/
I have tried as you said, sadly still the same issue...
Might be because it's a custom property on a custom membership provider? I feel like I have to edit the membership provider and add an override get property in the library from it?
I managed to get it to work as followed:
Thanks alot for the help though :)
is working on a reply...