Base solution for your next web application

Activities of "bbakermmc"

Never mind, looks like it was tied to me installing ELMAH.

If I set this key to "True" ABP errors come back just fine now. <add key="elmah.mvc.disableHandleErrorFilter" value="true" />

Question

Whats the best way to implement some custom user claims?

Im thinking I can create a new call in the Users AppService

public async Task CustomClaim(ProhibitPermissionInput input)
        {
            var user = await UserManager.GetUserByIdAsync(input.UserId);
            //var permission = _permissionManager.GetPermission(input.PermissionName);

            await UserManager.AddClaimAsync(input.UserId, new Claim("AllowedClients", "1,2,3"));

            //await UserManager.ProhibitPermissionAsync(user, permission);
        }

And then I think I need to modify something else to pull them out when they login correct?

Answer

UserAppService

public async Task CustomClaim(CustomClaimInput input)
        {
            await UserManager.AddClaimAsync(input.UserId, new Claim(input.ClaimName, input.ClaimValue));
        }

AccountController:

private async Task SignInAsync(User user, ClaimsIdentity identity = null, bool rememberMe = false)
        {
            if (identity == null)
            {
                identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
            }
            var claims = await _userManager.GetClaimsAsync(user.Id);

            foreach (var claim in claims)
            {
                identity.AddClaim(new Claim(claim.Type, claim.Value));
            }

            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = rememberMe }, identity);
        }

UsersLoginDTO

ADD
public ICollection<UserClaim> Claims { get; set; }

I keep getting the error of "The operation is not valid for the state of the transaction" when I try to call another method from one of our internal APIs. So the internal API has its own context and makes calls to the DB but it seems ABP is preventing them? I tried with the UOW Disabled and isTransact = false and still no luck. What am I doing wrong?

Controller:

try
            {
                var test = _apiAppService.GetLists(147);
                //using (var api = DmpApi.GetApiInstance(147))
                //{
                //    var test = api.GetDataAugmentationLists();
                //}
            }
            catch (Exception ex)
            {
                var error = ex;
            }

Service:

public class APIAppService : PlatformAppServiceBase, IAPIAppService
    {
        [UnitOfWork(IsDisabled = true)] 
        public List<DAList> GetLists(int clientId)
        {
            var data = new List<DAList>();
                using (var api = DmpApi.GetApiInstance(clientId))
                {
                    data = api.GetDataAugmentationLists();
                }

            return data;
        }
    }

Nevermind, I had to wrap my controller action with the attribute and it was fixed.

An exception of type 'Abp.UI.UserFriendlyException' occurred in Platform.Web.dll but was not handled in user code

Additional information: Ooppps! There is a problem!

Debug tries to open "UnitOfWorkInterceptor.cs"

Website then tells me I have a runtime error and to disable "Custom Errors" to see the message.

public ActionResult Index()
        {
            throw new UserFriendlyException("Ooppps! There is a problem!", "You are trying to see a product that is deleted...");
            return View();
        }

My bad, forgot to inherit the correct controller base :?

Question

In my code I'm calling a apb.notify and its throwing an error. Its related to toastr it looks like

.done(function(data) {
                abp.notify.success('Address Verification Reset!', 'test');
                grid.dataSource.read();
            });

Its trying to do this:

http://localhost:30001/Content/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADsSURBVEhLY2AYBfQMgf/3P8+/evAIgvA/FsIF+BavYDDWMBGroaSMMBiE8VC7AZDrIFaMFnii3AZTjUgsUUWUDA8OdAH6iQbQEhw4HyGsPEcKBXBIC4ARhex4G4BsjmweU1soIFaGg/WtoFZRIZdEvIMhxkCCjXIVsATV6gFGACs4Rsw0EGgIIH3QJYJgHSARQZDrWAB+jawzgs+Q2UO49D7jnRSRGoEFRILcdmEMWGI0cm0JJ2QpYA1RDvcmzJEWhABhD/pqrL0S0CWuABKgnRki9lLseS7g2AlqwHWQSKH4oKLrILpRGhEQCw2LiRUIa4lwAAAABJRU5ErkJggg==

I'm assuming its trying to load an image that goes with the message? Since I don't see a "Check" on the success, just a green message box.

It tells me: The length of the URL for this request exceeds the configured maxUrlLength value.

Answer
bundles.Add(
                new StyleBundle("~/Bundles/vendor/css")
                    //.Include("~/Content/themes/base/all.css", new CssRewriteUrlTransform())
                    .Include("~/Content/themes/bootstrap-simplex.css", new CssRewriteUrlTransform())
                    .Include("~/Content/toastr.min.css")
                    .Include("~/Scripts/sweetalert/sweet-alert.css", new CssRewriteUrlTransform())
                    .Include("~/Content/flags/famfamfam-flags.css", new CssRewriteUrlTransform())
                    .Include("~/Content/font-awesome.min.css", new CssRewriteUrlTransform())
                );

Had to remove the CssRewriteUrlTransform() and then it worked..

If I turn of WSFederation the registration page will work. This error is occurring when it I press "Register" but its not making it to the action in the controller.

[ArgumentNullException: Value cannot be null.
Parameter name: parameter]
   Microsoft.IdentityModel.Protocols.AuthenticationProtocolMessage.SetParameter(String parameter, String value) +103
   Microsoft.IdentityModel.Protocols.WsFederationMessage..ctor(IEnumerable`1 parameters) +217
   Microsoft.Owin.Security.WsFederation.&lt;AuthenticateCoreAsync&gt;d__1f.MoveNext() +1589
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +28
public void Configuration(IAppBuilder app)
        {
            app.UseAbp();

            app.UseOAuthBearerAuthentication(AccountController.OAuthBearerOptions);

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            if (IsTrue("ExternalAuth.Facebook.IsEnabled"))
            {
                app.UseFacebookAuthentication(CreateFacebookAuthOptions());
            }

            if (IsTrue("ExternalAuth.Twitter.IsEnabled"))
            {
                app.UseTwitterAuthentication(CreateTwitterAuthOptions());
            }

            if (IsTrue("ExternalAuth.Google.IsEnabled"))
            {
                app.UseGoogleAuthentication(CreateGoogleAuthOptions());
            }

            if (IsTrue("ExternalAuth.MMCFederation.IsEnabled"))
            {
                app.UseWsFederationAuthentication(CreateWsFederationAuthOptions());
            }

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });

            app.MapSignalR();

            //ENABLE TO USE HANGFIRE dashboard (Requires enabling Hangfire in PlatformWebModule)
            //app.UseHangfireDashboard("/hangfire", new DashboardOptions
            //{
            //    Authorization = new[] { new AbpHangfireAuthorizationFilter() } //You can remove this line to disable authorization
            //});
        }

        private static WsFederationAuthenticationOptions CreateWsFederationAuthOptions()
        {
            var websiteAddress = ConfigurationManager.AppSettings["MMCFederation.Address"];

            var wtrealm = ConfigurationManager.AppSettings["MMCFederation.Address"];
            var metaDataAddress = "https://fs.mmcweb.com/FederationMetadata/2007-06/FederationMetadata.xml";

            return new WsFederationAuthenticationOptions
            {
                Wtrealm = wtrealm,
                MetadataAddress = metaDataAddress,
                AuthenticationType = "Windows",
                Notifications = new WsFederationAuthenticationNotifications
                {
                    RedirectToIdentityProvider = notification =>
                    {
                        if (notification.ProtocolMessage.IsSignOutMessage)
                        {
                            notification.HandleResponse();
                        }

                        notification.ProtocolMessage.Wreply = websiteAddress.EnsureEndsWith('/') + "Account/ExternalLoginCallback";

                        return Task.FromResult(0);
                    },
                    SecurityTokenValidated = notification =>
                    {
                        var name = notification.AuthenticationTicket.Identity.Name;
                        notification.AuthenticationTicket.Identity.AddClaim(new Claim(ClaimTypes.Name, name));
                        return Task.FromResult(0);
                    }
                }
            };
        }
Showing 11 to 20 of 164 entries