小编Lea*_*res的帖子

MVC - 混合身份验证 - OWIN + Windows身份验证

我需要同时具有Windows身份验证和owin(表单)身份验证,但我无法让它工作.

可能最好的选择是让两个站点具有不同的身份验证方法.

我找到了一个能满足我需求的项目:MVC5-MixedAuth.但它使用IISExpress,我无法让它与本地IIS一起使用.

发生的错误是:

在Web服务器上配置请求筛选以拒绝请求,因为查询字符串太长.

如果我删除Startup.Auth.cs中的所有ConfigureAuth()方法,它不会抛出错误,但我无法登录,因为它需要进行CookieAuthentication.

Startup.Auth.cs:

public void ConfigureAuth(IAppBuilder app)
{
    app.CreatePerOwinContext(dbEmployeePortal.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login"),
        Provider = new CookieAuthenticationProvider
        {
            OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, UserMaster, int>
            (
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
                    getUserIdCallback: (id) => (Int32.Parse(id.GetUserId()))
            )
        }
    });

    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
    app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
    app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
}
Run Code Online (Sandbox Code Playgroud)

任何的想法?

更新1

错误

在Web服务器上配置请求筛选以拒绝请求,因为查询字符串太长.

出现是因为在尝试访问登录页面时发生登录循环.

c# asp.net-mvc windows-authentication owin asp.net-mvc-5

21
推荐指数
1
解决办法
2万
查看次数

OpenXML 动态创建“表/数据透视表”

我正在创建一个在内存上生成 Excel 的示例程序。\n该程序已经生成了 Excel,但是我无法让该表工作...

\n\n

程序:

\n\n
public class Program\n{\n    static void Main(string[] args)\n    {\n        CreateCurrentAccount();\n    }\n\n    static void CreateCurrentAccount()\n    {\n        byte[] _buffer = ExcelGenerator.CurrentAccount.GetExcel();\n        File.WriteAllBytes("CurrentAccount.xlsx", _buffer);\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

Excel生成器类:

\n\n
public class ExcelGenerator\n{\n    static uint? _generalStyle = 0;\n    static uint? _dateStyle = 1;\n    static uint? _currencyStyle = 2;\n    static uint? _percentageStyle = 3;\n    static int maxStyleSheetName = 31;\n\n    public static class CurrentAccount\n    {\n        static uint? _headerStyle = 4;\n        static uint? _tableHeaderStyle = 5;\n        static uint? _totalHeaderStyle = 6;\n\n        public …
Run Code Online (Sandbox Code Playgroud)

.net c# excel openxml openxml-sdk

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

MVC 5 - 角色 - IsUserInRole和添加用户角色

在MVC4中,我使用Roles.IsUserInRole来检查给定用户是否处于某个角色.但是,使用MVC5我不能再这样做了......

起初,它要求我在web.config上启用RoleManager,但后来我发现microsoft从Web.Security转移到了Microsoft.AspNet.Identity.

我现在的问题是,使用Microsoft.AspNet.Identity如何执行类似于Roles.IsUserInRole的操作?和/或在角色和用户之间创建关系.

顺便说一下,我还在尝试理解新的身份验证方法(ClaimsIdentity?).

c# claims-based-identity asp.net-roles asp.net-mvc-5

5
推荐指数
2
解决办法
9420
查看次数

Webpack ES6-通过动态导入加载Json(保留json文件)

我正在尝试将json文件(2个文件)拆分为多个单独的块。我能够做到,但是有一个“骗局”。

这些json .js通过webpack 转换为,这就是为什么我file-loader.json文件中添加了,但await import现在返回的是字符串而不是json。

Webpack规则

module: {
    rules: [
        { test: /\.scss$/, use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader", "sass-loader",] },
        { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff&name=fonts/[name].[ext]" },
        { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff2&name=fonts/[name].[ext]" },
        { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/octet-stream&name=fonts/[name].[ext]" },
        { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=application/vnd.ms-fontobject&name=fonts/[name].[ext]" },
        { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url-loader?limit=10000&mimetype=image/svg+xml&name=fonts/[name].[ext]" },
        {
            test: /\.(js|jsx)$/,
            // Skip any files outside of project's `src` directory
            include: [
                path.resolve(__dirname, "../src"),
            ],
            loaders: ["babel-loader"],
        },
        {
            test: /\.json$/,
            type: …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6 reactjs webpack webpack-file-loader

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

WebApi2 - 没有 OWIN 身份验证管理器与请求相关联

我正在构建一个带有不记名令牌身份验证的 Web API 2 项目。

对 access_token 的请求有效,但我的其他方法无效。API 返回以下内容:

没有 OWIN 身份验证管理器与请求相关联

完整响应消息

{  
   "Message":"An error has occurred.",
   "ExceptionMessage":"No OWIN authentication manager is associated with the request.",
   "ExceptionType":"System.InvalidOperationException",
   "StackTrace":"   at System.Web.Http.Owin.PassiveAuthenticationMessageHandler.SuppressDefaultAuthenticationChallenges(HttpRequestMessage request)\r\n   at System.Web.Http.Owin.PassiveAuthenticationMessageHandler.<SendAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()"
}
Run Code Online (Sandbox Code Playgroud)

启动文件

public partial class Startup
{
    public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
    static string PublicClientKey = "XXX";

    public void ConfigureAuth(IAppBuilder app)
    { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net owin asp.net-web-api2

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

MVC RazorGenerator-“类型(...)已经定义了具有相同参数类型的名为'Execute'的成员”

我一直在研究大型MVC应用程序,现在我需要提高应用程序的启动性能(对于第一次加载,这是+1分钟的错误)。

我也安装了RazorGenerator块和扩展名,但是当我编译时会出现很多错误。

VS错误

这可能是由于未指定发电机类型引起的吗?因为我没有发现他们的文档对此很有帮助。

或可能是因为我将以下指令添加到了其中一个视图(_EditHelperPage.cshtml),因为它呈现为HelperPage而不是WebViewPage

@* Generator: MvcView *@
Run Code Online (Sandbox Code Playgroud)

在我删除此行并将其添加到后razorgenerator.directives,它引发了另一个错误:

辅助页面错误

编辑

如果我搜索同名的类/构造函数,它将在以下位置找到结果 /obj/CodeGen/(...)

asp.net-mvc razor razorgenerator precompiled-views

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