asp.net-core-mvc

Required query string parameter in ASP.NET Core

北城以北 提交于 2019-12-01 15:49:00
问题 Using ASP.NET Core 1.1 with VS2015 (sdk 1.0.0-preview2-003131), I have the following controller: public class QueryParameters { public int A { get; set; } public int B { get; set; } } [Route("api/[controller]")] public class ValuesController : Controller { // GET api/values [HttpGet] public IEnumerable<string> Get([FromQuery]QueryParameters parameters) { return new [] { parameters.A.ToString(), parameters.B.ToString() }; } } As you can see, I have two query parameters. What I would like is to

How to pull configuration settings from XML file in Startup.cs

泪湿孤枕 提交于 2019-12-01 15:25:32
问题 I have a startup.cs file and i want to pull configurations from XML file rather than appsetings.json file. Is it possible with ASP.NET Core MVC? 回答1: If you want to use an appsettings.xml instead you can refer to my blog article here. Quote from the article: To use XML files, you need to add this NuGet package: Microsoft.Extensions.Configuration.Xml. I added the 1.0.0 to my project.json and added a appsettings.xml file. <configuration> <MySettings> <SomeSetting>Test</SomeSetting> <Another

asp.net 5 mvc 6 loginUrl change path

北战南征 提交于 2019-12-01 15:13:49
问题 When creating a new project in VS 2015 WebApplication, how would you go about changing the Redirect LoginUrl Path when not Authorize'd? I have created a new Area, where I have created a loginController. This loginController requires you are Authorize'd. But when trying to reach the pages, I am redirected to "/Account/Login". How would I go about changing this path to "/AREA/Login/Index"? 回答1: Try doing the following: services.Configure<CookieAuthenticationOptions>(options => { options

Where all types for http headers gone in ASP.NET 5?

荒凉一梦 提交于 2019-12-01 15:13:44
Previously, in WebApi (on .NET 4.x) we could work with headers of both the request and the response via typed interfaces (see HttpRequestMessage.Headers / HttpResponseMessage.Headers ). Now, in ASP.NET 5 we have HttpRequest and HttpResponse with Headers property of type IHeaderDictionary . But it's just an untyped Dictionary. Below I put an example with typed accessing could return a fine-tuned http-response. It's needed to create a HttpResponseMessage and fill its Headers collection (which was typed btw). HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); response

cannot update identity column in Entity Framework Core

╄→尐↘猪︶ㄣ 提交于 2019-12-01 15:05:48
问题 I've added a separate Identification to the AspNetUsers table called NumericId that will serve along with the GUID like ID that ASP has for default. I've added the property as an additional property of the ApplicationUser class: public class ApplicationUser : IdentityUser { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public virtual int NumericId { get; set; } } However, when I try to register, or update the user's details (that aren't even relevant to the numericId) I keep getting

ASP.NET Core 1.0 - MVC 6 - Cookie Expiration

非 Y 不嫁゛ 提交于 2019-12-01 14:45:11
UPDATE: It is definitely not a bug in RC1. The cookie settings are working with the default UserManager and UserStore, so it must be something related to my UserManager/UserStore, I've overseen. I basically use the implementation here: https://github.com/jesblit/ASPNET5-FormAuthenticationLDAP Original Post: I have a problem with persistent logins. No matter how I configure the cookie, after 30 minutes, the User is automatically logged out (no matter how much the user interacts with the App). I setup my App with: public void ConfigureServices(IServiceCollection services) { services.AddCaching()

Persistent Auth cookie in .net core 2.0

这一生的挚爱 提交于 2019-12-01 14:12:23
Recently I created my new website in .net core 2.0 and I'm using a persistent cookie in authentication. I'm also using persistent culture cookie for language. my website hosted in azure shared pool and I didn't specify any machine key . Problem. When I re-open my website after few hours of inactivity (new browser) I lost my auth cookie and I need to log in again but culture cookie works as per the last session. I also setup Application Insights availability to keep warm up my application (ping website in every 10 min from 2 different location). LoginController if (this.accountService

How to transform XML to HTML with XSLT in C#?

坚强是说给别人听的谎言 提交于 2019-12-01 13:38:12
How can I transform XML to HTML with XSLT in ASP.NET Core? I thought about: public static string TransformXMLToHTML(string inputXml, string xsltString) { XslCompiledTransform transform = new XslCompiledTransform(); using(XmlReader reader = XmlReader.Create(new StringReader(xsltString))) { transform.Load(reader); } StringWriter results = new StringWriter(); using(XmlReader reader = XmlReader.Create(new StringReader(inputXml))) { transform.Transform(reader, null, results); } return results.ToString(); } but the XmlReader does not exist in .NET Core. Do you have any idea? The System.Xml.Xsl

ASP.NET Core 1.0 - MVC 6 - Cookie Expiration

前提是你 提交于 2019-12-01 13:19:58
问题 UPDATE: It is definitely not a bug in RC1. The cookie settings are working with the default UserManager and UserStore, so it must be something related to my UserManager/UserStore, I've overseen. I basically use the implementation here: https://github.com/jesblit/ASPNET5-FormAuthenticationLDAP Original Post: I have a problem with persistent logins. No matter how I configure the cookie, after 30 minutes, the User is automatically logged out (no matter how much the user interacts with the App).

Persistent Auth cookie in .net core 2.0

自作多情 提交于 2019-12-01 12:04:23
问题 Recently I created my new website in .net core 2.0 and I'm using a persistent cookie in authentication. I'm also using persistent culture cookie for language. my website hosted in azure shared pool and I didn't specify any machine key . Problem. When I re-open my website after few hours of inactivity (new browser) I lost my auth cookie and I need to log in again but culture cookie works as per the last session. I also setup Application Insights availability to keep warm up my application