推荐文章

ASP.NET Core中使用百度在线编辑器UEditor

ASP.NET Core中使用百度在线编辑器UEditor

ASP.NET Core中使用百度在线编辑器UEditor
.net core添加Area区域

.net core添加Area区域

Asp. Ce使用Area区域,可以有效的对业务进行隔离,各种业务及分工可以更灵活。在Asp. Ce中启用区域也是极简单的,比如:一个网站有前端、用户后台、管理,我们使用Area就能清晰划分每个功能板块前端:使用用默认的路由用户:使用“Users”路由管理:使用“Admin”路由1、在“Startup.cs”,添加Area路由public void Configure(IApplicationBu
ASP.NET CORE对url参数的编码

ASP.NET CORE对url参数的编码

用URL传参数的时候,用&符号连接,如果某一个参数中含"#$ ^ & + ="这些符号的时候,在另一个页面就会取不到传过来的参数。解决办法:ASP. CE:编码var url="http:www.baidu.com&text=" + Uri.EscapeDataString("(&^%$#@!!")输出:http:www.baidu.com&text=%28%2A%26%5E%25%24%23
ASP.NET Core 2.0使用NLog日志配置

ASP.NET Core 2.0使用NLog日志配置

一、新建ASP. Ce 2.0 MVC项目,使用NuGet在浏览中搜索:NLog.Web.AspCe,如下图所示:二、在项目下新建一个xml类型的nlog.config文件《?xml version="1.0" encoding="utf8"?》《nlog xmlns="http:www.nlogproject.gschemasNLog.xsd" xmlns:xsi="http:www.
asp.net core使用IHttpContextAccessor获取来源页

asp.net core使用IHttpContextAccessor获取来源页

1、在Startup文件注入IHttpContextAccesspublic void ConfigureServices(IServiceCollection services) { ... 注入HttpContextAccess services.AddSingleton《IHttpContex

asp.net core使用IHttpContextAccessor获取来源页

日期:2018-07-07 点击:3323 来源:PB2.CN

1、在Startup文件注入IHttpContextAccessor

public void ConfigureServices(IServiceCollection services)
        {          
            ...
            //注入HttpContextAccessor
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            //注入HttpContextAccessor END
            ...
        }


2、在Controller里使用

private IHttpContextAccessor _accessor;
public HomeController(IHttpContextAccessor accessor)
{
     _accessor = accessor;
}
public IActionResult Index()
{                
    var httpcontext = _accessor.HttpContext;
    var headersDictionary = httpcontext.Request.Headers;
    var urlReferrer = headersDictionary[HeaderNames.Referer].ToString();//来源页
    var path=httpcontext.Request.Path ; //当前访问的路径 
           
    return View();            
}



这篇文档对您是否有帮助?

ASP.NET Core中使用百度在线编辑器UEditor

ASP.NET Core中使用百度在线编辑器UEditor

ASP.NET Core中使用百度在线编辑器UEditor
.net core添加Area区域

.net core添加Area区域

Asp. Ce使用Area区域,可以有效的对业务进行隔离,各种业务及分工可以更灵活。在Asp. Ce中启用区域也是极简单的,比如:一个网站有前端、用户后台、管理,我们使用Area就能清晰划分每个功能板块前端:使用用默认的路由用户:使用“Users”路由管理:使用“Admin”路由1、在“Startup.cs”,添加Area路由public void Configure(IApplicationBu
ASP.NET CORE对url参数的编码

ASP.NET CORE对url参数的编码

用URL传参数的时候,用&符号连接,如果某一个参数中含"#$ ^ & + ="这些符号的时候,在另一个页面就会取不到传过来的参数。解决办法:ASP. CE:编码var url="http:www.baidu.com&text=" + Uri.EscapeDataString("(&^%$#@!!")输出:http:www.baidu.com&text=%28%2A%26%5E%25%24%23
ASP.NET Core 2.0使用NLog日志配置

ASP.NET Core 2.0使用NLog日志配置

一、新建ASP. Ce 2.0 MVC项目,使用NuGet在浏览中搜索:NLog.Web.AspCe,如下图所示:二、在项目下新建一个xml类型的nlog.config文件《?xml version="1.0" encoding="utf8"?》《nlog xmlns="http:www.nlogproject.gschemasNLog.xsd" xmlns:xsi="http:www.
asp.net core使用IHttpContextAccessor获取来源页

asp.net core使用IHttpContextAccessor获取来源页

1、在Startup文件注入IHttpContextAccesspublic void ConfigureServices(IServiceCollection services) { ... 注入HttpContextAccess services.AddSingleton《IHttpContex