I am currently using built in Windows Authentication for my MVC3 web app.
It works as expected but I can't seem to figure out how to hide certain links on a view based on what user is logged in. I found info on using If (Roles.IsUserInRole) but that dont work as I do not know that Windows roles if any we are using. I think we are using Groups instead of roles.
Thanks
Role = group membership, so you can use it like this:
if (Roles.IsUserInRole("domain\\Administrators")) {
// do something
}
I think you can also use this solution:
if (Roles.IsUserInRole("role","username")) { //should also work, worked for me in the MVC3
// do something
}
Related
I want to fetch the current logged in username for a databasequery in C# and trying to find a C# version of the ASP "command" User.Identity.Name. When I'm googling it I only find people that's fetching the Windows username with Environment.Username and similiar solutions - which is not what I need.
So, I'm speaking of the accounts made from the ASP Configuration dialog in VS, or the auto-generated register functions. I can register/login/logout and everything, so I'm guessing there is some sort of session that's storing the info I need. I just don't know where I can find it.
I hope I'm not that confusing :) Anyone know how to fetch my session-info from a C# model?
You can get the name of the current user in MVC the same way as you can in classic ASP, with User.Identity.Name. The whole namespace is System.Web.HttpContext.Current.User.Identity.Name.
Without seeing your code I can't be sure, but I imagine you aren't including System.Web, and even if you are you may need to specify HttpContext.Current.User.Identity.Name.
You can pass Controller property "User" to your model.
something like this:
public ActionResult Index()
{
IndexModel model = new IndexModel(this.User);
}
I'm using an action filter that checks what browser version is being used on my site, if it's an older browser I put up a div at the top asking them to upgrade. I don't want web crawlers to get the div message, so I've implemented HttpBrowserCapabilitiesBase.Crawler and it looks like it works for Google, but Bing and the others don't seem to register as crawlers. Strange for a Microsoft product to not notice Bing as a crawler!
Is there some way to add user agents to the crawler property or something?
Thanks!
Edited: I'm using asp.net mvc 3, it looks like I need to user .Browser files(?). Anyone know of a comprehensive set of .Browser files out there for Bing and the rest of the crawlers?
You will probably need to update your browscap.ini file as the one shipped with IIS is probably old. You can get a new one at one of the following URLs:
http://browsers.garykeith.com/downloads.asp
http://owenbrady.net/browsercaps/
browscap.ini usually lives at: c:\windows\system32\inetsrv\browscap.ini
We're not using MVC but we do this:
Regex.IsMatch(Request.UserAgent, #"bot|crawler|baiduspider|80legs|ia_archiver|voyager|curl|wget|yahoo! slurp|mediapartners-google", RegexOptions.IgnoreCase);
More options in my answer here:
Detecting honest web crawlers
I use DotNetOpenAuth in my Asp.Net application.
I want to create a login page where user can choose among most common OpenID providers like google, yahoo...
I'd like to have image buttons like SO login.
1) Is there a best practice to achieve this? (Like a free/open asp.net control)
2) Do you have a list of common Discovery URLS?
https://www.google.com/accounts/o8/id (google)
https://me.yahoo.com (yahoo)
...
update
Just for info I've found also this:
socialauth-net
I believe this is what you're looking for: http://code.google.com/p/openid-selector/
You can check out this page which shows how to do OpenID Authentication using ASP.NET/MVC. If you are not using MVC, then check out this page (see cautionary comment below), which shows how to do it in C#/ASP.NET without any MVC.
Also check out StackApps and Stacky which help you implement some of the Stack Overflow type stuff in .NET.
Finally, if you need a list of providers/discovery list, check out this list!
I'm using facebook sdk. After the user authenticates to my application, I have his 'Likes' permission.
Can I add "like" to a product page automatically?
I'm not 100% sure on what you're asking, but here is some information which may be relevant.
Requesting a 'user_likes' permission will give you access the items a user has previously liked.
In order to programatically like something, (I believe) that entity has to exist within facebook - taken from http://developers.facebook.com/docs/reference/api/
/OBJECT_ID/likes Like the given object (if it has a /likes connection)
To do this you'll have to request the 'publish_stream' permission and then do something like:
// untested!
var app = new FacebookApp();
app.Post("OBJECT_ID/likes");
Failing that you'll have to add a like button (http://developers.facebook.com/docs/reference/plugins/like/) where the user will have to click themselves
Hope that helps :)
If I understand your question correctly, you want to add like buttons to product pages on your site. You are looking for the open graph api.
http://developers.facebook.com/docs/opengraph/
I've created a registration form control for a Sitecore site that will create a Sitecore user for registration. However, I need to implement some authorisation of the account before the user can log in with it and want to set the account to be disabled on creation.
I've been making use of the Security.Accounts.User class to achieve this so far, but can't seem to find anything in the Sitecore API that will allow me to disable the account. I know it is possible to disable accounts as the GUI contains a button to do this. Is there a way to achieve this programatically or am I looking for something that isn't there?
I'm using Sitecore 6.0 rev 090120.
a MembershipUser has an .IsApproved property (get; set;) which I gather is basically in place to solve the same issue you are addressing here.
What you are looking for is actually more of a regular ASP.NET issue than a Sitecore issue. I found this thread to be particularly helpful; http://forums.asp.net/t/1035758.aspx; and hopefully should help you along as well.
My working code:
//-- Create sitecore user
var membershipUser = Membership.CreateUser(GetDomainUsername(crmContact.AdUsername), password, crmContact.Email);
//-- then disable the user
membershipUser.IsApproved = false;
Membership.UpdateUser(membershipUser);
Based on Mark's hint.