小编Xam*_*Dev的帖子

使用IClientModelValidator进行验证

在以前的版本(RC1)中,我已使用该界面IClientModelValidator来验证/比较密码和使用' ModelClientValidationEqualToRule'类确认密码,如下所示

public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ClientModelValidationContext context)
    {
        String strMsg = AccessLocalization.GetString(_resourceID);

        var modelClientValidationEqualToRule = new ModelClientValidationEqualToRule(strMsg, _OtherPropertyName);

        yield return modelClientValidationEqualToRule;
    }
Run Code Online (Sandbox Code Playgroud)

并在jQuery中

  $.validator.addMethod("equalto",
   function (value, element, parameters) {
       return value;

   });

    $.validator.unobtrusive.adapters.add('equalto', [], function (options) {

        options.rules.equalto = {};
        options.messages['equalto'] = options.message;
    });
Run Code Online (Sandbox Code Playgroud)

但是,现在我正在使用.Net Core 1.0,该接口已完全更改,并且没有ModelClientValidationEqualToRule可用的' '类。

阅读文档后,我知道验证将在数据属性的帮助下完成。因此,到目前为止,我已经实现了必填字段属性,范围字段属性,电子邮件地址属性等。

但是,我不清楚如何验证密码和确认密码?

任何对此的帮助表示赞赏!

jquery asp.net-core-mvc asp.net-core asp.net-core-1.0

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

在mvc中使用IViewLocationExpander

我想从自定义位置渲染视图,所以为此我IViewLocationExpander在类中实现了 接口.我已startup file按如下方式注册了同一课程.

Startup.cs文件

 public void ConfigureServices(IServiceCollection services)
    {
       .....
        //Render view from custom location.
        services.Configure<RazorViewEngineOptions>(options =>
        {
            options.ViewLocationExpanders.Add(new CustomViewLocationExpander());
        });
        ....
    }
Run Code Online (Sandbox Code Playgroud)

CustomViewLocationExpander类

public class CustomViewLocationExpander : IViewLocationExpander
{
    public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
    {

        var session = context.ActionContext.HttpContext.RequestServices.GetRequiredService<SessionServices>();
        string folderName = session.GetSession<string>("ApplicationType");

        viewLocations = viewLocations.Select(f => f.Replace("/Views/", "/" + folderName + "/"));


        return viewLocations;
    }

    public void PopulateValues(ViewLocationExpanderContext context)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

我的应用程序视图结构如下

在此输入图像描述

我的问题是,如果我ViewsFrontend从URL http:// localhost:56739/trainee/Login/myclientname访问文件夹中 的Views/Login视图,并立即将浏览器中的url更改为http:// localhost:56739/admin/Login/myclientname,那么在这种情况下它仍然引用 …

c# asp.net-mvc asp.net-core-mvc asp.net-core-1.0

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

如何在mvc中获取虚拟目录

我正在开发一个 .net 核心应用程序,我需要虚拟目录的应用程序路径。我不想要物理路径,我想要它的 url 形式,如:

http://www.mywebsite.com/mydirectory
Run Code Online (Sandbox Code Playgroud)

我试过,Request.Host但它只给我 http://www.mywebsite.com没有虚拟目录路径。

对此的任何帮助表示赞赏!

virtual-directory asp.net-core-mvc asp.net-core

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

在 asp.net core 中插入/更新记录时出错

当我尝试插入/更新记录时,出现以下错误。

无法跟踪实体类型的实例,因为已跟踪另一个具有相同 {'Id'} 键值的实例。

下面是我的代码。在这里,我通过以 1 递增的方式创建/生成 ID(主键)。我在保存和更新时都遇到错误

public bool SaveDataCapDetails(List<TDataCapDetails> lstDataCapDetails)
        {
            bool IsSuccess = false;

            using (var dbContextTransaction = _objContext.Database.BeginTransaction())
            {
                try
                {

                    List<TDataCapDetails> lstDataCapDetailsRecords = null;

                    if (lstDataCapDetails.Where(x => x.Id == 0).Count() > 0)
                    {
                        lstDataCapDetailsRecords = new List<TDataCapDetails>();
                        lstDataCapDetailsRecords.InsertRange(0, lstDataCapDetails);

                        int? id = _objContext.TDataCapDetails.Max(x => (int?)x.Id);
                        id = id == null ? 0 : id;
                        foreach (var item in lstDataCapDetailsRecords.Where(x => x.Id == 0))
                        {
                            id = id + 1;
                            item.Id = (int)id;
                        }
                        _objContext.Entry(lstDataCapDetailsRecords).State = …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework asp.net-core

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

Web API错误-此请求已被阻止;内容必须通过HTTPS提供

我们已经在Azure上部署了api,并试图在用angular 5编写的Web应用程序中使用该API。但是,当我们尝试使用该API时,会遇到以下错误。

Chrome混合内容:“ https://somedevapp.azurewebsites.net/#/managesomething ”上的页面已通过HTTPS加载,但请求了不安全的XMLHttpRequest端点' http://admindevapp.azurewebsites.net/api/data/getdata ' 。该请求已被阻止;内容必须通过HTTPS提供。

Firefox阻止加载混合的活动内容

这个问题与CORS有关吗?如何解决这个问题?

任何帮助对此表示赞赏!

azure asp.net-web-api mixed-content angular5

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

选择查询以获取数据库对象

我有数据库,其中包含大量的表,存储过程.那么,我如何在特定数据库的单个查询中获取表,存储过程等特定对象.

sql-server-2008

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

使用资源所有者密码在身份服务器中获取声明

我使用身份服务器 4 进行身份验证,使用授权类型为“ResourceOwnerPassword”。我能够对用户进行身份验证,但无法获得与用户相关的声明。那么我怎样才能得到那些呢?

下面是我的代码

客户

启动文件

app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority = "http://localhost:5000",
                RequireHttpsMetadata = false,
                ApiName = "api1"
            });
Run Code Online (Sandbox Code Playgroud)

控制器

public async Task<IActionResult> Authentication(LoginViewModel model)
        {
            var disco = await DiscoveryClient.GetAsync("http://localhost:5000");

            // request token
            var tokenClient = new TokenClient(disco.TokenEndpoint, "ro.client", "secret");
            var tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync(model.Email, model.Password, "api1");

            if (tokenResponse.IsError)
            {
                Console.WriteLine(tokenResponse.Error);
            }
// Here I am not getting the claims, it is coming Forbidden
            var extraClaims = new UserInfoClient(disco.UserInfoEndpoint);
            var identityClaims = await extraClaims.GetAsync(tokenResponse.AccessToken);
            if (!tokenResponse.IsError)
            {
                Console.WriteLine(identityClaims.Json);
            } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc asp.net-core identityserver4

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

DocumentDB 查询以查找创建日期

我想检索只有 documentID 和文档创建日期时间详细信息的文档。我可以通过以下查询获取 DocumentID,但我们如何获取文档创建日期时间。

select c.id from c
Run Code Online (Sandbox Code Playgroud)

但是,除了 id,我还需要获取文档创建日期

对此的任何帮助表示赞赏!

c# azure-cosmosdb

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

在c#中使用epplus读取受密码保护的excel

我正在使用 epplus 库下载带有密码的 Excel 文件。下载部分工作正常。

public ActionResult DownloadExcel()
{

string sFileName = string.Empty;

using (ExcelPackage package = projectBL.DownloadExcel(ID, id1, id3, id4, id5))
   {
     System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
        {
            FileName = package.File.Name,
        };

        Response.Headers.Add("Content-Disposition", cd.ToString());

        return File(package.GetAsByteArray("password"), "application/vndopenxmlformats-officedocument.spreadsheetml.sheet");

    }
}
Run Code Online (Sandbox Code Playgroud)

但每当我尝试上传此受密码保护的文件时,都会出现以下错误

该文件不是有效的包文件。如果文件已加密,请在构造函数中提供密码。

因此,我通过提供读取文件所需的密码解决了上述错误。下面是相同的代码。

public ActionResult UploadExcel()
{
  if (Request.Form.Files != null && Request.Form.Files.Count > 0)
   {
     var fileObject = Request.Form.Files[0];

     string fileName = ContentDispositionHeaderValue.Parse(fileObject.ContentDisposition).FileName.Trim('"');

     var Stream = fileObject.OpenReadStream();

     ExcelPackage package = new ExcelPackage(Stream,"password");

     projectBL.SaveData(package);

     return Json("Records Saved Succesfully.");
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# epplus asp.net-web-api asp.net-core-webapi

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