Use of IdentityBasicAuthenticationAttribute in MVC 4 API [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How can I add the IdentityBasicAuthenticationAttribute in my project? I have read the link below shared by the #IonutUngureanu, but some of the steps are skipped in the document.
Please check the attached screenshot for the error.
Thank You.

You could use or create a custom Authentication/Authorize filter attribute:
https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/authentication-filters

From your picture I see that you are missing the implementation of the IdentityBasicAuthenticationAttribute class. Step by step instructions:
Create a folder called Filters
In the folder Filters create a class called IdentityBasicAuthenticationAttribute :
public class IdentityBasicAuthenticationAttribute : BasicAuthenticationAttribute
{
protected override async Task<IPrincipal> AuthenticateAsync(string userName, string password, CancellationToken cancellationToken)
{
// Implement logic suitable for your case
return new ClaimsPrincipal(identity);
}
}
Register your filter:
config.Filters.Add(new IdentityBasicAuthenticationAttribute());
Full code sample here: http://aspnet.codeplex.com/sourcecontrol/latest#Samples/WebApi/BasicAuthentication/BasicAuthentication/Filters/IdentityBasicAuthenticationAttribute.cs

Related

How to write below mentioned swift code in .cs file for xamarin? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 12 months ago.
Improve this question
I am new to xamarin and swift and I am creating a demo and in that, I have to write down some iOS related code which is mentioned below in code but the code is swift and I want to add that code in my .cs file so that I can use it with my UI page and it is giving errors as mentioned in the below image. It would be great if you can guide me with this and provide me with what code should I need to write and where.
UIApplication.shared.open(redirectUrl, options: [:], completionHandler: { success in
if success {
// Handle success.
} else {
// Handle failure. Most likely app is not present on the user's device. You can redirect to App Store using these links:
}
})
This should work for you. My advise, please refer to the official documentation it's all there.
var param = new NSDictionary();
UIApplication.SharedApplication.OpenUrl(new NSUrl("https://google.com"), param, (completed) =>
{
if (completed)
{
}
else
{
}
});

How to make website readonly that link from certain websites. asp.net [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a website where a user logs in, can see his information and edit it. There is also another website, something like a site only for admins, where if I click a link it redirects me to the first website, logged in as that user but I can only read his information not edit it. I am having trouble finding out how to make website 1 both readable only and read/writeable.
I am doing this in Asp.NET mvc using C#.
One method would be to check for authorization in the Razor view.
Psuedocode:
#if(User.IsAuthorizedForEdit()
{
#*your edit view code*#
}
else
{
#*your readonly view code*#
}
This does make for some bloaty Razor. The other (arguably, better) alternative is to direct them to the appropriate view in your controller based on user.
Handy-wavy psuedocode to give you an idea:
public ActionResult ViewProfile(int profileId)
{
var user = GetCurrentUser();//without looking at your code, I can't infer this piece.
var profile = GetProfile(profileId);
if(IsAuthorizedToEdit(user, profileId)
{
return View("edit", profile);
}
else
{
return View("view", profile);
}
}
In theory, you already have a read-only view and an edit view, so the latter would be more reusable.

My custom attribute not working [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to make an attribute so that I can decorate an action/controller and have some code run.
This is the code for my Attribute:
public class UpdateLastLogInAttribute : System.Attribute
{
Linq.UserMinData umd { get; set; }
public UpdateLastLogInAttribute()
{
this.umd =datafuncs.GetMinData();
if (umd != null)
datafuncs.SaveLastConnected(umd);
}
}
...and this is the Controller that I want the Attribute to work with
[funcs.UpdateLastLogIn]
public class HomeController : Controller
{
}
However, when I hit the controller, my code never executes. What's wrong?
Attributes are dumb. There isn't any magic that makes code in attributes run. It's down to you to reflect on your code and to detect the attributes and run the code.
Fortunately, MVC already does this for specific attribute types, so...
You might consider extending ActionFilterAttribute and overriding OnActionExecuting,OnActionExecuted, OnResultExecuting or OnResultExecuted depending on which phase of the request you want to intercept.
MVC looks out for subclasses of this attribute and executes the four methods above at the appropriate time.

Interface in C# what does it mean in this context [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Was going through this code here
The code here confused me
private void sendMessage()
{
IConnectionFactory wlsConnectionFactory;
IQueue ordersQueue;
IDictionary<string, Object> environment;
IContext jndiContext;
In dot net and C# a I prefix means a Interface no ?
If the above statement is true what does this line mean for example
IQueue ordersQueue;
Would this program have worked if we had something like
Queue ordersQueue instead of IQueue ordersQueue ?
First of all, an I prefix implies an interface, but that's just a convention (albeit, a extreme widely-used convention)
IQueue ordersQueue;
means that ordersQueue can be assign any type which implements the IQueue interface.

Handling missing and null parameters in asp.net mvc [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am new to asp.net mvc.
now the requirement is that I have to handle following URLs in same ActionResult
if HTTP//jpripu/Handset/shop_code=&hosho_date= then do something.
if HTTP//jpripu/Handset/shop_code=Cust01&hosho_date=20131212 then do something
if HTTP//jpripu/Handset/hosho_date= then do something
if HTTP//jpripu/Handset/shop_code= then do something
Is it feasible to execute above conditions separately?
could anybody help me on this. Thanks.
If you mean URLs like http://jpripu/shop_code=&hosho_date=20130923
then this controller is for you:
public class HandsetController : Controller
{
public ActionResult Index(string shop_code, string hosho_date)
{
ViewBag.shop_code = shop_code;
ViewBag.hosho_date = hosho_date;
return View();
}
}
Note: Index - is default Action, defined in your routing.
Also I suggest Pluralsight Introduction to ASP.NET MVC 3 screencasts as a quick-start quide to ASP.NET MVC.

Categories