小编moh*_*her的帖子

基于没有键定义 mvc5 的类

我尝试从这个控制器添加视图。我只需要这个视图来显示不用于插入、更新或删除的数据

public ActionResult Index()
{
    var CartObj = ShoppingCart.GetCart(this.HttpContext);

    var classshop = new New
    {
        CartItems = CartObj.GetCartItems(),
        CartTotal = CartObj.GetSum()
    };

    return View(classshop);
}

namespace MusicStore.Models
{
    public class ShoppingCart
    {
        MusicStoreEntities dbo = new MusicStoreEntities();
        string ShoppingCartID { get; set; }

        public const string CartSessionKey = "CartId";
        public static ShoppingCart GetCart(HttpContextBase Context)
        {
            var cart = new ShoppingCart();
            cart.ShoppingCartID = cart.GetCardId(Context);
            return cart;
        }
        public static ShoppingCart GetCart(Controller controller)
        {
            return GetCart(controller.HttpContext);
        }

        public  List<Cart> GetCartItems()
        {
            return …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-5

5
推荐指数
1
解决办法
4262
查看次数

DropZone 在 init 中替换图像

我使用此代码从 init 中的数据库上传图像。现在我想在上传新图像时删除这个初始图像。

 var o = $("div#uploader").dropzone({
            url: "../../Merchant/UploadLogo",
            paramName: "logo",
            maxFiles: 1,

            //enqueueForUpload: false,
            maxfilesexceeded: function (file) {
                this.removeAllFiles();
                this.addFile(file);
            },

            addRemoveLinks: true,
            uploadMultiple: false,
            dictRemoveFile: "???",

            removedfile: function(file) {
                RemoveFile("Logo");
                var _ref;
                return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
            },

            init: function() {

                var mockFile = { name: "avatar1.jpg", size: 12345, type: 'image/jpeg', url: "../../Merchant/GetLogo" };
                this.options.addedfile.call(this, mockFile);
                this.options.thumbnail.call(this, mockFile, mockFile.url);//uploadsfolder is the folder where you have all those uploaded files
            }

        });
Run Code Online (Sandbox Code Playgroud)

javascript jquery dropzone.js

4
推荐指数
1
解决办法
4559
查看次数

当令牌过期或令牌未传递时,出现 404 错误而不是 401 Asp.net core 2

我创建了 Asp.net-core 2 项目并添加

  1. 由 Bearer 令牌授权的 api 控制器。
  2. 由 CookieAuthenticationDefaults.AuthenticationScheme 授权的 mvc 控制器。
  3. 没有app.UseIdentity(); 在配置功能中

当我尝试调用iisexpress中发布的api时,它会返回401未经授权。

当我尝试调用iis中发布的api时,它会返回404未找到。

当令牌过期或令牌未传递时,我收到 404 错误而不是 401

和我的创业公司

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApiContext>();
        //options =>
        //    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
        services.AddTransient<ApiContextSeed>();
        //a confirmed email.
        services.AddIdentity<ApplicationUser, IdentityRole>(config =>
        {
            config.SignIn.RequireConfirmedEmail = true;
            config.Password.RequireDigit = false;
            config.Password.RequireLowercase = false;
            config.Password.RequireNonAlphanumeric = false;
            config.Password.RequireUppercase = false;
            config.Password.RequiredUniqueChars =0;
            config.Password.RequiredLength = 6;
            config.User.AllowedUserNameCharacters = null;

        })
            .AddEntityFrameworkStores<ApiContext>()
            .AddDefaultTokenProviders();

        // Add application services.
        services.AddTransient<IEmailSender, EmailSender>();
        services.AddMvc().AddSessionStateTempDataProvider();
        services.AddResponseCaching();
        services.AddAutoMapper();
        services.AddSingleton<IEmailSender, EmailSender>();
        services.AddSingleton<IWizIQSender, WizIQSender>(); …
Run Code Online (Sandbox Code Playgroud)

api bearer-token asp.net-core asp.net-core-2.0

3
推荐指数
1
解决办法
1822
查看次数

为asp.net-core 2中的每个角色实现不同的登录页面

我想根据每个用户在 asp net core 中的角色实现不同的登录页面。我可以设置登录路径,但它对于任何角色都是静态的。

   services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(options =>
        {
            options.LoginPath = "Account/Login/";
            options.AccessDeniedPath = "Account/Forbidden/";
        }); 
Run Code Online (Sandbox Code Playgroud)

因此,当我调用授权(role =“Admin”)的操作时,重定向到管理员登录页面。当调用 Authorize(role="User") 重定向到用户登录页面的操作时

httpcookie asp.net-core asp.net-core-2.0

0
推荐指数
1
解决办法
2893
查看次数